From 8cd2bc24abf1409c5c12bfc425686643ca9df03c Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Wed, 2 Feb 2022 08:14:58 -0500 Subject: [PATCH] abstracting and cleaning up --- apple/appleui.cpp | 12 +-------- images.h | 13 +++++----- physicaldisplay.h | 1 + teensy/teensy-display.cpp | 54 +++++++++++++++++++++++++++++++++------ teensy/teensy-display.h | 4 +++ 5 files changed, 59 insertions(+), 25 deletions(-) diff --git a/apple/appleui.cpp b/apple/appleui.cpp index a54a253..e2f495f 100644 --- a/apple/appleui.cpp +++ b/apple/appleui.cpp @@ -121,17 +121,7 @@ void AppleUI::blit() if (redrawDriveActivity) { redrawDriveActivity = false; - - /* - // FIXME make these bitmaps so the size/location are abstracted - for (int y=0; ydrawPixel(x + LED_X, y + LED1_Y, driveActivity[0] ? 0xFA00 : 0x0000); - - g_display->drawPixel(x + LED_X, y + LED2_Y, driveActivity[1] ? 0xFA00 : 0x0000); - } - } - */ + g_display->drawDriveActivity(driveActivity[0], driveActivity[1]); } } diff --git a/images.h b/images.h index 23be10b..6a94d01 100644 --- a/images.h +++ b/images.h @@ -12,12 +12,13 @@ #define SCREENINSET_9341_X (18) #define SCREENINSET_9341_Y (13) -// Spacing and positioning of elements within the DBITMAP, used by AppleUI -#define LED_HEIGHT 9 -#define LED_WIDTH 17 -#define LED_X 48 -#define LED1_Y 68 -#define LED2_Y 117 +// drive activity LED positions +#define LED_HEIGHT_8875 9 +#define LED_WIDTH_8875 17 +#define LED1_X_8875 48 +#define LED2_X_8875 48 +#define LED1_Y_8875 68 +#define LED2_Y_8875 117 // These are the ABSTRACTED constants that AppleUI uses to tell the // display what it wants redrawn via drawUIImage(uint8_t imageIdx) diff --git a/physicaldisplay.h b/physicaldisplay.h index 79c419e..acd2585 100644 --- a/physicaldisplay.h +++ b/physicaldisplay.h @@ -15,6 +15,7 @@ class PhysicalDisplay { virtual void flush() = 0; virtual void drawUIImage(uint8_t imageIdx) = 0; + virtual void drawDriveActivity(bool drive0, bool drive1) = 0; // FIXME: drawImageOfSizeAt should probably be private now virtual void drawImageOfSizeAt(const uint8_t *img, uint16_t sizex, uint16_t sizey, uint16_t wherex, uint16_t wherey) = 0; diff --git a/teensy/teensy-display.cpp b/teensy/teensy-display.cpp index a8677c7..ad39ce7 100644 --- a/teensy/teensy-display.cpp +++ b/teensy/teensy-display.cpp @@ -53,12 +53,13 @@ TeensyDisplay::TeensyDisplay() appleImage = NULL; // FIXME abstract pin number, don't hard code it - pinMode(11, INPUT); - digitalWrite(11, HIGH); // turn on pull-up - + pinMode(11, INPUT_PULLUP); + delay(10); // let it rise before reading it + if (digitalRead(11)) { // Default: use older, smaller but faster, ILI display if pin 11 is not connected to ground Serial.println(" using ILI9341 display"); + use8875 = false; dmaBuffer16 = (uint16_t *)malloc((320*240)*2+32); // malloc() happens in the DMAMEM area (RAM2) // And we have to be sure dmaBuffer16 is 32-byte aligned for DMA purposes @@ -81,6 +82,7 @@ TeensyDisplay::TeensyDisplay() } else { // If someone grounded pin 11, then use the new RA8875 display Serial.println(" using RA8875 display"); + use8875 = true; dmaBuffer = (uint8_t *)malloc(800*480+32); // malloc() happens in the DMAMEM area (RAM2) // And we have to be sure dmaBuffer is 32-byte aligned for DMA purposes @@ -129,16 +131,24 @@ void TeensyDisplay::drawUIImage(uint8_t imageIdx) drawImageOfSizeAt(shellImage, shellWidth, shellHeight, 0, 0); break; case IMG_D1OPEN: - drawImageOfSizeAt(d1OpenImage, driveWidth, driveHeight, 55, 216); + drawImageOfSizeAt(d1OpenImage, driveWidth, driveHeight, + use8875 ? 4 : 55, + use8875 ? 67 : 216); break; case IMG_D1CLOSED: - drawImageOfSizeAt(d1ClosedImage, driveWidth, driveHeight, 55, 216); + drawImageOfSizeAt(d1ClosedImage, driveWidth, driveHeight, + use8875 ? 4 : 55, + use8875 ? 67 : 216); break; case IMG_D2OPEN: - drawImageOfSizeAt(d2OpenImage, driveWidth, driveHeight, 189, 216); + drawImageOfSizeAt(d2OpenImage, driveWidth, driveHeight, + use8875 ? 4 : 189, + use8875 ? 116 : 216); break; case IMG_D2CLOSED: - drawImageOfSizeAt(d2ClosedImage, driveWidth, driveHeight, 189, 216); + drawImageOfSizeAt(d2ClosedImage, driveWidth, driveHeight, + use8875 ? 4 : 189, + use8875 ? 116 : 216); break; case IMG_APPLEBATTERY: // FIXME *** @@ -146,6 +156,33 @@ void TeensyDisplay::drawUIImage(uint8_t imageIdx) } } +void TeensyDisplay::drawDriveActivity(bool drive0, bool drive1) +{ + // FIXME port constants for 9341 + if (drive0 != driveIndicator[0]) { + if (use8875) { + for (int y=0; y= nextMessageTime) { if (overlayMessage[0]) { - drawString(M_SELECTDISABLED, 1, (RA8875_HEIGHT - 18)/2, overlayMessage); // FIXME this /2 is clunky b/c drawString winds up doubling + /// FIXME This position needs updating for each display differently + // drawString(M_SELECTDISABLED, 1, (RA8875_HEIGHT - 18)/2, overlayMessage); // FIXME this /2 is clunky b/c drawString winds up doubling } nextMessageTime = millis() + 1000; } diff --git a/teensy/teensy-display.h b/teensy/teensy-display.h index 612c6cf..1d5e384 100644 --- a/teensy/teensy-display.h +++ b/teensy/teensy-display.h @@ -22,6 +22,8 @@ class TeensyDisplay : public PhysicalDisplay { virtual void clrScr(uint8_t coloridx); virtual void drawUIImage(uint8_t imageIdx); + virtual void drawDriveActivity(bool drive0, bool drive1); + virtual void drawImageOfSizeAt(const uint8_t *img, uint16_t sizex, uint16_t sizey, uint16_t wherex, uint16_t wherey); virtual void cacheDoubleWidePixel(uint16_t x, uint16_t y, uint8_t color); @@ -47,6 +49,8 @@ private: const uint8_t *appleImage; const uint16_t appleImageWidth, appleImageHeight; + bool use8875; + BaseDisplay *tft; };