66Adafruit_SSD1306 oled (SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
77bool oledInitialized = false ;
88
9+
10+
911// Helper: Convert UTF-8 string to CP437 for Adafruit GFX display
1012// CP437 contains German umlauts: ä=0x84, Ä=0x8E, ö=0x94, Ö=0x99, ü=0x81, Ü=0x9A, ß=0xE1
13+ // Supports /xHH escape sequences (e.g. /x84 → CP437 byte 0x84 = ä)
1114String utf8ToCP437 (const String& utf8) {
1215 String result = " " ;
1316 for (int i = 0 ; i < utf8.length (); i++) {
1417 uint8_t c = utf8[i];
15-
18+
1619 // Check for UTF-8 multi-byte sequences
1720 if ((c & 0x80 ) == 0 ) {
1821 // ASCII character (0x00-0x7F) - pass through
@@ -82,7 +85,7 @@ void displayText(const String& text, uint8_t textSize) {
8285 oled.display ();
8386}
8487
85- void displayNumber (float value, uint8_t textSize, const String& unit ) {
88+ void displayNumber (float value, uint8_t textSize) {
8689 initDisplay ();
8790 oled.setTextSize (textSize);
8891 oled.setTextColor (SSD1306_WHITE, SSD1306_BLACK);
@@ -91,12 +94,11 @@ void displayNumber(float value, uint8_t textSize, const String& unit) {
9194 // Smart formatting: show no decimals for whole numbers
9295 String out;
9396 if (value == (int )value) {
94- out = String ((int )value);
97+ oled. println ((int )value);
9598 } else {
96- out = String (value);
99+ oled. println (value);
97100 }
98- if (unit.length () > 0 ) out += unit;
99- oled.println (out);
101+
100102
101103 oled.display ();
102104
@@ -117,17 +119,7 @@ void handleClearDisplay(String args) {
117119
118120
119121
120- // Returns the display unit for a known sensor measurement type
121- static String getSensorUnit (const String& expr) {
122- // expr format: sensor:type:measurement
123- int lastColon = expr.lastIndexOf (' :' );
124- if (lastColon == -1 ) return " " ;
125- String measurement = expr.substring (lastColon + 1 );
126- measurement.toLowerCase ();
127- if (measurement == " temperature" ) return String ((char )0xF8 ) + " C" ; // °C in CP437
128- if (measurement == " humidity" ) return " %" ;
129- return " " ;
130- }
122+
131123
132124void handleDisplay (String args) {
133125 args.trim ();
@@ -165,10 +157,8 @@ void handleDisplay(String args) {
165157 return ;
166158 }
167159 // Ansonsten: Zahl evaluieren
168- String unit = " " ;
169- if (args.startsWith (" sensor:" )) unit = getSensorUnit (args);
170160 float num = evalNumber (args);
171- displayNumber (num, textSize, unit);
161+ displayNumber (( float ) num, textSize);
172162}
173163
174164// Global device ID variable
0 commit comments