@@ -98,6 +98,12 @@ uint8_t rotation = 1;
98
98
#endif
99
99
#endif
100
100
101
+ #ifndef LDR_IN
102
+ #define LDR_IN -1
103
+ #endif
104
+
105
+ int8_t ldr_pin = LDR_IN;
106
+
101
107
#ifdef AUTOCONFIG
102
108
#endif
103
109
@@ -142,6 +148,11 @@ void updateStarted() {
142
148
WiFiManager wifiManager;
143
149
WiFiManagerParameter stationNameParameter (" stationName" , " Stationsname" , fromStationName, sizeof (fromStationName));
144
150
WiFiManagerParameter 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
145
156
WiFiManagerParameter filterICEParameter (" filterICE" , " Hochgeschwindigkeitszüge (1 zum Aktivieren)" , String((filter & PROD_ICE) > 0).c_str(), 1);
146
157
WiFiManagerParameter filterICECParameter (" filterICEC" , " Intercity- und Eurocityzüge 1 zum Aktivieren)" , String((filter & PROD_IC_EC) > 0).c_str(), 1);
147
158
WiFiManagerParameter filterIRParameter (" filterIR" , " Interregio- und Schnellzüge (1 zum Aktivieren)" , String((filter & PROD_IR) > 0).c_str(), 1);
@@ -215,6 +226,16 @@ void readParams() {
215
226
} else {
216
227
Serial.println (" File not found" );
217
228
}
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
+ }
218
239
if (LittleFS.exists (" /filter" )) {
219
240
File f = LittleFS.open (" /filter" , " r" );
220
241
if (f) {
@@ -269,6 +290,12 @@ void afterConfigCallback() {
269
290
Serial.print (" Rotation gesetzt: " );
270
291
Serial.println (rotation);
271
292
}
293
+ ldr_pin = atoi (ldrParameter.getValue ());
294
+ {
295
+ File f = LittleFS.open (" /ldr" , " w" );
296
+ f.print (ldrParameter.getValue ());
297
+ f.close ();
298
+ }
272
299
uint16_t val =
273
300
(filterICEParameter.getValue ()[0 ] == ' 1' ) * PROD_ICE |
274
301
(filterICECParameter.getValue ()[0 ] == ' 1' ) * PROD_IC_EC |
@@ -338,6 +365,8 @@ void setup() {
338
365
wifiManager.addParameter (&stationNameParameter);
339
366
rotationParameter.setValue (String (rotation).c_str (), 1 );
340
367
wifiManager.addParameter (&rotationParameter);
368
+ ldrParameter.setValue (String (ldr_pin).c_str (), 2 );
369
+ wifiManager.addParameter (&ldrParameter);
341
370
filterICEParameter.setValue (String ((filter & PROD_ICE) > 0 ).c_str (), 1 );
342
371
wifiManager.addParameter (&filterICEParameter);
343
372
filterICECParameter.setValue (String ((filter & PROD_IC_EC) > 0 ).c_str (), 1 );
@@ -529,30 +558,30 @@ void loop() {
529
558
#ifdef AUTOCONFIG
530
559
checkConfigRequest ();
531
560
#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 );
535
564
#ifdef ESP32
536
- b >>= 2 ;
565
+ b >>= 2 ;
537
566
#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);
545
574
#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);
552
581
#endif
553
- nextBrightness = millis () + 10 ;
582
+ nextBrightness = millis () + 10 ;
583
+ }
554
584
}
555
- #endif
556
585
}
557
586
558
587
void printScroll (String text, uint16_t x, uint16_t y, bool force, bool cancelled) {
0 commit comments