Divers ajouts et correctifs

ajout sauvegarde en flash
et ajout écran de veille
This commit is contained in:
2026-05-22 00:35:39 +02:00
parent 71753703e8
commit 41fdaaa1ae
8 changed files with 357 additions and 108 deletions

View File

@@ -16,7 +16,6 @@
#include <Wire.h>
#include <Adafruit_GFX.h>
// Declaration for SSD1306 display on I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// Default on RP2040 Zero: SDA GPIO 4 SCL GPIO 5
@@ -26,17 +25,28 @@
#ifdef ESSAIS
#define OLED_HEIGHT 64 // OLED display height, in pixels
#define OLED_ADR 0x3D //Address 0x3D/0x3C to 128x64, 0x3C to 128x32
#define OLED_ADR 0x3C //0x3D //Address 0x3D/0x3C to 128x64, 0x3C to 128x32
#else
#define OLED_HEIGHT 32 // OLED display height, in pixels
#define OLED_ADR 0x3C
#define OLED_ADR 0x3C // 0x3C
#endif
Adafruit_SSD1306 oled(OLED_WIDTH, OLED_HEIGHT, &Wire, OLED_RST);
char _oledmsg[32]; // general purpose character buffer
void showInfo(char* l1, char* l2, char* l3) {
oled.clearDisplay();
oled.setTextSize(1); oled.setTextColor(SSD1306_WHITE);
oled.setCursor(0,0);
sprintf(_oledmsg,"%s",l1);
oled.println(_oledmsg);
sprintf(_oledmsg,"%s",l2);
oled.println(_oledmsg);
sprintf(_oledmsg,"%s",l3);
oled.println(_oledmsg);
oled.display();
}
void showTxt1(uint8_t x, uint8_t y, char* txt) {
oled.clearDisplay();
oled.setTextSize(1); oled.setTextColor(SSD1306_WHITE);
oled.setCursor(x,y); // O,0 at top-left corner
sprintf(_oledmsg,"CR:%s",txt);
@@ -51,23 +61,27 @@ void showText(String l1, String l2) {
}
void showInit() {
ledInit(); ledRGB(BLANK); //ledRGB(RED);
ledInit(); ledRGB(BLANK);// ledRGB(BLANK); //ledRGB(RED);//
if(!oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADR)) {
Serial.begin(115200); delay(100);
Serial.println(F("SSD1306 allocation failed"));
ledRGB(RED);
for(;;); // Don't proceed, loop forever
}
// setRotation(0)->point(0,0) is close to pin SDA
oled.clearDisplay();
oled.setRotation(2); // 2->point(0,0) is opposite of pins, 1&3 are vertical
//sprintf(_oledmsg, "SSD1306 @ %2d OK", OLED_ADR); oledTxt1(0,0,_oledmsg);
delay(100); // Serial.println(_oledmsg);
}
void showLOGO(int16_t gt) { /*--------- logo on SSD1306 -------------*/
oled.clearDisplay();
oled.clearDisplay(); oled.invertDisplay(true);
oled.drawBitmap(
LOGO_X0, LOGO_Y0,logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, LOGO_COLOR);
oled.display();
playRTTTL(sLOGO);
delay(gt);
delay(gt);
oled.invertDisplay(false);
}
void showTITRE() { // TextSize(2)=>10char, TextSize(1)=>22char,
oled.clearDisplay();
@@ -98,9 +112,9 @@ void showEXPOS(uint16_t t, int16_t m) {
void showREGLE() {
oled.clearDisplay(); oled.setTextColor(SSD1306_WHITE);
oled.setCursor(0,0); oled.setTextSize(2);
oled.println(F("Set values"));
oled.println(F("Set times"));
oled.setCursor(0,18); oled.setTextSize(1);
sprintf(_oledmsg,"- UVtime, + step time"); oled.println(_oledmsg);
sprintf(_oledmsg," - step, + expo UV"); oled.println(_oledmsg);
oled.display();
}
void showDUREE(uint16_t t) {
@@ -119,4 +133,55 @@ void showINCRE(uint16_t t) {
sprintf(_oledmsg,"- less, + more"); oled.println(_oledmsg);
oled.display();
}
void showSAUVE(uint16_t t, char* txt) {
oled.clearDisplay(); oled.setTextColor(SSD1306_WHITE);
oled.setCursor(0,0); oled.setTextSize(2);
sprintf(_oledmsg,"%s %3ds",txt,t); oled.println(_oledmsg);
oled.setCursor(0,18); oled.setTextSize(1);
sprintf(_oledmsg,"- quit, + save"); oled.println(_oledmsg);
oled.display();
}
typedef struct s_iconMvt {
int xp,yp,dy;
} t_iconMvt;
typedef struct s_sprite {
int count, h, w, x, y, dy;
const unsigned char *bmp;
t_iconMvt *iconsMvt;
} t_sprite ;
void initSprite(t_sprite *s, int c, int h, int w, int x, int y, int dy, const unsigned char *bmp,t_iconMvt *iconsMvt) {
//t_iconMvt iconsMvt[c]; //WIP malloc ?? || Arg
s->count=c; s->h=h; s->w=w; s->x=x; s->y=y; s->dy=dy;
for(int i=0; i< s->count; i++) {
iconsMvt[i].xp = random(1 - s->w, OLED_WIDTH);
iconsMvt[i].yp = -s->h;
iconsMvt[i].dy = random(1, 6);
}
s->bmp=bmp;
s->iconsMvt= iconsMvt;
}
void drawSprite(t_sprite *s, Adafruit_SSD1306 d) {
//int8_t iconsMvt[FLOCONS][3];
d.clearDisplay();
for(int i=0; i < s->count; i++) {
d.drawBitmap(
s->iconsMvt[i].xp, s->iconsMvt[i].yp, s->bmp, s->w, s->h, SSD1306_WHITE);
}
//d.display(); // Show the display buffer on the screen
}
void updateSprite(t_sprite *s) {
for(int i=0; i < s->count; i++) {
s->iconsMvt[i].yp += s->iconsMvt[i].dy;
// If sprite is off the bottom of the screen...
if (s->iconsMvt[i].yp >= OLED_HEIGHT) {
// Reinitialize to a random position, just off the top
s->iconsMvt[i].xp = random(1 - s->w, OLED_WIDTH);
s->iconsMvt[i].yp = -s->h; // HEIGHT
s->iconsMvt[i].dy = random(1, 6);
}
} // f=0; f< sprites.count; f++)
}
#endif // _INSOLAB_DISPLAYS_H_