You know as I typing think its beginning to get clearer on what I have to try next.The optimal iris image width can be computed by multiplying the round iris diameter (in pixels) by pi — 3.14 — while the image height is the iris radius in pixels. Doesn’t have to be exact, just “ish.” The default iris is 80 pixels across, so the map image is 256x64 pixels.
Been playing around with the iris map for the last couple of days. Think the problem is something with the polar coordinate map that is generated by the python script but can't nail the problem down.
It is very possible I screwed it up when I was trying to get it to work...
Or maybe it overflowed some max value (like might fit into a byte...
It is very possible I screwed it up when I was trying to get it to work...
Or maybe it overflowed some max value (like might fit into a byte...
One thing that I noticed is the use of double and sqrt/pow functions. On the Teensy 4 that is fine, but I should try changing the Teensy 3.5 version to use float specifically and powf/sqrtf to see if it improves the frame rate.
// And scale to iris range (IRIS_MAX is size at LIGHT_MIN)
v = map(v, 0, (LIGHT_MAX - LIGHT_MIN), IRIS_MAX, IRIS_MIN);
@KurtE - @MichaelMeissner - @defragster
Think we are all pretty dense and missed something obvious and took me 3 days to figure it out. Don't think there is anything wrong with our scaling of the images. Finally found something in the code that finally registered:
so essentially you have to change IRIS_MIN to about 500 for the larger eye while for the std iris (80 pixels its 120). Once you change it to 500 all works. Only thing that I can figure out. Have to test this on the smaller eyes to see what happens. ThouhtsCode:// And scale to iris range (IRIS_MAX is size at LIGHT_MIN) v = map(v, 0, (LIGHT_MAX - LIGHT_MIN), IRIS_MAX, IRIS_MIN);
#include "config.h" // ****** CONFIGURATION IS DONE IN HERE ******
#ifdef USE_ST7789
typedef ST7789_t3 displayType; // Using TFT display(s)
#define DISPLAY_SIZE 240
#else
typedef ST7735_t3 displayType; // Using TFT display(s)
#define DISPLAY_SIZE 128
#endif
#if DISPLAY_SIZE > 128
#if !defined(IRIS_MIN) // Each eye might have its own MIN/MAX
#define IRIS_MIN 500 // Iris size (0-1023) in brightest light
#endif
#if !defined(IRIS_MAX)
#define IRIS_MAX 700 // Iris size (0-1023) in darkest light
#endif
#else
#if !defined(IRIS_MIN) // Each eye ight have its own MIN/MAX
#define IRIS_MIN 120 // Iris size (0-1023) in brightest light
#endif
#if !defined(IRIS_MAX)
#define IRIS_MAX 720 // Iris size (0-1023) in darkest light
#endif
#ifdef USE_ST7789
typedef ST7789_t3 displayType; // Using TFT display(s)
#define DISPLAY_SIZE 240
#else
typedef ST7735_t3 displayType; // Using TFT display(s)
#define DISPLAY_SIZE 128
#endif
#include "config.h" // ****** CONFIGURATION IS DONE IN HERE ******
#define RGBColor(r, g, b) ST7735_t3x::Color565(r, g, b)
#define IRIS_MIN 500
#define IRIS_MAX 900
#define SCLERA_WIDTH 375
#define SCLERA_HEIGHT 375
@MichaelMeissner - @KurtE
Done. I incorporated two of the uncanny sketches in the ST7735_t4_rewrite branch that I have: https://github.com/mjs513/ST7735_t3/tree/ST7735_T4_rewrite. I also just did a PR to Paul for these changes as well: https://github.com/PaulStoffregen/ST7735_t3/pull/4
@mjs513 - I am/was curious how bad it would be to support Adafruit Fonts as well as our own fonts.
So I implemented it But now still trying to figure out way to properly handle the y_cursor...
https://github.com/KurtE/ST7735_t3/tree/T4_Rewrite_Adafruit_fonts
It is based off your T4 rewrite.
Figure if adafruit fonts worked, then don't have to worry as much about compatibility...
I hacked up the St7735 frame buffer test program, that checked the rotations, to add simple
command: t
which outputs a text page (like my ili93241...)
and: o
which outputs text again Opaque
Note their fonts did not support Opaque - I still have not looked into this part...
But you can see where they run into each other in Y part...
View attachment 17744
tft.println("0123456789zyxwvutu");
[COLOR="#FF0000"]tft.println();[/COLOR] //throw in new line before switching fonts
tft.setFont(&FreeMonoBoldOblique12pt7b);
// tft.setTextSize(2);
tft.println("AdaFruit");
tft.println("FreeSan12");
// tft.setTextSize(1);
tft.setFont(Arial_10);
tft.println("0123456789zyxwvutu");
#include <Adafruit_ST7735.h>
#include <Adafruit_ST7789.h>
#include <Adafruit_ST77xx.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>
#define TFT_SCLK 13 // SCLK can also use pin 14
#define TFT_MOSI 11 // MOSI can also use pin 7
#define TFT_CS 10 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
#define TFT_DC 9 // but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
#define TFT_RST 8 // RST can use any pin
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
float p = 3.1415926;
void setup(void) {
pinMode(TFT_CS, INPUT_PULLUP);
while (!Serial && millis() < 5000) ;
Serial.begin(9600);
Serial.print("hello!");
tft.init(240, 240, SPI_MODE2) ; // use for ILI9488
Serial.printf("init CS:%d DC:%d MOSI:%d SCLK:%d RST:%d\n ", TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
tft.fillScreen(ST77XX_RED);
delay(250);
tft.fillScreen(ST77XX_GREEN);
delay(250);
tft.fillScreen(ST77XX_BLUE);
delay(250);
tft.fillScreen(ST77XX_WHITE);
delay(250);
tft.fillScreen(ST77XX_BLACK);
delay(250);
}
uint8_t rotation = 0;
void drawTestScreen(uint16_t background_color) {
tft.fillScreen(background_color);
tft.fillRect(tft.width() / 2 - 32, 20, 64, tft.height() - 40, ST7735_GREEN);
tft.fillRect(tft.width() / 4 - 16, tft.height() / 4 - 16, 32, 32, ST7735_BLUE);
tft.fillRect(tft.width() * 3 / 4 - 16, tft.height() * 3 / 4 - 16, 32, 32, ST7735_WHITE);
tft.fillRect(tft.width() * 3 / 4 - 16, tft.height() / 4 - 16, 32, 32, ST7735_BLACK);
tft.fillRect(0, 0, 8, 8, ST7735_BLACK);
tft.fillRect(tft.width() - 8, tft.height() - 8, 8, 8, ST7735_WHITE);
tft.drawPixel(0, 0, ST7735_YELLOW);
tft.drawPixel(1, 1, ST7735_RED);
tft.drawPixel(2, 2, ST7735_BLUE);
tft.setCursor(0, tft.height() / 2 - 4);
tft.printf("R:%d W:%d H:%d", rotation, tft.width(), tft.height());
tft.drawPixel(tft.width() - 1, tft.height() - 1, ST7735_YELLOW);
tft.drawPixel(tft.width() - 2, tft.height() - 2, ST7735_RED);
tft.drawPixel(tft.width() - 3, tft.height() - 3, ST7735_BLUE);
}
void drawTextScreen(bool fOpaque) {
tft.fillScreen(ST77XX_RED);
if (fOpaque)
tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK );
else
tft.setTextColor(ST77XX_WHITE);
tft.setFont();
tft.setCursor(0, 5);
Serial.printf("ASC: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.println("AbCdEf");
Serial.printf("A Abcd: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.setTextSize(2);
tft.println("0123456789");
Serial.printf("A 01234: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.setTextSize(1);
tft.setFont(&FreeMonoBoldOblique12pt7b);
Serial.printf("A SF: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.println("AdaFruit");
Serial.printf("A Adafruit: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.setFont(&FreeSerif12pt7b);
Serial.printf("A SF: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.println("FreeSan12");
Serial.printf("A FreeSans: %d %d\n", tft.getCursorX(), tft.getCursorY());
}
void loop() {
tft.setRotation(rotation);
Serial.printf("Set Rotation: %d width: %d height: %d\n", rotation, tft.width(), tft.height());
rotation = (rotation + 1) & 0x3;
elapsedMillis timer;
drawTestScreen(ST7735_RED);
// large block of text
//delay(2500);
Serial.println("Hit any key to continue");
uint8_t loffset = 0;
for (;;) {
while (!Serial.available()) ;
char ch = Serial.read();
while (Serial.read() != -1) ;
if (ch == '.') {
tft.drawRect(loffset, loffset, tft.width() - 2 * loffset, tft.height() - 2 * loffset, ST7735_GREEN);
loffset++;
} else if (ch == 't') {
drawTextScreen(0);
} else if (ch == 'o') {
drawTextScreen(1);
} else {
break;
}
}
}
void testContinuousUpdate() {
}
//#define NEW_THE_DISP
#include <Adafruit_GFX.h> // Core graphics library
#include <ST7735_t3.h> // Hardware-specific library
#include <ST7789_t3.h> // Hardware-specific library
#include <SPI.h>
#include <st7735_t3_font_Arial.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>
#if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
//#define USE_SPI1
//#define USE_SPI2
//#define NON_SPI_PINS
#ifdef USE_SPI2
#define TFT_SCLK 37 //
//#define TFT_MISO 34
#define TFT_MOSI 35 // MOSI can also use pin 7
#define TFT_CS -1//36 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
#define TFT_DC 38 // but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
#define TFT_RST 39 // RST can use any pin
#elif defined(USE_SPI1)
#define TFT_SCLK 27 // SCLK can also use pin 14
#define TFT_MOSI 26 // MOSI can also use pin 7
#define TFT_CS 0 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
#define TFT_DC 2 // but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
#define TFT_RST 3 // RST can use any pin
#elif defined(NON_SPI_PINS)
#define TFT_SCLK 7 // SCLK can also use pin 14
#define TFT_MOSI 8 // MOSI can also use pin 7
#define TFT_CS 10 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
#define TFT_DC 9 // but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
#define TFT_RST 20 // RST can use any pin
#else
#define TFT_SCLK 13 // SCLK can also use pin 14
#define TFT_MOSI 11 // MOSI can also use pin 7
#define TFT_CS 10 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
#define TFT_DC 9 // but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
#define TFT_RST 8 // RST can use any pin
#endif
#define SD_CS 4 // CS for SD card, can use any pin
#else
//--------------------------------------------
// T3.X
//#define USE_SPI1
//#define USE_SPI2
#define USE_SPI1_NOT_HARDWARE_CSDC
#if defined(USE_SPI1_NOT_HARDWARE_CSDC)
#define TFT_SCLK 20 // SCLK can also use pin 14
#define TFT_MOSI 21 // MOSI can also use pin 7
#define TFT_CS 2 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
#define TFT_DC 3 // but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
#define TFT_RST 8 // RST can use any pin
#define SD_CS 4 // CS for SD card, can use any pin
#elif defined(USE_SPI1)
#define TFT_SCLK 32 // T3.5/T3.6
#define TFT_MOSI 0 //
#define TFT_CS 30 // random digital pin
#define TFT_DC 31 // Only Hardware CS pin on SPI1
#define TFT_RST 29 // RST can use any pin
#elif defined(USE_SPI2)
#define TFT_SCLK 46 // T3.5/T3.6
#define TFT_MOSI 44 //
#define TFT_CS 54 // Hardware CS on SPI2
#define TFT_DC 55 // Hardware CS pin on SPI2
#else
#define TFT_SCLK 13 // SCLK can also use pin 14
#define TFT_MOSI 11 // MOSI can also use pin 7
#define TFT_CS 10 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
#define TFT_DC 9 // but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
#define TFT_RST 8 // RST can use any pin
#endif
#define SD_CS 4 // CS for SD card, can use any pin
#endif
//#define TFT_CS2 7
#define TFT_BLK 7
ST7789_t3 tft = ST7789_t3(TFT_CS, TFT_DC, TFT_RST);
ST7789_t3 *ptft = &tft;
float p = 3.1415926;
void setup(void) {
pinMode(TFT_CS, INPUT_PULLUP);
while (!Serial && millis() < 5000) ;
Serial.begin(9600);
Serial.print("hello!");
tft.init(240, 320) ; // use for ILI9488
Serial.printf("init CS:%d DC:%d MOSI:%d SCLK:%d RST:%d\n ", TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
tft.fillScreen(ST77XX_RED);
delay(250);
tft.fillScreen(ST77XX_GREEN);
delay(250);
tft.fillScreen(ST77XX_BLUE);
delay(250);
tft.fillScreen(ST77XX_WHITE);
delay(250);
tft.fillScreen(ST77XX_BLACK);
delay(250);
}
uint8_t rotation = 0;
void drawTestScreen(uint16_t background_color) {
tft.fillScreen(background_color);
tft.fillRect(tft.width() / 2 - 32, 20, 64, tft.height() - 40, ST7735_GREEN);
tft.fillRect(tft.width() / 4 - 16, tft.height() / 4 - 16, 32, 32, ST7735_BLUE);
tft.fillRect(tft.width() * 3 / 4 - 16, tft.height() * 3 / 4 - 16, 32, 32, ST7735_WHITE);
tft.fillRect(tft.width() * 3 / 4 - 16, tft.height() / 4 - 16, 32, 32, ST7735_BLACK);
tft.fillRect(0, 0, 8, 8, ST7735_BLACK);
tft.fillRect(tft.width() - 8, tft.height() - 8, 8, 8, ST7735_WHITE);
tft.drawPixel(0, 0, ST7735_YELLOW);
tft.drawPixel(1, 1, ST7735_RED);
tft.drawPixel(2, 2, ST7735_BLUE);
tft.setCursor(0, tft.height() / 2 - 4);
tft.printf("R:%d W:%d H:%d", rotation, tft.width(), tft.height());
tft.drawPixel(tft.width() - 1, tft.height() - 1, ST7735_YELLOW);
tft.drawPixel(tft.width() - 2, tft.height() - 2, ST7735_RED);
tft.drawPixel(tft.width() - 3, tft.height() - 3, ST7735_BLUE);
}
void drawTextScreen(bool fOpaque) {
tft.fillScreen(ST77XX_RED);
if (fOpaque)
tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK );
else
tft.setTextColor(ST77XX_WHITE);
tft.setFont();
tft.setCursor(0, 5);
Serial.printf("ASC: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.println("AbCdEf");
tft.println();
Serial.printf("A Abcd: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.setTextSize(2);
tft.println("0123456789");
tft.println();
Serial.printf("A 01234: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.setTextSize(1);
tft.println();
tft.setFont(&FreeMonoBoldOblique12pt7b);
Serial.printf("A SF: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.println("AdaFruit");1
Serial.printf("A Adafruit: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.setFont(&FreeSerif12pt7b);
Serial.printf("A SF: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.println("FreeSan12");
Serial.printf("A FreeSans: %d %d\n", tft.getCursorX(), tft.getCursorY());
}
void loop() {
tft.setRotation(rotation);
Serial.printf("Set Rotation: %d width: %d height: %d\n", rotation, tft.width(), tft.height());
rotation = (rotation + 1) & 0x3;
elapsedMillis timer;
drawTestScreen(ST7735_RED);
// large block of text
//delay(2500);
Serial.println("Hit any key to continue");
uint8_t loffset = 0;
for (;;) {
while (!Serial.available()) ;
char ch = Serial.read();
while (Serial.read() != -1) ;
if (ch == '.') {
tft.drawRect(loffset, loffset, tft.width() - 2 * loffset, tft.height() - 2 * loffset, ST7735_GREEN);
loffset++;
} else if (ch == 't') {
drawTextScreen(0);
} else if (ch == 'o') {
drawTextScreen(1);
} else {
break;
}
}
}
void testContinuousUpdate() {
}
// Maybe support GFX Fonts as well?
void ST7735_t3::setFont(const GFXfont *f) {
font = NULL; // turn off the other font...
if(f) { // Font struct pointer passed in?
if(!gfxFont) { // And no current font struct?
// Switching from classic to new font behavior.
// Move cursor pos down 6 pixels so it's on baseline.
[COLOR="#FF0000"]cursor_y += 16;[/COLOR] [B] // uncommented and increased to 16[/B]
}
} else if(gfxFont) { // NULL passed. Current font struct defined?
// Switching from new to classic font behavior.
// Move cursor pos up 6 pixels so it's at top-left of char.
[COLOR="#FF0000"]cursor_y -= 6;[/COLOR][B] //uncommented[/B]
}
gfxFont = f;
}
void drawTextScreen(bool fOpaque) {
tft.fillScreen(ST77XX_RED);
if (fOpaque)
tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK );
else
tft.setTextColor(ST77XX_WHITE);
tft.setFont();
tft.setCursor(0, 5);
Serial.printf("ASC: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.println("AbCdEf");
Serial.printf("A Abcd: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.setTextSize(2);
tft.println("0123456789");
Serial.printf("A 01234: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.setTextSize(1);
tft.setFont(&FreeMonoBoldOblique12pt7b);
Serial.printf("A SF: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.println("AdaFruit");
Serial.printf("A Adafruit: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.setFont(&FreeSerif12pt7b);
Serial.printf("A SF: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.println("FreeSan12");
Serial.printf("A FreeSans: %d %d\n", tft.getCursorX(), tft.getCursorY());
tft.setCursor(30, 100);
tft.drawRect(30, 100, 60, 20, ST7735_GREEN);
tft.print("FreeSans");
tft.setFont();
tft.setCursor(30, 130);
tft.drawRect(30, 130, 60, 20, ST7735_GREEN);
tft.print("System");
tft.setCursor(30, 160);
tft.setFont(&FreeSerif12pt7b);
tft.drawRect(30, 160, 60, 20, ST7735_GREEN);
tft.print("FreeSans");
}
getTextBounds(const char *string, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
getTextBounds(const String &str, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
setTextSize(uint8_t s),
setTextSize(uint8_t sx, uint8_t sy),
That is probably the problem. When you start mixing fonts the baseline changes so the delta between baselines need to adjusted when you switch the fonts by some value delta-y. That is what the +-6 is suppose to do: https://learn.adafruit.com/adafruit-gfx-graphics-library/using-fontsKurtE said:I think the +6 versus +16 is more to do with which font was choosen. Probably a larger font would need larger value. I think their two font systems, System font draws from the top and the GFXFonts draw from Bottom or maybe some hypothetical base line?
But that looks like it only applies when printing on the same line (not sure about this).whereas the cursor position when printing with the classic font identified the top-left corner of the character cell, with new fonts the cursor position indicates the baseline — the bottom-most row — of subsequent text. Characters may vary in size and width, and don’t necessarily begin at the exact cursor column (as in below, this character starts one pixel left of the cursor, but others may be on or to the right of it).
When switching between built-in and custom fonts, the library will automatically shift the cursor position up or down 6 pixels as needed to continue along the same baseline.
getTextBounds expects a string, a starting cursor X&Y position (the current cursor position will not be altered), and addresses of two signed and two unsigned 16-bit integers. These last four values will then contain the upper-left corner and the width & height of the area covered by this text — these can then be passed directly as arguments to fillRect().
This will unfortunately “blink” the text when erasing and redrawing, but is unavoidable. The old scheme of drawing background pixels in the same pass only creates a new set of problems.
Yeah just noticed that when going through the code.KurtE said:There are still a few missing pieces here. In here (taken from ILI9341_t3n I think, which I pulled in from a PR) is a function strPixelLen which is supposed to find out how long the string is in pixels. Which probably needs GFX font changes.