Skip to content

Commit 4949bdf

Browse files
Boost screen refresh, some changes to pupil tracking
1 parent 44c1abe commit 4949bdf

3 files changed

Lines changed: 35 additions & 17 deletions

File tree

M4_Eyes/M4_Eyes.ino

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,12 @@ void setup() {
162162
delay(20);
163163
#endif
164164

165-
uint8_t e;
165+
uint8_t e, rtna = 0x01; // Screen refresh rate control (datasheet 9.2.18, FRCTRL2)
166166
// Initialize displays
167167
for(e=0; e<NUM_EYES; e++) {
168168
eye[e].display = new Adafruit_ST7789(eye[e].spi, eye[e].cs, eye[e].dc, eye[e].rst);
169169
eye[e].display->init(240, 240);
170+
eye[e].display->sendCommand(0xC6, &rtna, 1);
170171
eye[e].spi->setClockSource(DISPLAY_CLKSRC);
171172
eye[e].display->fillScreen(0x1234);
172173
eye[e].display->setRotation(0);
@@ -510,24 +511,30 @@ void loop() {
510511
timeToNextBlink = blinkDuration * 3 + random(4000000);
511512
}
512513

513-
// Eyelids naturally "track" the pupils (move up or down automatically)
514-
int ix = (int)map2screen(mapRadius - eye[eyeNum].eyeX) + 120, // Pupil position
515-
iy = (int)map2screen(mapRadius - eye[eyeNum].eyeY) + 120; // on screen
516-
iy += irisRadius / 2; // top edge of iris (ish) in screen pixels
517514
float uq, lq; // So many sloppy temp vars in here for now, sorry
518-
if(eyeNum & 1) ix = 239 - ix; // Flip for right eye
519-
if(iy > upperOpen[ix]) {
520-
uq = 1.0;
521-
} else if(iy < upperClosed[ix]) {
522-
uq = 0.0;
523-
} else {
524-
uq = (float)(iy - upperClosed[ix]) / (float)(upperOpen[ix] - upperClosed[ix]);
525-
}
526-
if(booped) {
527-
uq = 0.9;
528-
lq = 0.7;
515+
if(tracking) {
516+
// Eyelids naturally "track" the pupils (move up or down automatically)
517+
int ix = (int)map2screen(mapRadius - eye[eyeNum].eyeX) + 120, // Pupil position
518+
iy = (int)map2screen(mapRadius - eye[eyeNum].eyeY) + 120; // on screen
519+
iy += irisRadius * trackFactor;
520+
if(eyeNum & 1) ix = 239 - ix; // Flip for right eye
521+
if(iy > upperOpen[ix]) {
522+
uq = 1.0;
523+
} else if(iy < upperClosed[ix]) {
524+
uq = 0.0;
525+
} else {
526+
uq = (float)(iy - upperClosed[ix]) / (float)(upperOpen[ix] - upperClosed[ix]);
527+
}
528+
if(booped) {
529+
uq = 0.9;
530+
lq = 0.7;
531+
} else {
532+
lq = 1.0 - uq;
533+
}
529534
} else {
530-
lq = 1.0 - uq;
535+
// If no tracking, eye is FULLY OPEN when not blinking
536+
uq = 1.0;
537+
lq = 1.0;
531538
}
532539
// Dampen eyelid movements slightly
533540
// SAVE upper & lower lid factors per eye,

M4_Eyes/file.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@ void loadConfig(char *filename) {
266266
JsonVariant iristv = doc["irisTexture"],
267267
scleratv = doc["scleraTexture"];
268268

269+
v = doc["tracking"];
270+
if(v.is<bool>()) tracking = v.as<bool>();
271+
v = doc["squint"];
272+
if(v.is<float>()) {
273+
trackFactor = 1.0 - v.as<float>();
274+
if(trackFactor < 0.0) trackFactor = 0.0;
275+
else if(trackFactor > 1.0) trackFactor = 1.0;
276+
}
277+
269278
// Convert clockwise int (0-1023) or float (0.0-1.0) values to CCW int used internally:
270279
v = doc["irisSpin"];
271280
if(v.is<float>()) irisSpin = v.as<float>() * -1024.0;

M4_Eyes/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ GLOBAL_VAR uint16_t lightSensorMax GLOBAL_INIT(1023);
6969
GLOBAL_VAR float lightSensorCurve GLOBAL_INIT(1.0);
7070
GLOBAL_VAR float irisMin GLOBAL_INIT(0.45);
7171
GLOBAL_VAR float irisRange GLOBAL_INIT(0.35);
72+
GLOBAL_VAR bool tracking GLOBAL_INIT(true);
73+
GLOBAL_VAR float trackFactor GLOBAL_INIT(0.5);
7274

7375
// Pin definition stuff will go here
7476

0 commit comments

Comments
 (0)