commit 80dedb840f10a48675e7507667297d61021e838a Author: Michael Wesemann Date: Tue Oct 13 19:55:01 2026 +0200 initial commit [141.14.129.234,mike] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bbb08e --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +.DS_Store +.AppleDouble +.LSOverride +._* +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes + +# Zugangsdaten: API-Token für mgsh, WLAN-Passwörter (Vorlage: firmware/secrets.h.example) +.mgshrc +firmware/secrets.h + +# Build-Ausgaben und erzeugte Vorschaubilder +.build/ +.preview/ + +# temporäre Dateien +cad/.check/ +tmp/ diff --git a/blink/blink.ino b/blink/blink.ino new file mode 100644 index 0000000..a191c06 --- /dev/null +++ b/blink/blink.ino @@ -0,0 +1,27 @@ +// Blink-Test für den Seeed Studio XIAO ESP32-C3. +// Das Board hat keine eigene User-LED: externe LED mit ~220 Ω Vorwiderstand an D10 gegen GND. +// Jeder Takt wird zusätzlich über USB-Serial ausgegeben, dazu der Zustand der BOOT-Taste. + +const int LED_PIN = D10; +const int BOOT_BUTTON_PIN = 9; // BOOT-Taste auf der Platine, gedrückt = LOW +const unsigned long BLINK_INTERVAL_MS = 500; + +void setup() { + Serial.begin(115200); + pinMode(LED_PIN, OUTPUT); + pinMode(BOOT_BUTTON_PIN, INPUT_PULLUP); +} + +void loop() { + static bool ledOn = false; + static unsigned long count = 0; + + ledOn = !ledOn; + digitalWrite(LED_PIN, ledOn ? HIGH : LOW); + + bool buttonPressed = digitalRead(BOOT_BUTTON_PIN) == LOW; + Serial.printf("#%lu LED %s | BOOT-Taste %s\n", ++count, ledOn ? "an " : "aus", + buttonPressed ? "gedrückt" : "-"); + + delay(BLINK_INTERVAL_MS); +} diff --git a/cad/esticky.scad b/cad/esticky.scad new file mode 100644 index 0000000..741f443 --- /dev/null +++ b/cad/esticky.scad @@ -0,0 +1,128 @@ + +$fn=128; +w=2; +x=90+(14-8.5); +y=38.5; +h=14; + +T(0,45,0) top(); +T(0,0,0) bottom(); + +o=0.06; + +xo=20; + +ih=4.8; + +bh=4; // Höhe des Bodens, auf dem das Oberteil aufsitzt + +// Taster (SMD 6x3 mm, 5 mm hoch inkl. Knopf) an der rechten Schmalseite, Knopf zeigt nach außen. +// Ein Taster: kurz drücken = nächste App, lang drücken = Neustart. Weitere Taster als weitere Einträge in sw_y/sw_out. +// Maße in Einbaulage, also in den Koordinaten von bottom(); ins Oberteil mit flip_to_top(). +sw_l=6.2; // Länge, entlang der Wand +sw_b=3.7; // Breite, in Einbaulage senkrecht +sw_h=3.5; // Höhe ohne Knopf +sw_k=1.5; // Knopf steht über das Gehäuse +sw_kl=2.6; // Knopf Länge +sw_kb=1.8; // Knopf Breite +sw_s=0.15; // Spiel um das Tastergehäuse +sw_ks=0.3; // Spiel um den Knopf +sw_wd=1.2; // Wandstärke der Halterung +sw_z=8.5; // Mitte der Taster über der Unterseite +sw_y=[(y+w+w)/2]; // Mitte der Schmalseite +sw_out=[0.5]; // Knopf steht 0,5 mm über die Außenwand (negativ = versenkt) +sw_cl=sw_l+2*sw_s+2*sw_wd; +sw_cb=sw_b+2*sw_s+2*sw_wd; +function sw_front(i)=x+w+w+sw_out[i]-sw_k; // Vorderseite Tastergehäuse +function sw_back(i)=sw_front(i)-sw_h; + +module bottom() { + D() { + U() { + RC(x+w+w,y+w+w,4,2,2); + T(w+o/2,w+o/2,0.5) RC(x-o,y-o,ih+4,1,1); + } + T(w+o/2+w,w+o/2+w,w) RC(x-o-w-w,y-o-w-w,ih+4,1,1); + T(xo-9,w-0.1,w) C(18,21.5,16); + switch_lip_notches(); + } + + D() { + T(xo-9-w,w,0) C(18+w+w,21.5+w,8.5); + T(xo-9,w-0.1,w) C(18,21.5,16); + T(xo-9+4,w-0.1,w) C(10,31.5,16); + } + T(xo-9,21.5+w-9-5,w) C(18,9,3); + switch_backstops(); +} + +module top() { + D() { + U() { + D() { + RC(x+w+w,y+w+w,h,2,2); + T(w,w,0.5) RC(x,y,20,1,1); + T(w+14,w+4.5,-1) RC(x-14-14,y-4.5-4.5,20,1,1); + + T(xo-4.5,y,h-3.45) C(9.5,10,3.5); + + } + flip_to_top() switch_cradles(); + } + flip_to_top() switch_cutouts(); + } + T(w,w,0) C(4.8,y,4); +} + +// Geometrie aus Einbaulage ins Oberteil übertragen (Oberteil wird umgedreht auf den Boden gesetzt) +module flip_to_top() { T(0,y+w+w,h+bh) R(180,0,0) children(); } + +// Taschen für die Taster an der Innenwand des Oberteils, hinten offen zum Einschieben +module switch_cradles() { + for (i=[0:len(sw_y)-1]) { + x0=sw_back(i)+0.8; // die letzten 0,8 mm bleiben frei für die Lötbeinchen + d=x+w+0.5-x0; + T(x0,sw_y[i]-sw_cl/2,sw_z-sw_cb/2) H() { // 45°-Schräge zum Display, druckt ohne Stützen + C(d,sw_cl,sw_cb); + T(d-0.01,0,0) C(0.01,sw_cl,sw_cb+d); + } + } +} + +// Platz für Tastergehäuse (bei vorstehendem Knopf 1 mm in die Wand) und Loch für den Knopf +module switch_cutouts() { + for (i=[0:len(sw_y)-1]) { + T(sw_back(i)-1,sw_y[i]-sw_l/2-sw_s,sw_z-sw_b/2-sw_s) C(sw_h+1.01,sw_l+2*sw_s,sw_b+2*sw_s); + T(sw_front(i)-0.01,sw_y[i]-sw_kl/2-sw_ks,sw_z-sw_kb/2-sw_ks) C(w+2,sw_kl+2*sw_ks,sw_kb+2*sw_ks); + } +} + +// Aussparungen im Rand des Unterteils, damit die Taschen beim Zusammenstecken vorbeipassen +module switch_lip_notches() { + for (i=[0:len(sw_y)-1]) T(x-o/2-0.2,sw_y[i]-sw_cl/2-0.3,sw_z-sw_cb/2-0.3) C(w+0.4,sw_cl+0.6,20); +} + +// Rippen hinter den Tastern, damit sie beim Drücken nicht nach innen ausweichen +module switch_backstops() { + for (i=[0:len(sw_y)-1]) T(sw_back(i)-0.2-1.6,sw_y[i]-1.5,w) C(1.6,3,sw_z+sw_b/2-w); +} +//////////////////////////////////////////////////////////////////////////////////////////////// + + +module D() { difference() { children(0);children([1:1:$children-1]); } } +module I() { intersection() { children(0);children([1:1:$children-1]); } } +module U() { union() { children(); } } +module H() { hull() { children(); } } +module R(x,y,z) { rotate([x,y,z]) children(); } +module T(x,y,z) { translate([x,y,z]) children(); } +module C(x,y,z) { cube([x,y,z]); } +module Z(h,d) { cylinder(h,d/2,d/2); } +module ZZ(h,d,e) { cylinder(h,d/2,e/2); } +module RC(xd ,yd ,zd,ra,rb) { + hull() { + T(ra,ra,0) if (ra==0) { Z(zd,0.0001); } else { Z(zd,ra*2); } + T(xd-ra,ra,0) if (ra==0) { Z(zd,0.0001); } else { Z(zd,ra*2); } + T(rb,yd-rb,0) if (rb==0) { Z(zd,0.0001); } else { Z(zd,rb*2); } + T(xd-rb,yd-rb,0) if (rb==0) { Z(zd,0.0001); } else { Z(zd,rb*2); } + } +} diff --git a/cad/esticky_v2.scad b/cad/esticky_v2.scad new file mode 100644 index 0000000..52934b5 --- /dev/null +++ b/cad/esticky_v2.scad @@ -0,0 +1,239 @@ +// esticky Gehäuse V2: Rahmen mit Display vorne, Deckel hinten trägt die gesamte Elektronik +// (XIAO, Taster, Akku). Zwischen den Teilen nur der Display-Stecker. +// Montage: Display in den Rahmen legen, Stecker aufs Display, Deckel rechts etwas nach links +// versetzt ansetzen, nach rechts schieben (Laschen greifen in die Nuten), links absenken, +// 2 Schrauben M2 x 4 oder M2 x 5 in die Einschmelzgewinde drehen. +// Koordinaten: x Länge, y Breite (USB-Seite bei y max), z von der Front (0) nach hinten. + +$fn=64; + +T(0,0,0) frame(); +T(0,2*(y+w+w)+5,zl+lid_t) R(180,0,0) lid(); // Deckel mit der Innenseite nach oben drucken + +// --- aus V1 übernommen --- +w=2; // Wandstärke +x=90+(14-8.5); // Innenlänge +y=38.5; // Innenbreite +face=0.5; // Stärke der Front +xo=20; // Mitte des XIAO in x +bar=4.8; // Steg links, damit die aktive Displayfläche mittig im Fenster liegt + +// --- Display (Waveshare 2.9" Rev2.1) --- +disp_l=89.5; +disp_b=38; +disp_t=3.5; // Dicke inkl. Bauteilen hinten – bitte nachmessen +disp_free=4.8; // freier Raum hinter dem Display für Stecker und Kabel; dort nur die Andrückstege +standoff_h=6; // Messing-Abstandsbolzen hinten in den Ecken (ca. 3 mm von den Kanten), Stege weichen ihnen aus +post_w=5; // Länge der Andrückstege entlang der Displaykante + +// --- XIAO ESP32-C3: Bauteilseite (USB-C) zum Deckel, Rückseite mit den Lötstellen zum Display --- +// Gehalten nur über die flache Rückseite: an der fernen Schmalseite eine feste Lippe, +// an der USB-Seite zwei Rastarme neben den Ecken (vor den ersten Pins). +xiao_l=21; +xiao_b=17.8; +xiao_pcb=1.3; // Platinendicke (gemessen) +xiao_usb_h=3.3; // Höhe der USB-Buchse über der Platine (gemessen), sie liegt auf dem Deckel auf +usb_over=1.2; // USB-Buchse steht über die Platinenkante (gemessen) +usb_w=9.5; // Durchbruch für die Buchse, nach oben offen (der Deckel schließt ihn) +plug_w=13; // Senkung außen in Rahmen und Deckel, damit der Stecker tief genug hineingeht +plug_h=7.5; +plug_d=1.4; +lip=1.5; // so weit greift die Lippe über die ferne Schmalseite +clip_nose=0.8; // so weit greifen die Rastnasen über die Rückseite +clip_t=0.9; // Dicke der Rastarme +clip_relief=1; // Rastarme beginnen in einer Vertiefung im Deckel, das macht sie länger und biegsamer + +// --- LiPo-Akku im Fach auf dem Deckel --- +bat_l=33; // gemessen +bat_b=20; +bat_t=8.5; +bat_x=41.5; // Beginn des Akkufachs in x + +// --- Taster (SMD), Knopf zeigt nach rechts auf die Druckzunge in der Wand --- +sw_l=6.2; // Länge, entlang der Wand +sw_b=3.7; // Breite, in Einbaulage senkrecht +sw_h=3.5; // Höhe ohne Knopf +sw_k=1.5; // Knopf steht über +sw_lift=1.4; // Abstand Taster–Deckel +sw_y=(y+w+w)/2; +key_t=1.2; // Dicke der Druckzunge (PLA; bei PETG eher 1.4) +key_gap=0.3; // Luft zwischen Knopf und Noppen der Zunge + +// --- Deckel und Befestigung --- +lid_t=2; +s=0.2; // allgemeines Spiel +insert_d=3.2; // Loch für Einschmelzgewinde M2 (Außen-Ø ca. 3.6, Länge 3 mm) +insert_l=4; // Lochtiefe: Gewindelänge plus Platz für verdrängtes Material +screw_x=w+1.8; // Schraubenmitte nah an der Außenwand, damit rundum genug Material bleibt +screw_y=[8,y+w+w-8]; +boss_b=8; // Breite der Schraubdome in y +hook_y=[6.5,y+w+w-6.5]; + +// --- abgeleitete Maße --- +zd=face+disp_t; // Rückseite des Displays +clip_h=1.3; // Rastnase plus Spiel unter der Platinenrückseite +zl=zd+disp_free+max(bat_t,clip_h+xiao_pcb+xiao_usb_h); // Innenseite Deckel = Höhe Rahmen +xiao_x0=xo-xiao_b/2; +xiao_y1=y+w-s; // Platinenkante an der USB-Seite +xiao_y0=xiao_y1-xiao_l; +xiao_zc=zl-xiao_usb_h; // Bauteilseite +xiao_zb=xiao_zc-xiao_pcb; // Rückseite +usb_z=zl-xiao_usb_h/2; // Mitte der USB-Buchse +sw_tip=x+w-s; // Knopfspitze knapp vor der Wandinnenseite +sw_front=sw_tip-sw_k; +sw_back=sw_front-sw_h; +sw_zt=zl-sw_lift; // Seite zum Deckel +sw_zb=sw_zt-sw_b; // Seite zum Display +sw_z=(sw_zt+sw_zb)/2; +key_y0=sw_y-10; // Gelenk der Zunge +key_y1=sw_y+2; // freies Ende +key_h=4.2; + +//////////////////////////////////////////////////////////////////////////////////////////////// + +module frame() { + D() { + U() { + D() { + RC(x+w+w,y+w+w,zl,2,2); + T(w,w,face) RC(x,y,zl,1,1); + } + T(w,w,0) C(bar,y,zd); + for (sy=screw_y) T(w,sy-boss_b/2,zd) C(bar,boss_b,zl-zd); // Schraubdome auf dem Steg + } + T(w+14,w+4.5,-1) RC(x-14-14,y-4.5-4.5,20,1,1); // Fenster + for (sy=screw_y) { + T(screw_x,sy,zl-insert_l) Z(insert_l+1,insert_d); // Einschmelzgewinde + T(screw_x,sy,zl-insert_l-3) Z(3.01,1.8); // Platz für die Schraubenspitze + } + // USB-C: Durchbruch nach oben offen, die Buchse gleitet beim Aufsetzen des Deckels hinein + T(xo-usb_w/2,y+w-1,usb_z-xiao_usb_h/2-0.3) C(usb_w,w+2,zl); + usb_plug_recess(); + key_cutout(); + // Nuten für die Laschen des Deckels + for (hy=hook_y) T(x+w-0.01,hy-2.5-s,zl-2.8) C(0.9,5+2*s,1.2); + } + key_nub(); +} + +// Druckzunge in der rechten Wand: U-förmiger Schlitz, innen verdünnt, außen eine Mulde als Tastpunkt +module key_cutout() { + slot=0.6; + z0=sw_z-key_h/2; + T(x+w-1,key_y0,z0+key_h) C(w+2,key_y1+slot-key_y0,slot); + T(x+w-1,key_y0,z0-slot) C(w+2,key_y1+slot-key_y0,slot); + T(x+w-1,key_y1,z0-slot) C(w+2,slot,key_h+2*slot); + T(x+w-1,key_y0,z0) C(1+w-key_t,key_y1-key_y0,key_h); + T(x+w+w+2.6,sw_y,sw_z) sphere(r=3); +} + +// Senkung außen für den USB-Stecker, geht durch Rahmenwand und Deckelkante +module usb_plug_recess() { + T(xo-plug_w/2,y+w+w-plug_d,usb_z-plug_h/2) C(plug_w,plug_d+1,plug_h); +} + +// Noppen auf der Zunge, drückt auf den Knopf; bündig mit der Wandinnenseite +module key_nub() { + T(sw_tip+key_gap,sw_y,sw_z) R(0,90,0) Z(x+w+w-key_t-sw_tip-key_gap+0.01,1.6); +} + +//////////////////////////////////////////////////////////////////////////////////////////////// + +module lid() { + D() { + T(0,0,zl) RC(x+w+w,y+w+w,lid_t,2,2); + for (sy=screw_y) { + T(screw_x,sy,zl-1) Z(lid_t+2,2.4); + T(screw_x,sy,zl+lid_t-1.2) Z(2,4.2); // Senkung für den Schraubenkopf + } + usb_plug_recess(); + clip_reliefs(); + } + // Laschen rechts, greifen in die Nuten der Wand + for (hy=hook_y) { + T(x+w-s-1.2,hy-2.5,zl-3) C(1.2,5,3.01); + T(x+w-s-0.01,hy-2.5,zl-2.6) C(0.71,5,0.8); + } + xiao_holder(); + switch_holder(); + battery_tray(); + display_posts(); +} + +// Platine erst mit der fernen Schmalseite unter die Lippe schieben, dann die USB-Seite +// zwischen die Rastarme drücken. Beides greift nur über die flache Rückseite. +module xiao_holder() { + x0=xiao_x0+1; + x1=xiao_x0+xiao_b-1; + T(x0,xiao_y0-s-1.5,xiao_zb-clip_h) C(x1-x0,1.5,zl-xiao_zb+clip_h+0.01); // Anschlag + T(x0,xiao_y0-s-1.5,xiao_zb-clip_h) C(x1-x0,1.5+s+lip,clip_h-0.1); // Lippe über der Rückseite + + for (mx=[0,1]) T(xo,0,0) mirror([mx,0,0]) T(-xo,0,0) { + ya=xiao_y1-2; // nur vor dem ersten Pin + yb=xiao_y1-0.3; + T(xiao_x0-s-clip_t,ya,xiao_zb-clip_h) C(clip_t,yb-ya,zl-xiao_zb+clip_h+clip_relief); + H() { // Rastnase, Anlaufschräge zum Display hin + T(xiao_x0-s,ya,xiao_zb-0.11) C(clip_nose+s,yb-ya,0.01); + T(xiao_x0-s,ya,xiao_zb-clip_h) C(0.01,yb-ya,0.01); + } + } +} + +// Vertiefungen im Deckel, in denen die Rastarme beginnen +module clip_reliefs() { + for (mx=[0,1]) T(xo,0,0) mirror([mx,0,0]) T(-xo,0,0) + T(xiao_x0-s-clip_t-0.5,xiao_y1-2-0.5,zl-0.01) C(clip_t+1,2.7,clip_relief+0.01); +} + +// Taster liegt auf einem Sockel, seitlich eingerastet, hinten abgestützt (Lötbeinchen bleiben frei) +module switch_holder() { + T(sw_back,sw_y-sw_l/2,sw_zt) C(sw_h,sw_l,sw_lift+0.01); + for (m=[0,1]) T(0,sw_y,0) mirror([0,m,0]) T(0,-sw_y,0) { + yw=sw_y+sw_l/2+0.1; // Innenseite der Seitenwand + T(sw_back+0.8,yw,sw_zb-0.86) C(sw_front-sw_back-0.8,1.2,zl-sw_zb+0.87); + H() { // Rastnase über der Displayseite des Tasters + T(sw_back+0.8,yw-0.5,sw_zb-0.06) C(sw_front-sw_back-0.8,0.5,0.01); + T(sw_back+0.8,yw,sw_zb-0.86) C(sw_front-sw_back-0.8,0.01,0.01); + } + } + T(sw_back-0.2-1.6,sw_y-1.5,sw_zb) C(1.6,3,zl-sw_zb+0.01); +} + +// Akkufach, zum XIAO hin offen für das Kabel +module battery_tray() { + ib=bat_b+2*s; + T(bat_x-s-1.2,(y+w+w)/2-ib/2-1.2,zl-3) D() { + C(bat_l+2*s+2.4,ib+2.4,3.01); + T(1.2,1.2,-1) C(bat_l+2*s,ib,5); + T(-1,(ib+2.4)/2-5,-1) C(3.4,10,5); + } +} + +// Stege, die das Display an den Längskanten nach vorne drücken; mit Abstand zu den Bolzen in den Ecken +module display_posts() { + e=(y+w+w-disp_b)/2; + for (p=[[16,0],[33,0],[61,0],[84,0],[36,1],[61,1],[84,1]]) { + py=p[1]==0?e+s:y+w+w-e-s-1.45; + T(p[0]-post_w/2,py,zd) C(post_w,1.45,zl-zd+0.01); + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////// + +module D() { difference() { children(0);children([1:1:$children-1]); } } +module I() { intersection() { children(0);children([1:1:$children-1]); } } +module U() { union() { children(); } } +module H() { hull() { children(); } } +module R(x,y,z) { rotate([x,y,z]) children(); } +module T(x,y,z) { translate([x,y,z]) children(); } +module C(x,y,z) { cube([x,y,z]); } +module Z(h,d) { cylinder(h,d/2,d/2); } +module ZZ(h,d,e) { cylinder(h,d/2,e/2); } +module RC(xd ,yd ,zd,ra,rb) { + hull() { + T(ra,ra,0) if (ra==0) { Z(zd,0.0001); } else { Z(zd,ra*2); } + T(xd-ra,ra,0) if (ra==0) { Z(zd,0.0001); } else { Z(zd,ra*2); } + T(rb,yd-rb,0) if (rb==0) { Z(zd,0.0001); } else { Z(zd,rb*2); } + T(xd-rb,yd-rb,0) if (rb==0) { Z(zd,0.0001); } else { Z(zd,rb*2); } + } +} diff --git a/cad/switch.png b/cad/switch.png new file mode 100644 index 0000000..41a61f8 Binary files /dev/null and b/cad/switch.png differ diff --git a/display_test/display_test.ino b/display_test/display_test.ino new file mode 100644 index 0000000..bc85650 --- /dev/null +++ b/display_test/display_test.ino @@ -0,0 +1,37 @@ +// Display-Test für das Waveshare 2.9" e-Paper Module Rev2.1 (296x128, SSD1680, schwarz/weiß) +// am Seeed Studio XIAO ESP32-C3. +// Verkabelung: VCC+PWR→3V3, GND→GND, DIN→D10, CLK→D8, CS→D1, DC→D2, RST→D5, BUSY→D4. + +#include +#include +#include + +GxEPD2_BW display( + GxEPD2_290_T94_V2(/*CS=*/D1, /*DC=*/D2, /*RST=*/D5, /*BUSY=*/D4)); + +void setup() { + // Diagnose-Ausgabe auf USB-Serial (Busy-Zeiten), 2 ms Reset-Puls für Waveshare-Boards + display.init(115200, true, 2, false); + display.setRotation(1); // Querformat 296x128 + display.setTextColor(GxEPD_BLACK); + + display.setFullWindow(); + display.firstPage(); + do { + display.fillScreen(GxEPD_WHITE); + display.drawRoundRect(4, 4, display.width() - 8, display.height() - 8, 8, GxEPD_BLACK); + display.setFont(&FreeSansBold18pt7b); + display.setCursor(20, 50); + display.print("esticky"); + display.setFont(&FreeSans9pt7b); + display.setCursor(20, 85); + display.print("Hallo vom XIAO ESP32-C3!"); + display.setCursor(20, 110); + display.print("Waveshare 2.9\" Rev2.1"); + } while (display.nextPage()); + + display.hibernate(); // Bild bleibt ohne Strom stehen + Serial.println("Display aktualisiert, Display im Ruhezustand."); +} + +void loop() {} diff --git a/firmware/firmware.ino b/firmware/firmware.ino new file mode 100644 index 0000000..473deb6 --- /dev/null +++ b/firmware/firmware.ino @@ -0,0 +1,406 @@ +// esticky-Firmware: E-Paper-Notizzettel mit mehreren Apps, umschaltbar mit einem Taster. +// Taster kurz = nächste App, lang (2 s) = Neustart. Zwischen den Aktualisierungen Deep Sleep. +// Hardware: XIAO ESP32-C3 + Waveshare 2.9" e-Paper Rev2.1 (4 Graustufen über GxEPD2_4G). +// Verkabelung: VCC+PWR→3V3, GND→GND, DIN→D10, CLK→D8, CS→D1, DC→D2, RST→D5, BUSY→D4, +// Taster D3↔GND, Akku-Spannungsteiler 2×200 kΩ an D0. +// Kompilieren mit PartitionScheme=min_spiffs (Programm > 1,2 MB). +// Mit -DESTICKY_PREVIEW wird jedes Bild zusätzlich über Serial ausgegeben und der Deep Sleep übersprungen. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "secrets.h" +#include "info_view.h" +#include "meteogram_data.h" +#include "meteogram_view.h" +#include "weather_data.h" +#include "weather_view.h" + +enum App : uint8_t { APP_WEATHER, APP_METEOGRAM, APP_INFO, APP_COUNT }; + +const char* LOCATION_NAME = "Berlin"; +const float LATITUDE = 52.52; +const float LONGITUDE = 13.41; + +const uint64_t WEATHER_INTERVAL_US = 30ULL * 60 * 1000 * 1000; +const uint64_t RETRY_INTERVAL_US = 5ULL * 60 * 1000 * 1000; // nach WLAN- oder Abruffehler +const unsigned long UPLOAD_WINDOW_MS = 30000; // nach Reset/Einstecken wach bleiben, damit Uploads klappen +const unsigned long WIFI_TIMEOUT_MS = 20000; +const unsigned long WIFI_REMEMBERED_TIMEOUT_MS = 4000; // danach doch alle bekannten Netze absuchen +const unsigned long LONG_PRESS_MS = 2000; +const int BATTERY_PIN = D0; // Spannungsteiler 2×200 kΩ an BAT+, D0 sieht die halbe Akkuspannung +const int BUTTON_PIN = D3; // Taster gegen GND; nur GPIO0–5 (D0–D3) wecken aus dem Deep Sleep + +using DrawFunction = std::function; + +GxEPD2_4G_4G display( + GxEPD2_290_T94(/*CS=*/D1, /*DC=*/D2, /*RST=*/D5, /*BUSY=*/D4)); +WiFiMulti wifiMulti; +Preferences prefs; + +App currentApp = APP_WEATHER; +bool lastUpdateOk = true; // false: Wetterabruf fehlgeschlagen, bald neuer Versuch +float batteryVoltage = NAN; + +// Zuletzt genutzter Zugangspunkt; der RTC-Speicher übersteht den Deep Sleep, nicht aber Reset oder Stromausfall +struct RememberedWifi { + bool valid; + uint8_t network; // Index in WIFI_NETWORKS + uint8_t bssid[6]; + int32_t channel; +}; +RTC_DATA_ATTR RememberedWifi rememberedWifi = {}; + +// Die gewählte App steht im NVS, damit sie Neustarts und leeren Akku übersteht +App loadApp() { + prefs.begin("esticky", true); + uint8_t app = prefs.getUChar("app", APP_WEATHER); + prefs.end(); + return app < APP_COUNT ? (App)app : APP_WEATHER; +} + +void saveApp(App app) { + prefs.begin("esticky", false); + prefs.putUChar("app", app); + prefs.end(); +} + +// Akkuspannung in Volt, NAN ohne plausiblen Messwert. Vor dem WLAN messen, der Sendestrom drückt die Spannung. +float readBatteryVoltage() { + uint32_t sumMillivolts = 0; + for (int i = 0; i < 16; i++) { + sumMillivolts += analogReadMilliVolts(BATTERY_PIN); + } + float voltage = 2.0f * sumMillivolts / 16 / 1000.0f; + return voltage > 2.5f && voltage < 4.5f ? voltage : NAN; +} + +void rememberWifi() { + for (size_t i = 0; i < sizeof(WIFI_NETWORKS) / sizeof(WIFI_NETWORKS[0]); i++) { + if (WiFi.SSID() == WIFI_NETWORKS[i].ssid) { + rememberedWifi.network = i; + memcpy(rememberedWifi.bssid, WiFi.BSSID(), sizeof(rememberedWifi.bssid)); + rememberedWifi.channel = WiFi.channel(); + rememberedWifi.valid = true; + return; + } + } +} + +// Verbindet zuerst direkt mit dem gemerkten Zugangspunkt (ohne Netzsuche), sonst über alle bekannten Netze +bool connectWifi() { + WiFi.persistent(false); // Zugangsdaten nicht bei jedem Verbinden in den Flash schreiben + WiFi.mode(WIFI_STA); + unsigned long start = millis(); + + if (rememberedWifi.valid) { + const WifiCredentials& network = WIFI_NETWORKS[rememberedWifi.network]; + WiFi.begin(network.ssid, network.password, rememberedWifi.channel, rememberedWifi.bssid); + while (WiFi.status() != WL_CONNECTED && millis() - start < WIFI_REMEMBERED_TIMEOUT_MS) delay(20); + if (WiFi.status() == WL_CONNECTED) { + Serial.printf("WLAN verbunden (gemerkt): %s, %d dBm (%lu ms)\n", WiFi.SSID().c_str(), WiFi.RSSI(), + millis() - start); + return true; + } + Serial.println("WLAN: gemerkter Zugangspunkt nicht erreichbar, suche alle Netze"); + WiFi.disconnect(); + rememberedWifi.valid = false; + } + + static bool networksAdded = false; + if (!networksAdded) { + for (const auto& network : WIFI_NETWORKS) { + wifiMulti.addAP(network.ssid, network.password); + } + networksAdded = true; + } + while (wifiMulti.run() != WL_CONNECTED) { + if (millis() - start > WIFI_TIMEOUT_MS) { + Serial.println("WLAN: keine Verbindung"); + return false; + } + delay(250); + } + rememberWifi(); + Serial.printf("WLAN verbunden (gesucht): %s, IP %s, %d dBm (%lu ms)\n", WiFi.SSID().c_str(), + WiFi.localIP().toString().c_str(), WiFi.RSSI(), millis() - start); + return true; +} + +// Lädt die Antwort von Open-Meteo direkt in doc. Öffentliche Daten ohne Zugangsdaten, +// daher reicht HTTP (spart Zeit und Akku gegenüber TLS). +bool getJson(const char* url, JsonDocument& doc) { + HTTPClient http; + http.useHTTP10(true); // kein Chunked-Encoding, damit ArduinoJson direkt aus dem Stream lesen kann + http.begin(url); + int status = http.GET(); + if (status != HTTP_CODE_OK) { + Serial.printf("Open-Meteo: HTTP-Fehler %d\n", status); + http.end(); + return false; + } + + DeserializationError error = deserializeJson(doc, http.getStream()); + http.end(); + if (error) { + Serial.printf("Open-Meteo: JSON-Fehler %s\n", error.c_str()); + return false; + } + return true; +} + +bool fetchWeather(Weather& weather) { + char url[400]; + snprintf(url, sizeof(url), + "http://api.open-meteo.com/v1/forecast?latitude=%.4f&longitude=%.4f" + "¤t=temperature_2m,relative_humidity_2m,weather_code,wind_speed_10m,is_day" + "&daily=weather_code,temperature_2m_max,temperature_2m_min,precipitation_probability_max" + "&timezone=Europe%%2FBerlin&forecast_days=%d", + LATITUDE, LONGITUDE, FORECAST_DAYS); + JsonDocument doc; + if (!getJson(url, doc)) return false; + + JsonObject current = doc["current"]; + strlcpy(weather.time, current["time"] | "", sizeof(weather.time)); + weather.temperature = current["temperature_2m"]; + weather.humidity = current["relative_humidity_2m"]; + weather.windSpeed = current["wind_speed_10m"]; + weather.weatherCode = current["weather_code"]; + weather.isDay = current["is_day"] == 1; + + JsonObject daily = doc["daily"]; + for (int i = 0; i < FORECAST_DAYS; i++) { + DayForecast& day = weather.days[i]; + strlcpy(day.date, daily["time"][i] | "", sizeof(day.date)); + day.weatherCode = daily["weather_code"][i]; + day.tempMin = daily["temperature_2m_min"][i]; + day.tempMax = daily["temperature_2m_max"][i]; + day.rainProbability = daily["precipitation_probability_max"][i]; + } + + Serial.printf("Open-Meteo: %s, %.1f °C, Code %d, %s\n", weather.time, weather.temperature, weather.weatherCode, + weather.isDay ? "Tag" : "Nacht"); + return true; +} + +bool fetchMeteogram(Meteogram& meteogram) { + char url[400]; + snprintf(url, sizeof(url), + "http://api.open-meteo.com/v1/forecast?latitude=%.4f&longitude=%.4f¤t=temperature_2m" + "&hourly=temperature_2m,precipitation,precipitation_probability" + "&timezone=Europe%%2FBerlin&forecast_days=%d", + LATITUDE, LONGITUDE, METEOGRAM_DAYS); + JsonDocument doc; + if (!getJson(url, doc)) return false; + + strlcpy(meteogram.time, doc["current"]["time"] | "", sizeof(meteogram.time)); + JsonObject hourly = doc["hourly"]; + strlcpy(meteogram.start, hourly["time"][0] | "", sizeof(meteogram.start)); // nur das Datum + float rainTotal = 0; + for (int i = 0; i < METEOGRAM_HOURS; i++) { + meteogram.temperature[i] = hourly["temperature_2m"][i]; + meteogram.precipitation[i] = hourly["precipitation"][i]; + meteogram.rainProbability[i] = hourly["precipitation_probability"][i]; + rainTotal += meteogram.precipitation[i]; + } + + Serial.printf("Open-Meteo: Meteogramm ab %s, %d Stunden, Regen gesamt %.1f mm\n", meteogram.start, + METEOGRAM_HOURS, rainTotal); + return true; +} + +#ifdef ESTICKY_PREVIEW +// Entwicklungshilfe: zeichnet das Bild in einen Canvas und gibt es über Serial aus, eine Zeile pro +// Pixelreihe mit 0 = weiß … 3 = schwarz; tools/capture_preview.py macht daraus PNG-Dateien. +void dumpPreview(const DrawFunction& draw, const char* label) { + GFXcanvas16 canvas(GxEPD2_290_T94::HEIGHT, GxEPD2_290_T94::WIDTH); + draw(canvas); + Serial.printf("PREVIEW-BEGIN %s\n", label); + char row[GxEPD2_290_T94::HEIGHT + 1]; + for (int y = 0; y < canvas.height(); y++) { + for (int x = 0; x < canvas.width(); x++) { + uint16_t c = canvas.getPixel(x, y); + row[x] = c == GxEPD_WHITE ? '0' : c == GxEPD_LIGHTGREY ? '1' : c == GxEPD_DARKGREY ? '2' : '3'; + } + row[canvas.width()] = '\0'; + Serial.println(row); + } + Serial.println("PREVIEW-END"); +} +#endif + +void showOnDisplay(const char* label, const DrawFunction& draw) { + static bool initialized = false; + if (!initialized) { + SPI.begin(SCK, -1, MOSI, -1); // ohne MISO, damit GPIO9 für die BOOT-Taste frei bleibt + display.init(115200, true, 2, false); + display.setRotation(1); // Querformat 296x128 + initialized = true; + } + Serial.printf("Display: %s\n", label); + display.setFullWindow(); + display.firstPage(); + do { + draw(display); + } while (display.nextPage()); + display.hibernate(); // nächstes Zeichnen weckt den Controller per Reset + +#ifdef ESTICKY_PREVIEW + dumpPreview(draw, label); +#endif +} + +// Aktualisiert die aktuelle App. userTriggered (Tastendruck, Neustart): Fehler werden angezeigt; +// bei der Aktualisierung per Timer bleibt nach einem Fehler das letzte Bild stehen. +void runApp(bool userTriggered) { + StatusInfo status = {batteryVoltage, currentApp, APP_COUNT}; + + if (currentApp == APP_INFO) { + lastUpdateOk = true; + showOnDisplay("info", [&](Adafruit_GFX& gfx) { drawInfo(gfx, status); }); + return; + } + + // Wetter und Meteogramm brauchen frische Daten aus dem Netz + Weather weather; + Meteogram meteogram; + bool connected = connectWifi(); + if (currentApp == APP_WEATHER) lastUpdateOk = connected && fetchWeather(weather); + else lastUpdateOk = connected && fetchMeteogram(meteogram); + WiFi.disconnect(true); + WiFi.mode(WIFI_OFF); + + if (lastUpdateOk && currentApp == APP_WEATHER) { + showOnDisplay("wetter", [&](Adafruit_GFX& gfx) { drawWeather(gfx, weather, LOCATION_NAME, status); }); + } else if (lastUpdateOk) { + showOnDisplay("meteogramm", [&](Adafruit_GFX& gfx) { drawMeteogram(gfx, meteogram, LOCATION_NAME, status); }); + } else if (userTriggered) { + const char* title = currentApp == APP_WEATHER ? "Wetter" : "Meteogramm"; + showOnDisplay("meldung", [&](Adafruit_GFX& gfx) { + drawMessage(gfx, title, "Keine Verbindung, neuer Versuch in 5 min", status); + }); + } +} + +void switchToNextApp() { + currentApp = (App)((currentApp + 1) % APP_COUNT); + saveApp(currentApp); + Serial.printf("Taster kurz: App %d\n", currentApp); +} + +// Wartet, solange der Taster gedrückt ist; true, sobald er LONG_PRESS_MS lang gehalten wurde +bool isLongPress(unsigned long pressedSince) { + while (digitalRead(BUTTON_PIN) == LOW) { + if (millis() - pressedSince >= LONG_PRESS_MS) return true; + delay(10); + } + return false; +} + +void restartAfterRelease() { + Serial.println("Taster lang: Neustart"); + while (digitalRead(BUTTON_PIN) == LOW) delay(10); + Serial.flush(); + esp_restart(); +} + +// Behandelt einen Tastendruck, falls der Taster gerade gedrückt ist (solange das Board wach ist) +void pollButton() { + if (digitalRead(BUTTON_PIN) == HIGH) return; + if (isLongPress(millis())) restartAfterRelease(); + delay(30); // Prellen beim Loslassen abwarten + switchToNextApp(); + runApp(true); +} + +// Wetter und Meteogramm alle 30 min (nach Fehler nach 5 min), Info braucht keine Aktualisierung (0 = nur Taster weckt) +uint64_t sleepInterval() { + if (currentApp == APP_INFO) return 0; + return lastUpdateOk ? WEATHER_INTERVAL_US : RETRY_INTERVAL_US; +} + +void goToSleep(uint64_t intervalUs) { + while (digitalRead(BUTTON_PIN) == LOW) delay(10); // sonst weckt der Taster sofort wieder + gpio_pullup_en((gpio_num_t)BUTTON_PIN); + gpio_pulldown_dis((gpio_num_t)BUTTON_PIN); + esp_deep_sleep_enable_gpio_wakeup(1ULL << BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW); + if (intervalUs > 0) esp_sleep_enable_timer_wakeup(intervalUs); + Serial.printf("Deep Sleep: Taster%s\n", intervalUs > 0 ? " oder Timer" : ""); + Serial.flush(); + esp_deep_sleep_start(); +} + +void setup() { + Serial.begin(115200); + pinMode(BUTTON_PIN, INPUT_PULLUP); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); + currentApp = loadApp(); + + if (cause == ESP_SLEEP_WAKEUP_GPIO) { + if (isLongPress(0)) restartAfterRelease(); // der Druck begann ungefähr mit dem Aufwachen + switchToNextApp(); + } + + batteryVoltage = readBatteryVoltage(); + Serial.printf("Start: Weckgrund %d, App %d, Akku %.2f V\n", cause, currentApp, batteryVoltage); + runApp(cause != ESP_SLEEP_WAKEUP_TIMER); + +#ifdef ESTICKY_PREVIEW + // alle Ansichten einmal ausgeben, damit sie ohne Tastendruck geprüft werden können + StatusInfo status = {batteryVoltage, APP_WEATHER, APP_COUNT}; + Weather weather; + Meteogram meteogram; + if (connectWifi()) { + if (fetchWeather(weather)) { + dumpPreview([&](Adafruit_GFX& gfx) { drawWeather(gfx, weather, LOCATION_NAME, status); }, "wetter"); + } + status.appIndex = APP_METEOGRAM; + if (fetchMeteogram(meteogram)) { + dumpPreview([&](Adafruit_GFX& gfx) { drawMeteogram(gfx, meteogram, LOCATION_NAME, status); }, "meteogramm"); + + // erfundener Regen, damit Balken und Wahrscheinlichkeit auch bei trockenem Wetter geprüft werden können: + // kräftiger Schauer am zweiten Tag gegen 16 Uhr, Nieselregen am dritten Vormittag + Meteogram rainy = meteogram; + for (int i = 0; i < METEOGRAM_HOURS; i++) { + float shower = expf(-powf((i - 40) / 3.0f, 2)), drizzle = expf(-powf((i - 58) / 4.0f, 2)); + rainy.precipitation[i] = roundf((3.4f * shower + 0.3f * drizzle) * 10) / 10; + rainy.rainProbability[i] = min(100, (int)(85 * expf(-powf((i - 40) / 8.0f, 2)) + 60 * drizzle + 5)); + } + dumpPreview([&](Adafruit_GFX& gfx) { drawMeteogram(gfx, rainy, LOCATION_NAME, status); }, "meteogramm-regen"); + } + } + WiFi.disconnect(true); + WiFi.mode(WIFI_OFF); + status.appIndex = APP_INFO; + dumpPreview([&](Adafruit_GFX& gfx) { drawInfo(gfx, status); }, "info"); + dumpPreview([&](Adafruit_GFX& gfx) { + drawMessage(gfx, "Wetter", "Keine Verbindung, neuer Versuch in 5 min", status); + }, "meldung"); + Serial.println("Vorschau-Modus: kein Deep Sleep, Taster bleibt aktiv"); + return; +#endif + + bool coldStart = cause != ESP_SLEEP_WAKEUP_TIMER && cause != ESP_SLEEP_WAKEUP_GPIO; + if (coldStart) { + Serial.printf("Upload-Fenster: %lu s wach\n", UPLOAD_WINDOW_MS / 1000); + unsigned long start = millis(); + while (millis() - start < UPLOAD_WINDOW_MS) { + pollButton(); + delay(20); + } + } + goToSleep(sleepInterval()); +} + +void loop() { +#ifdef ESTICKY_PREVIEW + pollButton(); + delay(20); +#endif +} diff --git a/firmware/info_view.cpp b/firmware/info_view.cpp new file mode 100644 index 0000000..4aa8d2a --- /dev/null +++ b/firmware/info_view.cpp @@ -0,0 +1,66 @@ +#include "info_view.h" + +#include +#include +#include +#include +#include // nur für die Farbwerte GxEPD_WHITE … GxEPD_BLACK + +namespace { + +// __DATE__ ("Oct 4 2026") als "04.10.2026" +void buildDate(char* buffer, size_t size) { + static const char MONTHS[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + const char* date = __DATE__; + char month[4] = {date[0], date[1], date[2], '\0'}; + int monthNumber = (strstr(MONTHS, month) - MONTHS) / 3 + 1; + snprintf(buffer, size, "%02d.%02d.%s", atoi(date + 4), monthNumber, date + 7); +} + +} // namespace + +void drawInfo(Adafruit_GFX& gfx, const StatusInfo& status) { + U8G2_FOR_ADAFRUIT_GFX fonts; + fonts.begin(gfx); + char text[40]; + + gfx.fillScreen(GxEPD_WHITE); + + fonts.setForegroundColor(GxEPD_BLACK); + useFont(fonts, u8g2_font_helvB14_tf); + fonts.drawUTF8(6, 24, "esticky"); + + fonts.setForegroundColor(GxEPD_DARKGREY); + useFont(fonts, u8g2_font_helvR08_tf); + char date[12]; + buildDate(date, sizeof(date)); + snprintf(text, sizeof(text), "Firmware vom %s", date); + fonts.drawUTF8(gfx.width() - 6 - fonts.getUTF8Width(text), 24, text); + + fonts.setForegroundColor(GxEPD_BLACK); + useFont(fonts, u8g2_font_helvR10_tf); + fonts.drawUTF8(6, 52, "Taste kurz: nächste App"); + fonts.drawUTF8(6, 72, "Taste lang (2 s): Neustart"); + + if (!isnan(status.batteryVoltage)) { + snprintf(text, sizeof(text), "Akku %.2f V", status.batteryVoltage); + *strchr(text, '.') = ','; + fonts.drawUTF8(6, 98, text); + } + + drawStatusBar(gfx, fonts, "Info", status); +} + +void drawMessage(Adafruit_GFX& gfx, const char* title, const char* text, const StatusInfo& status) { + U8G2_FOR_ADAFRUIT_GFX fonts; + fonts.begin(gfx); + + gfx.fillScreen(GxEPD_WHITE); + fonts.setForegroundColor(GxEPD_BLACK); + useFont(fonts, u8g2_font_helvB14_tf); + fonts.drawUTF8(6, 40, title); + useFont(fonts, u8g2_font_helvR10_tf); + fonts.drawUTF8(6, 70, text); + + drawStatusBar(gfx, fonts, title, status); +} diff --git a/firmware/info_view.h b/firmware/info_view.h new file mode 100644 index 0000000..1d6f3fd --- /dev/null +++ b/firmware/info_view.h @@ -0,0 +1,11 @@ +// Info-App und einfache Meldungen, 296x128 im Querformat. +#pragma once + +#include +#include "ui_common.h" + +// Bedienhinweise, Akkuspannung und Firmware-Stand +void drawInfo(Adafruit_GFX& gfx, const StatusInfo& status); + +// Meldung mit Überschrift und Text, z. B. wenn keine Wetterdaten abgerufen werden konnten +void drawMessage(Adafruit_GFX& gfx, const char* title, const char* text, const StatusInfo& status); diff --git a/firmware/meteogram_data.h b/firmware/meteogram_data.h new file mode 100644 index 0000000..ccd9ca3 --- /dev/null +++ b/firmware/meteogram_data.h @@ -0,0 +1,15 @@ +// Stündliche Vorhersage für das Meteogramm, wie sie von Open-Meteo abgerufen wird. +#pragma once + +#include + +const int METEOGRAM_DAYS = 3; +const int METEOGRAM_HOURS = METEOGRAM_DAYS * 24; // ab heute 0 Uhr + +struct Meteogram { + char start[11]; // Datum der ersten Stunde, "2026-10-04" + char time[17]; // Ortszeit der aktuellen Werte, "2026-10-04T14:15" + float temperature[METEOGRAM_HOURS]; + float precipitation[METEOGRAM_HOURS]; // mm pro Stunde + uint8_t rainProbability[METEOGRAM_HOURS]; // Prozent +}; diff --git a/firmware/meteogram_view.cpp b/firmware/meteogram_view.cpp new file mode 100644 index 0000000..8c863ca --- /dev/null +++ b/firmware/meteogram_view.cpp @@ -0,0 +1,119 @@ +#include "meteogram_view.h" + +#include +#include +#include +#include +#include // nur für die Farbwerte GxEPD_WHITE … GxEPD_BLACK + +namespace { + +// Diagrammfläche: oben Tagesnamen, links °C, rechts mm, unten Stundenmarken und Statuszeile +const int PLOT_LEFT = 24; +const int PLOT_RIGHT = 274; +const int PLOT_TOP = 14; +const int PLOT_BOTTOM = 94; +const int PLOT_HEIGHT = PLOT_BOTTOM - PLOT_TOP; +const float PX_PER_HOUR = float(PLOT_RIGHT - PLOT_LEFT) / METEOGRAM_HOURS; + +int hourX(float hour) { + return PLOT_LEFT + lroundf(hour * PX_PER_HOUR); +} + +void dottedHLine(Adafruit_GFX& g, int x0, int x1, int y, uint16_t color) { + for (int x = x0; x <= x1; x += 3) g.drawPixel(x, y, color); +} + +void dashedVLine(Adafruit_GFX& g, int x, int y0, int y1, uint16_t color) { + for (int y = y0; y <= y1; y += 4) g.drawFastVLine(x, y, 2, color); +} + +} // namespace + +void drawMeteogram(Adafruit_GFX& gfx, const Meteogram& m, const char* location, const StatusInfo& status) { + U8G2_FOR_ADAFRUIT_GFX fonts; + fonts.begin(gfx); + char text[40]; + + gfx.fillScreen(GxEPD_WHITE); + + // Skalen: Temperatur auf volle 5 °C mit mindestens 10 °C Spanne, Regen mindestens 1 mm pro Stunde + float tLow = m.temperature[0], tHigh = m.temperature[0], rainHigh = 0; + for (int i = 0; i < METEOGRAM_HOURS; i++) { + tLow = min(tLow, m.temperature[i]); + tHigh = max(tHigh, m.temperature[i]); + rainHigh = max(rainHigh, m.precipitation[i]); + } + int scaleLow = floorf(tLow / 5) * 5; + int scaleHigh = ceilf(tHigh / 5) * 5; + if (scaleHigh - scaleLow < 10) scaleHigh += 5; + if (scaleHigh - scaleLow < 10) scaleLow -= 5; + int gridStep = scaleHigh - scaleLow > 30 ? 10 : 5; + float rainScale = max(1.0f, ceilf(rainHigh)); + auto tempY = [&](float t) { + return PLOT_BOTTOM - (int)lroundf((t - scaleLow) / (scaleHigh - scaleLow) * PLOT_HEIGHT); + }; + + // Regenwahrscheinlichkeit als hellgraue Fläche (0–100 % der Höhe), Regenmenge als dunkelgraue Balken + for (int i = 0; i < METEOGRAM_HOURS; i++) { + int x0 = hourX(i), x1 = hourX(i + 1); + int probabilityHeight = PLOT_HEIGHT * m.rainProbability[i] / 100; + if (probabilityHeight > 0) { + gfx.fillRect(x0, PLOT_BOTTOM - probabilityHeight, x1 - x0, probabilityHeight, GxEPD_LIGHTGREY); + } + int amountHeight = lroundf(min(m.precipitation[i] / rainScale, 1.0f) * PLOT_HEIGHT); + if (amountHeight > 0) { + gfx.fillRect(x0, PLOT_BOTTOM - amountHeight, max(1, x1 - x0 - 1), amountHeight, GxEPD_DARKGREY); + } + } + + // Temperaturraster mit Beschriftung links, Regenskala rechts oben + fonts.setForegroundColor(GxEPD_DARKGREY); + useFont(fonts, u8g2_font_5x7_tf); + for (int t = scaleLow; t <= scaleHigh; t += gridStep) { + int y = tempY(t); + dottedHLine(gfx, PLOT_LEFT, PLOT_RIGHT, y, GxEPD_DARKGREY); + snprintf(text, sizeof(text), "%d°", t); + fonts.drawUTF8(PLOT_LEFT - 3 - fonts.getUTF8Width(text), y + 3, text); + } + snprintf(text, sizeof(text), "%gmm", rainScale); + fonts.drawUTF8(gfx.width() - 2 - fonts.getUTF8Width(text), PLOT_TOP + 6, text); + + // Tage: Trennlinien um Mitternacht, Tagesnamen oben, Marken für 6, 12 und 18 Uhr unten + int firstWeekday = weekday(m.start); + for (int d = 0; d < METEOGRAM_DAYS; d++) { + int dayStart = hourX(d * 24), dayEnd = hourX((d + 1) * 24); + if (d > 0) gfx.drawFastVLine(dayStart, 2, PLOT_BOTTOM - 2, GxEPD_DARKGREY); + + fonts.setForegroundColor(GxEPD_BLACK); + useFont(fonts, u8g2_font_helvB08_tf); + drawCentered(fonts, d == 0 ? "Heute" : DAY_NAMES[(firstWeekday + d) % 7], (dayStart + dayEnd) / 2, 10); + + fonts.setForegroundColor(GxEPD_DARKGREY); + useFont(fonts, u8g2_font_5x7_tf); + for (int h = 6; h < 24; h += 6) { + int x = hourX(d * 24 + h); + gfx.drawFastVLine(x, PLOT_BOTTOM + 1, 2, GxEPD_DARKGREY); + snprintf(text, sizeof(text), "%d", h); + drawCentered(fonts, text, x, PLOT_BOTTOM + 10); + } + } + gfx.drawFastHLine(PLOT_LEFT, PLOT_BOTTOM, PLOT_RIGHT - PLOT_LEFT, GxEPD_BLACK); + + // Temperaturkurve, 2 px stark, Punkte jeweils in der Stundenmitte + for (int i = 1; i < METEOGRAM_HOURS; i++) { + int xa = hourX(i - 0.5f), xb = hourX(i + 0.5f); + int ya = tempY(m.temperature[i - 1]), yb = tempY(m.temperature[i]); + gfx.drawLine(xa, ya, xb, yb, GxEPD_BLACK); + gfx.drawLine(xa, ya + 1, xb, yb + 1, GxEPD_BLACK); + } + + // jetzt: gestrichelte Linie, wenn die aktuelle Zeit auf den ersten Tag fällt + if (strncmp(m.time, m.start, 10) == 0) { + float nowHour = atoi(m.time + 11) + atoi(m.time + 14) / 60.0f; + dashedVLine(gfx, hourX(nowHour), PLOT_TOP, PLOT_BOTTOM, GxEPD_BLACK); + } + + snprintf(text, sizeof(text), "%s · Stand %s", location, m.time + 11); + drawStatusBar(gfx, fonts, text, status); +} diff --git a/firmware/meteogram_view.h b/firmware/meteogram_view.h new file mode 100644 index 0000000..2ea1c58 --- /dev/null +++ b/firmware/meteogram_view.h @@ -0,0 +1,8 @@ +// Meteogramm über drei Tage: Temperaturkurve, Regenmenge und Regenwahrscheinlichkeit, 296x128 im Querformat. +#pragma once + +#include +#include "meteogram_data.h" +#include "ui_common.h" + +void drawMeteogram(Adafruit_GFX& gfx, const Meteogram& meteogram, const char* location, const StatusInfo& status); diff --git a/firmware/secrets.h.example b/firmware/secrets.h.example new file mode 100644 index 0000000..4577ce3 --- /dev/null +++ b/firmware/secrets.h.example @@ -0,0 +1,13 @@ +// Vorlage für secrets.h: als secrets.h kopieren und die eigenen WLAN-Zugangsdaten eintragen. +// secrets.h ist git-ignoriert und wird nicht eingecheckt. +#pragma once + +struct WifiCredentials { + const char* ssid; + const char* password; +}; + +// Der ESP32-C3 kann nur 2,4 GHz, reine 5-GHz-Netze werden einfach nicht gefunden. +const WifiCredentials WIFI_NETWORKS[] = { + {"", ""}, +}; diff --git a/firmware/ui_common.cpp b/firmware/ui_common.cpp new file mode 100644 index 0000000..fa2f417 --- /dev/null +++ b/firmware/ui_common.cpp @@ -0,0 +1,78 @@ +#include "ui_common.h" + +#include +#include +#include +#include // nur für die Farbwerte GxEPD_WHITE … GxEPD_BLACK + +const char* const DAY_NAMES[7] = {"So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"}; + +// nach Sakamoto +int weekday(const char* date) { + static const int offsets[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; + int y = atoi(date), m = atoi(date + 5), d = atoi(date + 8); + if (m < 3) y -= 1; + return (y + y / 4 - y / 100 + y / 400 + offsets[m - 1] + d) % 7; +} + +void useFont(U8G2_FOR_ADAFRUIT_GFX& fonts, const uint8_t* font) { + fonts.setFont(font); + fonts.setFontMode(1); +} + +void drawCentered(U8G2_FOR_ADAFRUIT_GFX& fonts, const char* text, int centerX, int baseline) { + fonts.drawUTF8(centerX - fonts.getUTF8Width(text) / 2, baseline, text); +} + +// Ladezustand einer LiPo-Zelle aus der Spannung, grob nach typischer Entladekurve +int batteryPercent(float voltage) { + static const float VOLTS[] = {3.30f, 3.60f, 3.70f, 3.75f, 3.80f, 3.85f, 3.90f, 4.00f, 4.10f, 4.20f}; + static const int PERCENT[] = {0, 5, 15, 25, 40, 55, 65, 80, 90, 100}; + const int count = sizeof(VOLTS) / sizeof(VOLTS[0]); + if (voltage <= VOLTS[0]) return 0; + for (int i = 1; i < count; i++) { + if (voltage < VOLTS[i]) { + float t = (voltage - VOLTS[i - 1]) / (VOLTS[i] - VOLTS[i - 1]); + return lroundf(PERCENT[i - 1] + t * (PERCENT[i] - PERCENT[i - 1])); + } + } + return 100; +} + +namespace { + +void batteryIcon(Adafruit_GFX& g, int x, int y, int percent) { + const int w = 16, h = 8; + g.drawRect(x, y, w, h, GxEPD_BLACK); + g.fillRect(x + w, y + 2, 2, h - 4, GxEPD_BLACK); + g.fillRect(x + 2, y + 2, (w - 4) * percent / 100, h - 4, percent <= 15 ? GxEPD_BLACK : GxEPD_DARKGREY); +} + +void appDots(Adafruit_GFX& g, int centerX, int centerY, int index, int count) { + const int spacing = 9; + int x = centerX - (count - 1) * spacing / 2; + for (int i = 0; i < count; i++, x += spacing) { + if (i == index) g.fillCircle(x, centerY, 3, GxEPD_BLACK); + else g.drawCircle(x, centerY, 3, GxEPD_DARKGREY); + } +} + +} // namespace + +void drawStatusBar(Adafruit_GFX& gfx, U8G2_FOR_ADAFRUIT_GFX& fonts, const char* leftText, const StatusInfo& status) { + gfx.drawFastHLine(0, STATUS_LINE_Y, gfx.width(), GxEPD_LIGHTGREY); + fonts.setForegroundColor(GxEPD_DARKGREY); + useFont(fonts, u8g2_font_helvR08_tf); + fonts.drawUTF8(6, 124, leftText); + + if (status.appCount > 1) appDots(gfx, gfx.width() / 2, 120, status.appIndex, status.appCount); + + if (!isnan(status.batteryVoltage)) { + char text[8]; + int percent = batteryPercent(status.batteryVoltage); + snprintf(text, sizeof(text), "%d %%", percent); + int textX = gfx.width() - 6 - fonts.getUTF8Width(text); + fonts.drawUTF8(textX, 124, text); + batteryIcon(gfx, textX - 24, 116, percent); + } +} diff --git a/firmware/ui_common.h b/firmware/ui_common.h new file mode 100644 index 0000000..1c75d2a --- /dev/null +++ b/firmware/ui_common.h @@ -0,0 +1,26 @@ +// Gemeinsame Bausteine aller Apps: Schriften, Statuszeile mit App-Punkten und Akkuanzeige. +#pragma once + +#include +#include + +const int STATUS_LINE_Y = 111; // Trennlinie über der Statuszeile (Querformat 296x128) + +struct StatusInfo { + float batteryVoltage; // Volt, NAN ohne Messwert (dann ohne Akkuanzeige) + int appIndex; + int appCount; +}; + +extern const char* const DAY_NAMES[7]; // "So", "Mo", … "Sa" + +// Wochentag, 0 = Sonntag; date im Format "YYYY-MM-DD" +int weekday(const char* date); + +// setFont schaltet den transparenten Modus ab (der Hintergrund wäre dann schwarz), daher immer hierüber +void useFont(U8G2_FOR_ADAFRUIT_GFX& fonts, const uint8_t* font); +void drawCentered(U8G2_FOR_ADAFRUIT_GFX& fonts, const char* text, int centerX, int baseline); +int batteryPercent(float voltage); + +// Statuszeile: links Text, in der Mitte ein Punkt pro App (aktuelle gefüllt), rechts der Akku +void drawStatusBar(Adafruit_GFX& gfx, U8G2_FOR_ADAFRUIT_GFX& fonts, const char* leftText, const StatusInfo& status); diff --git a/firmware/weather_data.h b/firmware/weather_data.h new file mode 100644 index 0000000..a5a7e78 --- /dev/null +++ b/firmware/weather_data.h @@ -0,0 +1,22 @@ +// Wetterdaten, wie sie von Open-Meteo abgerufen und auf dem Display angezeigt werden. +#pragma once + +const int FORECAST_DAYS = 3; + +struct DayForecast { + char date[11]; // "2026-10-03" + int weatherCode; // WMO-Code + float tempMin; + float tempMax; + int rainProbability; // Prozent +}; + +struct Weather { + char time[17]; // Ortszeit der Messung, "2026-10-03T17:00" + float temperature; + int humidity; + float windSpeed; // km/h + int weatherCode; // WMO-Code + bool isDay; + DayForecast days[FORECAST_DAYS]; +}; diff --git a/firmware/weather_view.cpp b/firmware/weather_view.cpp new file mode 100644 index 0000000..ba5fb9d --- /dev/null +++ b/firmware/weather_view.cpp @@ -0,0 +1,236 @@ +#include "weather_view.h" + +#include +#include +#include +#include // nur für die Farbwerte GxEPD_WHITE … GxEPD_BLACK + +namespace { + +// Layout (Querformat 296x128): links aktuelles Wetter, rechts drei Tage, unten Statuszeile +const int LEFT_PANEL_WIDTH = 150; +const int DAY_COLUMN_WIDTH = 48; + +enum class Sky { Clear, PartlyCloudy, Overcast, Fog, Drizzle, Rain, Snow, Thunder }; + +Sky skyFor(int code) { + if (code == 0) return Sky::Clear; + if (code <= 2) return Sky::PartlyCloudy; + if (code == 3) return Sky::Overcast; + if (code == 45 || code == 48) return Sky::Fog; + if (code >= 51 && code <= 57) return Sky::Drizzle; + if ((code >= 61 && code <= 67) || (code >= 80 && code <= 82)) return Sky::Rain; + if ((code >= 71 && code <= 77) || code == 85 || code == 86) return Sky::Snow; + if (code >= 95) return Sky::Thunder; + return Sky::Overcast; +} + +const char* conditionText(int code, bool isDay) { + switch (code) { + case 0: return isDay ? "Sonnig" : "Klar"; + case 1: return "Überwiegend klar"; + case 2: return "Teils bewölkt"; + case 3: return "Bedeckt"; + case 45: case 48: return "Nebel"; + case 51: case 53: case 55: return "Nieselregen"; + case 56: case 57: return "Eisiger Niesel"; + case 61: return "Leichter Regen"; + case 63: return "Regen"; + case 65: return "Starker Regen"; + case 66: case 67: return "Eisregen"; + case 71: return "Leichter Schnee"; + case 73: return "Schnee"; + case 75: return "Starker Schnee"; + case 77: return "Schneegriesel"; + case 80: case 81: return "Regenschauer"; + case 82: return "Starke Schauer"; + case 85: case 86: return "Schneeschauer"; + case 95: return "Gewitter"; + case 96: case 99: return "Gewitter, Hagel"; + default: return "Unbekannt"; + } +} + +void formatTemperature(char* buffer, size_t size, float temperature) { + snprintf(buffer, size, "%ld°", lroundf(temperature)); +} + +// --- Wettersymbole; (cx, cy) ist die Mitte, size die Kantenlänge des Symbolfelds --- + +void cloudShape(Adafruit_GFX& g, int cx, int cy, int w, int inset, uint16_t color) { + int h = w * 0.32f; + g.fillRoundRect(cx - w / 2 + inset, cy + inset, w - 2 * inset, h - 2 * inset, h / 2 - inset, color); + g.fillCircle(cx - w * 0.20f, cy + w * 0.05f, w * 0.20f - inset, color); + g.fillCircle(cx + w * 0.12f, cy - w * 0.02f, w * 0.28f - inset, color); +} + +// Wolke mit schwarzem Umriss; die Wolke ist etwa 0,62·w hoch, (cx, cy) liegt in ihrer Mitte +void cloud(Adafruit_GFX& g, int cx, int cy, int w, uint16_t fill) { + int outline = w >= 40 ? 3 : 2; + cloudShape(g, cx, cy, w, 0, GxEPD_BLACK); + cloudShape(g, cx, cy, w, outline, fill); +} + +void sun(Adafruit_GFX& g, int cx, int cy, int r) { + int rayStart = r + 3; + int rayEnd = r + 3 + max(3, r / 2); + for (int i = 0; i < 8; i++) { + float a = i * PI / 4; + int x1 = cx + cosf(a) * rayStart, y1 = cy + sinf(a) * rayStart; + int x2 = cx + cosf(a) * rayEnd, y2 = cy + sinf(a) * rayEnd; + g.drawLine(x1, y1, x2, y2, GxEPD_BLACK); + g.drawLine(x1 + 1, y1, x2 + 1, y2, GxEPD_BLACK); + g.drawLine(x1, y1 + 1, x2, y2 + 1, GxEPD_BLACK); + } + g.fillCircle(cx, cy, r, GxEPD_BLACK); + g.fillCircle(cx, cy, r - 2, GxEPD_LIGHTGREY); +} + +void moon(Adafruit_GFX& g, int cx, int cy, int r) { + g.fillCircle(cx, cy, r, GxEPD_BLACK); + g.fillCircle(cx, cy, r - 2, GxEPD_LIGHTGREY); + g.fillCircle(cx + r * 0.55f, cy - r * 0.35f, r * 0.8f, GxEPD_WHITE); +} + +void rainDrops(Adafruit_GFX& g, int cx, int top, int size, int count) { + int length = size * 0.18f; + for (int i = 0; i < count; i++) { + int x = cx + (i - (count - 1) / 2.0f) * size * 0.22f; + for (int t = 0; t < 2; t++) { + g.drawLine(x + t, top, x + t - length / 3, top + length, GxEPD_BLACK); + } + } +} + +void snowFlakes(Adafruit_GFX& g, int cx, int top, int size) { + int arm = max(2, (int)(size * 0.06f)); + for (int i = 0; i < 3; i++) { + int x = cx + (i - 1) * size * 0.24f; + int y = top + arm + (i % 2) * arm; + g.drawLine(x, y - arm, x, y + arm, GxEPD_BLACK); + g.drawLine(x - arm, y - arm / 2, x + arm, y + arm / 2, GxEPD_BLACK); + g.drawLine(x - arm, y + arm / 2, x + arm, y - arm / 2, GxEPD_BLACK); + } +} + +void lightningBolt(Adafruit_GFX& g, int cx, int top, int size) { + int s = size; + g.fillTriangle(cx + s * 0.06f, top, cx - s * 0.08f, top + s * 0.16f, cx + s * 0.03f, top + s * 0.16f, GxEPD_BLACK); + g.fillTriangle(cx - s * 0.03f, top + s * 0.12f, cx + s * 0.08f, top + s * 0.12f, cx - s * 0.06f, top + s * 0.32f, + GxEPD_BLACK); +} + +void fogBars(Adafruit_GFX& g, int cx, int cy, int size) { + int thickness = max(2, (int)(size * 0.07f)); + for (int i = 0; i < 4; i++) { + int w = size * (i % 2 ? 0.62f : 0.80f); + int y = cy - size * 0.27f + i * size * 0.18f; + int x = cx - w / 2 + (i % 2 ? size * 0.06f : 0); + g.fillRoundRect(x, y, w, thickness, thickness / 2, GxEPD_DARKGREY); + } +} + +void weatherIcon(Adafruit_GFX& g, int code, bool isDay, int cx, int cy, int size) { + int cloudWidth = size * 0.8f; + int precipCloudY = cy - size * 0.14f; // Wolke etwas höher, darunter Niederschlag + int precipTop = cy + size * 0.22f; + + switch (skyFor(code)) { + case Sky::Clear: + if (isDay) sun(g, cx, cy, size * 0.24f); + else moon(g, cx, cy, size * 0.30f); + break; + case Sky::PartlyCloudy: + if (isDay) sun(g, cx - size * 0.16f, cy - size * 0.14f, size * 0.17f); + else moon(g, cx - size * 0.14f, cy - size * 0.14f, size * 0.22f); + cloud(g, cx + size * 0.08f, cy + size * 0.12f, size * 0.72f, GxEPD_WHITE); + break; + case Sky::Overcast: + cloud(g, cx + size * 0.12f, cy - size * 0.10f, size * 0.62f, GxEPD_DARKGREY); + cloud(g, cx - size * 0.06f, cy + size * 0.08f, cloudWidth, GxEPD_LIGHTGREY); + break; + case Sky::Fog: + fogBars(g, cx, cy, size); + break; + case Sky::Drizzle: + cloud(g, cx, precipCloudY, cloudWidth, GxEPD_LIGHTGREY); + rainDrops(g, cx, precipTop, size, 2); + break; + case Sky::Rain: + cloud(g, cx, precipCloudY, cloudWidth, GxEPD_DARKGREY); + rainDrops(g, cx, precipTop, size, 3); + break; + case Sky::Snow: + cloud(g, cx, precipCloudY, cloudWidth, GxEPD_LIGHTGREY); + snowFlakes(g, cx, precipTop, size); + break; + case Sky::Thunder: + cloud(g, cx, precipCloudY, cloudWidth, GxEPD_DARKGREY); + lightningBolt(g, cx, precipTop - size * 0.04f, size); + break; + } +} + +void raindrop(Adafruit_GFX& g, int cx, int bottom, uint16_t color) { + g.fillCircle(cx, bottom - 2, 2, color); + g.fillTriangle(cx - 2, bottom - 2, cx + 2, bottom - 2, cx, bottom - 7, color); +} + +} // namespace + +void drawWeather(Adafruit_GFX& gfx, const Weather& weather, const char* location, const StatusInfo& status) { + U8G2_FOR_ADAFRUIT_GFX fonts; + fonts.begin(gfx); + char text[40]; + + gfx.fillScreen(GxEPD_WHITE); + + // links: aktuelles Wetter + weatherIcon(gfx, weather.weatherCode, weather.isDay, 36, 38, 64); + + fonts.setForegroundColor(GxEPD_BLACK); + useFont(fonts, u8g2_font_logisoso38_tf); + formatTemperature(text, sizeof(text), weather.temperature); + fonts.drawUTF8(76, 58, text); + + useFont(fonts, u8g2_font_helvB12_tf); + fonts.drawUTF8(6, 88, conditionText(weather.weatherCode, weather.isDay)); + + useFont(fonts, u8g2_font_helvR08_tf); + fonts.setForegroundColor(GxEPD_DARKGREY); + snprintf(text, sizeof(text), "Wind %ld km/h · Feuchte %d %%", lroundf(weather.windSpeed), weather.humidity); + fonts.drawUTF8(6, 104, text); + + gfx.drawFastVLine(LEFT_PANEL_WIDTH, 6, STATUS_LINE_Y - 12, GxEPD_DARKGREY); + + // rechts: drei Tage + for (int i = 0; i < FORECAST_DAYS; i++) { + const DayForecast& day = weather.days[i]; + int centerX = LEFT_PANEL_WIDTH + 2 + i * DAY_COLUMN_WIDTH + DAY_COLUMN_WIDTH / 2; + + fonts.setForegroundColor(GxEPD_BLACK); + useFont(fonts, u8g2_font_helvB10_tf); + drawCentered(fonts, i == 0 ? "Heute" : DAY_NAMES[weekday(day.date)], centerX, 15); + + weatherIcon(gfx, day.weatherCode, true, centerX, 38, 34); + + useFont(fonts, u8g2_font_helvB12_tf); + formatTemperature(text, sizeof(text), day.tempMax); + drawCentered(fonts, text, centerX, 74); + + fonts.setForegroundColor(GxEPD_DARKGREY); + useFont(fonts, u8g2_font_helvR10_tf); + formatTemperature(text, sizeof(text), day.tempMin); + drawCentered(fonts, text, centerX, 90); + + useFont(fonts, u8g2_font_helvR08_tf); + snprintf(text, sizeof(text), "%d %%", day.rainProbability); + int textWidth = fonts.getUTF8Width(text); + int startX = centerX - (textWidth + 7) / 2; + raindrop(gfx, startX + 2, 104, GxEPD_DARKGREY); + fonts.drawUTF8(startX + 7, 104, text); + } + + snprintf(text, sizeof(text), "%s · Stand %s", location, weather.time + 11); + drawStatusBar(gfx, fonts, text, status); +} diff --git a/firmware/weather_view.h b/firmware/weather_view.h new file mode 100644 index 0000000..05b75c6 --- /dev/null +++ b/firmware/weather_view.h @@ -0,0 +1,9 @@ +// Layout der Wetteranzeige für 296x128 im Querformat mit 4 Graustufen. +#pragma once + +#include +#include "ui_common.h" +#include "weather_data.h" + +// Zeichnet die komplette Anzeige. Funktioniert mit dem Display und mit einem GFXcanvas16 (Vorschau). +void drawWeather(Adafruit_GFX& gfx, const Weather& weather, const char* location, const StatusInfo& status); diff --git a/grey_demo/grey_demo.ino b/grey_demo/grey_demo.ino new file mode 100644 index 0000000..5552663 --- /dev/null +++ b/grey_demo/grey_demo.ino @@ -0,0 +1,75 @@ +// Graustufen-Demo: 4 Stufen (weiß, hellgrau, dunkelgrau, schwarz) mit GxEPD2_4G. +// Hardware: XIAO ESP32-C3 + Waveshare 2.9" e-Paper Module Rev2.1 (Panel GDEM029T94, SSD1680). +// Verkabelung: VCC+PWR→3V3, GND→GND, DIN→D10, CLK→D8, CS→D1, DC→D2, RST→D5, BUSY→D4. +// Graustufen gehen auf diesem Panel nur per Voll-Refresh. GxEPD2_4G nicht zusammen mit +// GxEPD2 im selben Sketch einbinden, beide definieren gleichnamige Treiberklassen. + +#include +#include +#include +#include + +GxEPD2_4G_4G display( + GxEPD2_290_T94(/*CS=*/D1, /*DC=*/D2, /*RST=*/D5, /*BUSY=*/D4)); + +struct Shade { + uint16_t color; + uint16_t textColor; + const char* name; +}; + +const Shade SHADES[] = { + {GxEPD_WHITE, GxEPD_BLACK, "weiss"}, + {GxEPD_LIGHTGREY, GxEPD_BLACK, "hell"}, + {GxEPD_DARKGREY, GxEPD_WHITE, "dunkel"}, + {GxEPD_BLACK, GxEPD_WHITE, "schwarz"}, +}; + +void printCentered(const char* text, int16_t centerX, int16_t baselineY) { + int16_t x, y; + uint16_t w, h; + display.getTextBounds(text, 0, 0, &x, &y, &w, &h); + display.setCursor(centerX - w / 2 - x, baselineY); + display.print(text); +} + +void setup() { + SPI.begin(SCK, -1, MOSI, -1); // ohne MISO, damit GPIO9 für die BOOT-Taste frei bleibt + display.init(115200, true, 2, false); + display.setRotation(1); // Querformat 296x128 + + const int16_t boxW = display.width() / 4; + const int16_t boxH = 64; + + display.setFullWindow(); + display.firstPage(); + do { + display.fillScreen(GxEPD_WHITE); + + // obere Hälfte: vier Farbfelder + display.setFont(&FreeSans9pt7b); + for (int i = 0; i < 4; i++) { + display.fillRect(i * boxW, 0, boxW, boxH, SHADES[i].color); + display.setTextColor(SHADES[i].textColor); + printCentered(SHADES[i].name, i * boxW + boxW / 2, boxH / 2 + 6); + } + display.drawRect(0, 0, display.width(), boxH, GxEPD_BLACK); // Rahmen, damit das weiße Feld sichtbar ist + + // untere Hälfte: Text in den drei dunklen Stufen + display.setFont(&FreeSansBold9pt7b); + display.setTextColor(GxEPD_BLACK); + display.setCursor(8, 84); + display.print("Schwarzer Text"); + display.setTextColor(GxEPD_DARKGREY); + display.setCursor(8, 104); + display.print("Dunkelgrauer Text"); + display.setTextColor(GxEPD_LIGHTGREY); + display.setCursor(8, 124); + display.print("Hellgrauer Text"); + } while (display.nextPage()); + + display.hibernate(); + Serial.println("Graustufen-Demo angezeigt, Display im Ruhezustand."); +} + +void loop() {} diff --git a/notes_test/notes_test.ino b/notes_test/notes_test.ino new file mode 100644 index 0000000..ab7f430 --- /dev/null +++ b/notes_test/notes_test.ino @@ -0,0 +1,101 @@ +// Blätter-Test: Notizen mit der BOOT-Taste durchschalten, Display per Teil-Refresh (ohne Flackern). +// Teil-Refresh hinterlässt Reste und blassere Schrift, daher folgt nach kurzer Pause ein Voll-Refresh. +// Hardware wie display_test: XIAO ESP32-C3 + Waveshare 2.9" e-Paper Module Rev2.1. +// Verkabelung: VCC+PWR→3V3, GND→GND, DIN→D10, CLK→D8, CS→D1, DC→D2, RST→D5, BUSY→D4. + +#include +#include +#include +#include + +GxEPD2_BW display( + GxEPD2_290_T94_V2(/*CS=*/D1, /*DC=*/D2, /*RST=*/D5, /*BUSY=*/D4)); + +const int BOOT_BUTTON_PIN = 9; // BOOT-Taste auf der Platine, gedrückt = LOW +const unsigned long CLEANUP_DELAY_MS = 3000; // Pause nach dem letzten Umblättern bis zum Voll-Refresh + +struct Note { + const char* title; + const char* lines[3]; +}; + +const Note NOTES[] = { + {"Einkaufen", {"Milch, Brot, Kaffee", "Tomaten, Basilikum", "Batterien AAA"}}, + {"Termine", {"Di 10:30 Zahnarzt", "Do 18:00 Sport", "Sa Geburtstag Anna"}}, + {"Idee", {"Notizen per WLAN", "aufs Display schicken", ""}}, + {"Bedienung", {"BOOT-Taste: weiter", "Teil-Refresh ohne", "Flackern"}}, +}; +const int NOTE_COUNT = sizeof(NOTES) / sizeof(NOTES[0]); + +int currentNote = 0; + +void drawNote(int index) { + const Note& note = NOTES[index]; + display.firstPage(); + do { + display.fillScreen(GxEPD_WHITE); + display.setFont(&FreeSansBold12pt7b); + display.setCursor(10, 26); + display.print(note.title); + + char page[8]; + snprintf(page, sizeof(page), "%d/%d", index + 1, NOTE_COUNT); + display.setFont(&FreeSans9pt7b); + int16_t x, y; + uint16_t w, h; + display.getTextBounds(page, 0, 0, &x, &y, &w, &h); + display.setCursor(display.width() - w - 10, 24); + display.print(page); + + display.drawFastHLine(10, 34, display.width() - 20, GxEPD_BLACK); + for (int i = 0; i < 3; i++) { + display.setCursor(10, 60 + i * 24); + display.print(note.lines[i]); + } + } while (display.nextPage()); +} + +void showNote(bool fullRefresh) { + if (fullRefresh) { + display.setFullWindow(); + } else { + display.setPartialWindow(0, 0, display.width(), display.height()); + } + unsigned long start = millis(); + drawNote(currentNote); + display.powerOff(); + Serial.printf("Notiz %d/%d (%s, %lu ms)\n", currentNote + 1, NOTE_COUNT, + fullRefresh ? "Voll-Refresh" : "Teil-Refresh", millis() - start); +} + +void setup() { + SPI.begin(SCK, -1, MOSI, -1); // ohne MISO, damit GPIO9 für die BOOT-Taste frei bleibt + display.init(115200, true, 2, false); + display.setRotation(1); // Querformat 296x128 + display.setTextColor(GxEPD_BLACK); + pinMode(BOOT_BUTTON_PIN, INPUT_PULLUP); + + showNote(true); +} + +void loop() { + static bool wasPressed = false; + static bool needsCleanup = false; + static unsigned long lastFlip = 0; + bool pressed = digitalRead(BOOT_BUTTON_PIN) == LOW; + + if (pressed && !wasPressed) { + currentNote = (currentNote + 1) % NOTE_COUNT; + showNote(false); + needsCleanup = true; + lastFlip = millis(); + } + + if (needsCleanup && millis() - lastFlip > CLEANUP_DELAY_MS) { + showNote(true); + needsCleanup = false; + } + + wasPressed = pressed; + delay(20); // einfache Entprellung +} diff --git a/tools/capture_preview.py b/tools/capture_preview.py new file mode 100644 index 0000000..71609df --- /dev/null +++ b/tools/capture_preview.py @@ -0,0 +1,65 @@ +"""Liest die Serial-Ausgabe der esticky-Firmware im Vorschau-Modus (-DESTICKY_PREVIEW) +und speichert jeden PREVIEW-Block als PNG (Graustufen, 3-fach vergrößert). + +Aufruf: uv run --with pyserial --with pillow python tools/capture_preview.py SEKUNDEN AUSGABEORDNER [PORT] + +Das Öffnen des Ports startet den XIAO neu. Gelesen wird, bis "Vorschau-Modus" erscheint +oder die Zeit abgelaufen ist; alle anderen Zeilen werden ausgegeben. +""" +import re +import sys +import time +from pathlib import Path + +import serial +from PIL import Image + +PALETTE = {"0": 255, "1": 192, "2": 128, "3": 0} +BOOT_NOISE = re.compile(r"^(ESP-ROM|Build:|Saved|SPIWP|mode:|load:|entry )") + + +def save_png(rows, path, scale=3, pad=4): + width, height = len(rows[0]), len(rows) + image = Image.new("L", (width, height)) + image.putdata([PALETTE.get(c, 64) for row in rows for c in row]) + image = image.resize((width * scale, height * scale), Image.NEAREST) + framed = Image.new("L", (image.width + 2 * pad, image.height + 2 * pad), 90) + framed.paste(image, (pad, pad)) + framed.save(path) + + +def main(): + timeout, outdir = float(sys.argv[1]), Path(sys.argv[2]) + port = sys.argv[3] if len(sys.argv) > 3 else "/dev/cu.usbmodem21201" + outdir.mkdir(parents=True, exist_ok=True) + + connection = serial.Serial() + connection.port, connection.baudrate, connection.timeout = port, 115200, 0.5 + connection.dtr = connection.rts = False + connection.open() + + data, deadline = b"", time.time() + timeout + while time.time() < deadline and b"Vorschau-Modus" not in data: + try: + data += connection.read(65536) + except serial.SerialException as error: + print("Serial beendet:", error) + break + + rows, label = None, None + for line in data.decode("utf-8", "replace").splitlines(): + line = line.rstrip("\r") + if line.startswith("PREVIEW-BEGIN"): + rows, label = [], line.split(" ", 1)[1] + elif line == "PREVIEW-END" and rows: + save_png(rows, outdir / f"{label}.png") + print(f"gespeichert: {outdir / label}.png") + rows = None + elif rows is not None: + rows.append(line) + elif line and not BOOT_NOISE.match(line): + print(line) + + +if __name__ == "__main__": + main() diff --git a/wifi_scan/wifi_scan.ino b/wifi_scan/wifi_scan.ino new file mode 100644 index 0000000..807afd2 --- /dev/null +++ b/wifi_scan/wifi_scan.ino @@ -0,0 +1,21 @@ +// WLAN-Test: sucht alle 10 s nach Netzwerken und gibt sie über USB-Serial aus. +// Der XIAO ESP32-C3 braucht dafür die mitgelieferte Antenne am U.FL-Stecker. + +#include + +void setup() { + Serial.begin(115200); + WiFi.mode(WIFI_STA); + WiFi.disconnect(); +} + +void loop() { + int count = WiFi.scanNetworks(); + Serial.printf("%d Netzwerke gefunden:\n", count); + for (int i = 0; i < count; i++) { + Serial.printf(" %-32s %4d dBm Kanal %2d %s\n", WiFi.SSID(i).c_str(), WiFi.RSSI(i), WiFi.channel(i), + WiFi.encryptionType(i) == WIFI_AUTH_OPEN ? "offen" : "verschluesselt"); + } + WiFi.scanDelete(); + delay(10000); +}