Skip to content

Commit 4262fd3

Browse files
author
Adafruit Adabot
committed
center eyes, check files for press-on-boot
1 parent 394ef17 commit 4262fd3

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

M4_Eyes/M4_Eyes.ino

Lines changed: 12 additions & 6 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,13 +165,13 @@ 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

@@ -204,7 +208,9 @@ void setup() {
204208
yield();
205209
uint8_t e;
206210
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
207212
eye[e].spi->setClockSource(DISPLAY_CLKSRC);
213+
#endif
208214
eye[e].display->fillScreen(0);
209215
eye[e].dma.allocate();
210216
eye[e].dma.setTrigger(eye[e].spi->getDMAC_ID_TX());
@@ -837,7 +843,7 @@ void loop() {
837843
// Initialize new SPI transaction & address window...
838844
eye[eyeNum].spi->beginTransaction(settings);
839845
digitalWrite(eye[eyeNum].cs, LOW); // Chip select
840-
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);
841847
delayMicroseconds(1);
842848
digitalWrite(eye[eyeNum].dc, HIGH); // Data mode
843849
if(eyeNum == (NUM_EYES-1)) {

M4_Eyes/globals.h

Lines changed: 2 additions & 0 deletions
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

0 commit comments

Comments
 (0)