@@ -98,6 +98,12 @@ uint8_t rotation = 1;
9898#endif
9999#endif
100100
101+ #ifndef LDR_IN
102+ #define LDR_IN -1
103+ #endif
104+
105+ int8_t ldr_pin = LDR_IN;
106+
101107#ifdef AUTOCONFIG
102108#endif
103109
@@ -142,6 +148,11 @@ void updateStarted() {
142148WiFiManager wifiManager;
143149WiFiManagerParameter stationNameParameter (" stationName" , " Stationsname" , fromStationName, sizeof (fromStationName));
144150WiFiManagerParameter rotationParameter (" rotation" , " Rotation (1 oder 3)" , String(rotation).c_str(), 1);
151+ #ifdef ESP8266
152+ WiFiManagerParameter ldrParameter (" ldrpin" , " Lichtsensor (-1 zum Deaktivieren, 17 sonst)" , String(ldr_pin).c_str(), 2);
153+ #else
154+ WiFiManagerParameter ldrParameter (" ldrpin" , " Lichtsensor (-1 zum Deaktivieren, CYD z.B. 34 zum Aktivieren)" , String(ldr_pin).c_str(), 2);
155+ #endif
145156WiFiManagerParameter filterICEParameter (" filterICE" , " Hochgeschwindigkeitszüge (1 zum Aktivieren)" , String((filter & PROD_ICE) > 0).c_str(), 1);
146157WiFiManagerParameter filterICECParameter (" filterICEC" , " Intercity- und Eurocityzüge 1 zum Aktivieren)" , String((filter & PROD_IC_EC) > 0).c_str(), 1);
147158WiFiManagerParameter filterIRParameter (" filterIR" , " Interregio- und Schnellzüge (1 zum Aktivieren)" , String((filter & PROD_IR) > 0).c_str(), 1);
@@ -215,6 +226,16 @@ void readParams() {
215226 } else {
216227 Serial.println (" File not found" );
217228 }
229+ if (LittleFS.exists (" /ldr" )) {
230+ File f = LittleFS.open (" /ldr" , " r" );
231+ if (f) {
232+ ldr_pin = f.readString ().toInt ();
233+ } else {
234+ Serial.println (" File not open" );
235+ }
236+ } else {
237+ Serial.println (" File not found" );
238+ }
218239 if (LittleFS.exists (" /filter" )) {
219240 File f = LittleFS.open (" /filter" , " r" );
220241 if (f) {
@@ -269,6 +290,12 @@ void afterConfigCallback() {
269290 Serial.print (" Rotation gesetzt: " );
270291 Serial.println (rotation);
271292 }
293+ ldr_pin = atoi (ldrParameter.getValue ());
294+ {
295+ File f = LittleFS.open (" /ldr" , " w" );
296+ f.print (ldrParameter.getValue ());
297+ f.close ();
298+ }
272299 uint16_t val =
273300 (filterICEParameter.getValue ()[0 ] == ' 1' ) * PROD_ICE |
274301 (filterICECParameter.getValue ()[0 ] == ' 1' ) * PROD_IC_EC |
@@ -338,6 +365,8 @@ void setup() {
338365 wifiManager.addParameter (&stationNameParameter);
339366 rotationParameter.setValue (String (rotation).c_str (), 1 );
340367 wifiManager.addParameter (&rotationParameter);
368+ ldrParameter.setValue (String (ldr_pin).c_str (), 2 );
369+ wifiManager.addParameter (&ldrParameter);
341370 filterICEParameter.setValue (String ((filter & PROD_ICE) > 0 ).c_str (), 1 );
342371 wifiManager.addParameter (&filterICEParameter);
343372 filterICECParameter.setValue (String ((filter & PROD_IC_EC) > 0 ).c_str (), 1 );
@@ -529,30 +558,30 @@ void loop() {
529558#ifdef AUTOCONFIG
530559 checkConfigRequest ();
531560#endif
532- # ifdef LDR_IN
533- if (nextBrightness < millis ()) {
534- uint16_t b = analogRead (LDR_IN );
561+ if (ldr_pin > 0 ) { // 0 is never an analog in
562+ if (nextBrightness < millis ()) {
563+ uint16_t b = analogRead (ldr_pin );
535564#ifdef ESP32
536- b >>= 2 ;
565+ b >>= 2 ;
537566#endif
538- if (b < currentBrightness) {
539- currentBrightness--;
540- } else if (b > currentBrightness) {
541- currentBrightness++;
542- }
543- uint16_t brightness = map (currentBrightness, 1023 , 0 , MIN_BRIGHTNESS, MAX_BRIGHTNESS);
544- analogWrite (TFT_BL, brightness);
567+ if (b < currentBrightness) {
568+ currentBrightness--;
569+ } else if (b > currentBrightness) {
570+ currentBrightness++;
571+ }
572+ uint16_t brightness = map (currentBrightness, 1023 , 0 , MIN_BRIGHTNESS, MAX_BRIGHTNESS);
573+ analogWrite (TFT_BL, brightness);
545574#ifdef DEBUG_BRIGHTNESS
546- Serial.print (" B:\t " );
547- Serial.print (b);
548- Serial.print (" \t CB:\t " );
549- Serial.print (currentBrightness);
550- Serial.print (" \t L:\t " );
551- Serial.println (brightness);
575+ Serial.print (" B:\t " );
576+ Serial.print (b);
577+ Serial.print (" \t CB:\t " );
578+ Serial.print (currentBrightness);
579+ Serial.print (" \t L:\t " );
580+ Serial.println (brightness);
552581#endif
553- nextBrightness = millis () + 10 ;
582+ nextBrightness = millis () + 10 ;
583+ }
554584 }
555- #endif
556585}
557586
558587void printScroll (String text, uint16_t x, uint16_t y, bool force, bool cancelled) {
0 commit comments