From a7dd5da69894321fef37c315c852b877ca57f84b Mon Sep 17 00:00:00 2001 From: jearz Date: Fri, 22 May 2026 18:19:07 +0200 Subject: [PATCH] =?UTF-8?q?Finalisation=20gestion=20d'icones=20dans=20l'?= =?UTF-8?q?=C3=A9cran=20de=20veille.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correction fonctions de gestion des icones. Ajout et modification des bitmaps d'icones. Ajout fonction de changement d'icone en cours de déroulement. --- minuteur/bitmaps.h | 25 +++++++--------- minuteur/displays.h | 48 +++++++++++++++++++++--------- minuteur/minuteur.ino | 68 +++++++++---------------------------------- 3 files changed, 58 insertions(+), 83 deletions(-) diff --git a/minuteur/bitmaps.h b/minuteur/bitmaps.h index c28a45d..8e1fd6e 100644 --- a/minuteur/bitmaps.h +++ b/minuteur/bitmaps.h @@ -85,31 +85,26 @@ void playPop(){ anyrtttl::blocking::play(PIEZO, _pop_);} void playClk(){ anyrtttl::blocking::play(PIEZO, _clk_);} // Snooze screen saver -#define SNOOZE_HEIGHT 16 -#define SNOOZE_WIDTH 16 -#define XPOS 0 // Indexes into the 'icons' array in function below -#define YPOS 1 -#define DELTAY 2 -#define _DISPLAYWIDTH 128 -#define _DISPLAYHEIGHT 32 -#define FLOCONS 4 // snowflakes in animation +#define ICON_HEIGHT 16 +#define ICON_WIDTH 16 const unsigned char flake_bmp [] PROGMEM = { - 0x01, 0x80, 0xc3, 0xc3, 0xe3, 0xc7, 0xfb, 0xdf, 0x7f, 0xfe, 0x3f, 0xfc, 0x1f, 0xf8, 0x0f, 0xf0, - 0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe, 0xfb, 0xdf, 0xe3, 0xc7, 0xc3, 0xc3, 0x01, 0x80 + 0x00, 0x00, 0x00, 0x70, 0x38, 0x70, 0x38, 0x70, 0x3c, 0xe0, 0x0e, 0xee, 0x07, 0xce, 0x1f, 0xfe, + 0x7f, 0xf0, 0x73, 0xc0, 0x77, 0xe0, 0x07, 0x78, 0x0f, 0x78, 0x0e, 0x38, 0x0e, 0x00, 0x00, 0x00 }; // 'smiley', 16x16px const unsigned char smiley_bmp [] PROGMEM = { 0x07, 0xc0, 0x1f, 0xf0, 0x3f, 0xf8, 0x7f, 0xfc, 0x63, 0x8c, 0xdd, 0x76, 0xd3, 0x96, 0xe7, 0xce, - 0xff, 0xfe, 0xfd, 0x7e, 0x6f, 0xec, 0x73, 0x9c, 0x3c, 0x78, 0x1f, 0xf0, 0x07, 0xc0, 0x00, 0x00 + 0xff, 0xfe, 0xfd, 0x7e, 0x67, 0xcc, 0x70, 0x1c, 0x3c, 0x78, 0x1f, 0xf0, 0x07, 0xc0, 0x00, 0x00 }; // 'frown', 16x16px const unsigned char frown_bmp [] PROGMEM = { 0x07, 0xc0, 0x1f, 0xf0, 0x3f, 0xf8, 0x67, 0xcc, 0x53, 0x94, 0xdd, 0x76, 0xd9, 0x36, 0xe1, 0x0e, 0xff, 0xfe, 0xff, 0xfe, 0x78, 0x3c, 0x73, 0x9c, 0x37, 0xd8, 0x1f, 0xf0, 0x07, 0xc0, 0x00, 0x00 }; -//sprite_t smiley = { 6, 16, 16, 0, 1, 2, smiley_bmp }; -//sprite_t frown = { unsigned short c6, 16, 16, 0, 1, 2, frown_bmp }; - - +// 'neutral', 16x16px +const unsigned char neutral_bmp [] PROGMEM = { + 0x07, 0xc0, 0x1f, 0xf0, 0x3f, 0xf8, 0x67, 0xcc, 0x53, 0x94, 0xdd, 0x76, 0xd9, 0x36, 0xe1, 0x0e, + 0xff, 0xfe, 0xfd, 0x7e, 0x7f, 0xfc, 0x70, 0x1c, 0x3f, 0xf8, 0x1f, 0xf0, 0x07, 0xc0, 0x00, 0x00 +}; #endif // _INSOLAB_BITMAP_H_ diff --git a/minuteur/displays.h b/minuteur/displays.h index d87fa98..971aeb5 100644 --- a/minuteur/displays.h +++ b/minuteur/displays.h @@ -75,6 +75,7 @@ void showInit() { delay(100); // Serial.println(_oledmsg); } void showLOGO(int16_t gt) { /*--------- logo on SSD1306 -------------*/ + ledRGB(BLANK); oled.clearDisplay(); oled.invertDisplay(true); oled.drawBitmap( LOGO_X0, LOGO_Y0,logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, LOGO_COLOR); @@ -84,6 +85,7 @@ void showLOGO(int16_t gt) { /*--------- logo on SSD1306 -------------*/ oled.invertDisplay(false); } void showTITRE() { // TextSize(2)=>10char, TextSize(1)=>22char, + ledRGB(GREEN); oled.clearDisplay(); oled.setCursor(0,0); oled.setTextSize(2); // doble scale oled.setTextColor(SSD1306_WHITE); @@ -142,32 +144,32 @@ void showSAUVE(uint16_t t, char* txt) { oled.display(); } typedef struct s_iconMvt { - int xp,yp,dy; + int xp,yp,dx,dy; // x & y position, dx & dy to add for next move } t_iconMvt; typedef struct s_sprite { - int count, h, w, x, y, dy; - const unsigned char *bmp; - t_iconMvt *iconsMvt; + int count, h, w; // sprite count & sizes + const unsigned char *bmp; // bitmap address + t_iconMvt *iconsMvt; // icons displacement } t_sprite ; +//const unsigned char *Abmp[] = {&flake_bmp, &smiley_bmp, &frown_bmp}; -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; +void initSprite(t_sprite *s, int c, int w, int h, const unsigned char *bmp, t_iconMvt *icons) { + s->count=c; s->h=h; s->w=w; + s->iconsMvt=icons; 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->iconsMvt[i].xp = random(1 - w, OLED_WIDTH); + s->iconsMvt[i].yp = - h; + s->iconsMvt[i].dy = random(1, 6); } s->bmp=bmp; - s->iconsMvt= iconsMvt; } -void drawSprite(t_sprite *s, Adafruit_SSD1306 d) { +void drawSprite(t_sprite *s) { //int8_t iconsMvt[FLOCONS][3]; - d.clearDisplay(); + oled.clearDisplay(); for(int i=0; i < s->count; i++) { - d.drawBitmap( + oled.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 @@ -184,4 +186,22 @@ void updateSprite(t_sprite *s) { } } // f=0; f< sprites.count; f++) } +uint16_t changeSprite(t_sprite *s, uint16_t count){ + count++; + if ( count >100 && count <= 200) { + s->bmp = smiley_bmp; + } + else if ( count >200 && count <= 300) { + s->bmp = neutral_bmp; + } + else if ( count >300 && count <= 400) { + s->bmp = frown_bmp; + } + else if ( count >400 && count <= 500) { + s->bmp = flake_bmp; + } + else if ( count >500 ) count = 0; + + return count; +} #endif // _INSOLAB_DISPLAYS_H_ diff --git a/minuteur/minuteur.ino b/minuteur/minuteur.ino index 6190b6b..85294bd 100644 --- a/minuteur/minuteur.ino +++ b/minuteur/minuteur.ino @@ -32,6 +32,8 @@ - return to caller on time out * Sleep mode not stable, forum at : "https://github.com/earlephilhower/arduino-pico/issues/345" + ----------------------------------------------------------------------- + Mod: 2026/05/27 added 2 bitmap to sreen saver -----------------------------------------------------------------------*/ #define BUTTONPLUS 14 // PullUp 10K I=.33 mA #define BUTTONMINUS 15 // PullUp 10K I=.33 mA @@ -61,7 +63,7 @@ volatile uint16_t downTime; // count down time volatile uint16_t lastSetTime, lastStepTime, time2save=0; volatile boolean plusPushed=false; volatile boolean minusPushed=false; char sMsg[16]; -screen_t screen=sTITRE; +screen_t screen=sNONE; #include #include "displays.h" // Oled functions & led RGB #include "pt.h" // proto threads @@ -120,7 +122,7 @@ void setup() { lastStepTime=stepTime; showLOGO(greetTime); minusPushed=false; plusPushed=false; // in case button pushed while LOGO - ledRGB(GREEN); + screen=sTITRE; } void loop() { // CPU 0 dedicated to refresh display // TODO not recall screen if values did not change @@ -328,71 +330,30 @@ static PT_THREAD(pSauve(pt_t *lc)) { // } static PT_THREAD(pVeille(pt_t *lc)) { // OK and avoid bounces - static int8_t f, icons[FLOCONS][3]; - PT_BEGIN(lc); - PT_WAIT_UNTIL(lc, (screen==sVEILLE)); - ledRGB(NONE); - for(f=0; f< FLOCONS; f++) { - icons[f][XPOS] = random(1 - SNOOZE_WIDTH, oled.width()); - icons[f][YPOS] = -SNOOZE_HEIGHT; - icons[f][DELTAY] = random(1, 6); - } - do { - oled.clearDisplay(); - for(f=0; f< FLOCONS; f++) { // ~ 10 ok for this screen - oled.drawBitmap( - icons[f][XPOS], icons[f][YPOS], flake_bmp, - SNOOZE_WIDTH, SNOOZE_HEIGHT, SSD1306_WHITE); - } - PT_DELAY(lc, 80); - if (!(plusPushed || minusPushed)) { - oled.display(); - PT_DELAY(lc, 80); - // Then update coordinates of each icon - for(f=0; f< FLOCONS; f++) { - icons[f][YPOS] += icons[f][DELTAY]; - // If snowflake is off the bottom of the screen... - if (icons[f][YPOS] >= oled.height()) { - // Reinitialize to a random position, just off the top - icons[f][XPOS] = random(1 - SNOOZE_WIDTH, oled.width()); - icons[f][YPOS] = -SNOOZE_HEIGHT; - icons[f][DELTAY] = random(1, 6); - } - //PT_DELAY(lc, 100); - } // f=0; f< NUMFLAKES; f++) - } - } while (!(plusPushed || minusPushed )); - minusPushed=false; plusPushed=false; - oled.clearDisplay(); - PT_DELAY(lc, 200); - screen=sTITRE; //sCHOIX;// - PT_END(lc); // to try: exit & return flag ? -} - -#define ICONS 4 -t_iconMvt icons[ICONS]; -t_sprite sprite; - -static PT_THREAD(pBugVeille(pt_t *lc)) { // OK and avoid bounces + const int nbSprites = 10; + static t_iconMvt icons[nbSprites]; + static t_sprite sprite; + static uint16_t nbpass=0; PT_BEGIN(lc); PT_WAIT_UNTIL(lc, (screen==sVEILLE)); ledRGB(NONE); - initSprite(&sprite,ICONS,16,16,0,1,2, flake_bmp, icons); // load values to sprite + initSprite(&sprite,nbSprites,16,16, flake_bmp, icons); // load values to sprite do { - drawSprite(&sprite, oled); - PT_DELAY(lc, 80); + drawSprite(&sprite); + PT_DELAY(lc, 40); if (!(plusPushed || minusPushed)) { oled.display(); - PT_DELAY(lc, 80); + PT_DELAY(lc, 40); updateSprite(&sprite); // update coordinates of each sprite } + nbpass = changeSprite(&sprite, nbpass); } while (!(plusPushed || minusPushed )); minusPushed=false; plusPushed=false; oled.clearDisplay(); PT_DELAY(lc, 200); - screen=sCHOIX;// sTITRE; // + screen=sTITRE; // sCHOIX;// PT_END(lc); // to try: exit & return flag ? } @@ -408,7 +369,6 @@ void loop1() { // CPU 1 dedicated to run threads pDuree (&pDUREE); // process screen DUREE pSauve (&pSAUVE); // process screen SAUVE pVeille(&pVEILLE); // process screen saver - } /* * code debug