Skip to content

Commit 5ecf741

Browse files
Merge pull request #863 from ladyada/master
more tweekz
2 parents 5a476ec + 5011e55 commit 5ecf741

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

M4_Eyes/M4_Eyes.ino

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ void setup() {
145145

146146
arcada.displayBegin();
147147

148+
DISPLAY_SIZE = min(ARCADA_TFT_WIDTH, ARCADA_TFT_HEIGHT);
149+
DISPLAY_X_OFFSET = (ARCADA_TFT_WIDTH - DISPLAY_SIZE) / 2;
150+
DISPLAY_Y_OFFSET = (ARCADA_TFT_HEIGHT - DISPLAY_SIZE) / 2;
151+
148152
Serial.begin(115200);
149153
// while(!Serial) delay(10);
150154

@@ -161,22 +165,24 @@ void setup() {
161165
// of the nose booper when doing this...it self-calibrates on startup.
162166
// DO THIS BEFORE THE SPLASH SO IT DOESN'T REQUIRE A LENGTHY HOLD.
163167
char *filename = "config.eye";
164-
arcada.readButtons();
165-
uint32_t buttonState = arcada.justPressedButtons();
166-
if(buttonState & ARCADA_BUTTONMASK_UP) {
168+
169+
uint32_t buttonState = arcada.readButtons();
170+
if((buttonState & ARCADA_BUTTONMASK_UP) && arcada.exists("config1.eye")) {
167171
filename = "config1.eye";
168-
} else if(buttonState & ARCADA_BUTTONMASK_A) {
172+
} else if((buttonState & ARCADA_BUTTONMASK_A) && arcada.exists("config2.eye")) {
169173
filename = "config2.eye";
170-
} else if(buttonState & ARCADA_BUTTONMASK_DOWN) {
174+
} else if((buttonState & ARCADA_BUTTONMASK_DOWN) && arcada.exists("config3.eye")) {
171175
filename = "config3.eye";
172176
}
173177

174178
yield();
175179
// Initialize displays
176-
eye[0].display = arcada._display;
177-
if (NUM_EYES > 1) {
180+
#if (NUM_EYES > 1)
181+
eye[0].display = arcada._display;
178182
eye[1].display = arcada.display2;
179-
}
183+
#else
184+
eye[0].display = arcada.display;
185+
#endif
180186

181187
yield();
182188
if (arcada.drawBMP("/splash.bmp", 0, 0, (eye[0].display)) == IMAGE_SUCCESS) {
@@ -200,10 +206,11 @@ void setup() {
200206

201207
// Initialize DMAs
202208
yield();
203-
uint8_t e, rtna = 0x01; // Screen refresh rate control (datasheet 9.2.18, FRCTRL2)
209+
uint8_t e;
204210
for(e=0; e<NUM_EYES; e++) {
211+
#if (ARCADA_TFT_WIDTH != 160) && (ARCADA_TFT_HEIGHT != 128) // 160x128 is ST7735 which isn't able to deal
205212
eye[e].spi->setClockSource(DISPLAY_CLKSRC);
206-
eye[e].display->sendCommand(0xC6, &rtna, 1);
213+
#endif
207214
eye[e].display->fillScreen(0);
208215
eye[e].dma.allocate();
209216
eye[e].dma.setTrigger(eye[e].spi->getDMAC_ID_TX());
@@ -836,7 +843,7 @@ void loop() {
836843
// Initialize new SPI transaction & address window...
837844
eye[eyeNum].spi->beginTransaction(settings);
838845
digitalWrite(eye[eyeNum].cs, LOW); // Chip select
839-
eye[eyeNum].display->setAddrWindow(0, 0, DISPLAY_SIZE, DISPLAY_SIZE);
846+
eye[eyeNum].display->setAddrWindow(DISPLAY_X_OFFSET, DISPLAY_Y_OFFSET, DISPLAY_SIZE, DISPLAY_SIZE);
840847
delayMicroseconds(1);
841848
digitalWrite(eye[eyeNum].dc, HIGH); // Data mode
842849
if(eyeNum == (NUM_EYES-1)) {
@@ -888,6 +895,7 @@ void loop() {
888895
irisValue = irisMin + (sum * irisRange); // 0.0-1.0 -> iris min/max
889896
if((++iris_frame) >= (1 << IRIS_LEVELS)) iris_frame = 0;
890897
}
898+
#if defined(ADAFRUIT_MONSTER_M4SK_EXPRESS)
891899
if(voiceOn) {
892900
// Read buttons, change pitch
893901
arcada.readButtons();
@@ -906,6 +914,7 @@ void loop() {
906914
Serial.println(currentPitch);
907915
}
908916
}
917+
#endif
909918
user_loop();
910919
}
911920
} // end first-column check

M4_Eyes/eyes/hazel_128x128/lower.bmp

2.06 KB
Binary file not shown.

M4_Eyes/eyes/hazel_128x128/upper.bmp

2.06 KB
Binary file not shown.

M4_Eyes/globals.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ GLOBAL_VAR Adafruit_Arcada arcada;
2424

2525
#define MAX_DISPLAY_SIZE 240
2626
GLOBAL_VAR int DISPLAY_SIZE GLOBAL_INIT(240); // Start with assuming a 240x240 display
27+
GLOBAL_VAR int DISPLAY_X_OFFSET GLOBAL_INIT(0); // Used with rectangular screens
28+
GLOBAL_VAR int DISPLAY_Y_OFFSET GLOBAL_INIT(0); // Used with rectangular screens
2729
GLOBAL_VAR uint32_t stackReserve GLOBAL_INIT(5192); // See image-loading code
2830
GLOBAL_VAR int eyeRadius GLOBAL_INIT(0); // 0 = Use default in loadConfig()
2931
GLOBAL_VAR int eyeDiameter; // Calculated from eyeRadius later
@@ -152,7 +154,7 @@ typedef struct {
152154
int8_t winkPin; // Manual eye wink control (-1 = none)
153155
// Remaining values are initialized in code:
154156
columnStruct column[2]; // Alternating column structures A/B
155-
Adafruit_ST7789 *display; // Pointer to display object
157+
Adafruit_SPITFT *display; // Pointer to display object
156158
DMAbuddy dma; // DMA channel object with fix() function
157159
DmacDescriptor *dptr; // DMA channel descriptor pointer
158160
uint32_t dmaStartTime; // For DMA timeout handler

0 commit comments

Comments
 (0)