feat(esp32): add power-off hysteresis, change green color slighly for improved perception with red-green-blindness
This commit is contained in:
parent
7f3f5f2b6c
commit
02ef61c54b
1 changed files with 11 additions and 5 deletions
|
@ -143,9 +143,6 @@ void setup() {
|
|||
pixels.show();
|
||||
|
||||
WiFi.setHostname("spaceapimap");
|
||||
WiFi.setTxPower(WIFI_POWER_15dBm);
|
||||
WiFi.enableIpV6();
|
||||
WiFi.setAutoReconnect(true);
|
||||
|
||||
wifiManager.setDebugOutput(true);
|
||||
wifiManager.setConnectTimeout(60);
|
||||
|
@ -294,6 +291,7 @@ bool updateMap() {
|
|||
#ifdef FEATURE_LDR
|
||||
uint16_t rolling_average_brightness[10];
|
||||
uint8_t rolling_average_brightness_i = 0;
|
||||
bool leds_on_hysteresis = true;
|
||||
uint16_t ambientBrightnessToPower() {
|
||||
// Read brightness from LDR (0..2500 mV) and map to power level (0..255) and write into rolling average list
|
||||
rolling_average_brightness[rolling_average_brightness_i] = analogRead(FEATURE_LDR);
|
||||
|
@ -306,7 +304,15 @@ uint16_t ambientBrightnessToPower() {
|
|||
uint16_t brightness = sum / (sizeof(rolling_average_brightness)/sizeof(uint16_t));
|
||||
Serial.print("brightness: ");
|
||||
Serial.println(brightness);
|
||||
if (brightness < spiffs_config.brightness_thresh_lower) {
|
||||
if (brightness > spiffs_config.brightness_thresh_lower + 40 && leds_on_hysteresis) {
|
||||
Serial.println("LED power off!");
|
||||
leds_on_hysteresis = false;
|
||||
}
|
||||
if (brightness < spiffs_config.brightness_thresh_lower - 40 && !leds_on_hysteresis) {
|
||||
Serial.println("LED power on!");
|
||||
leds_on_hysteresis = true;
|
||||
}
|
||||
if (leds_on_hysteresis) {
|
||||
uint16_t clamped = min(max(brightness, spiffs_config.brightness_thresh_upper), spiffs_config.brightness_thresh_lower);
|
||||
uint8_t power = spiffs_config.brightness_min + (spiffs_config.brightness_max - spiffs_config.brightness_min) * pow(1.0f * (spiffs_config.brightness_thresh_lower - clamped) / (spiffs_config.brightness_thresh_lower - spiffs_config.brightness_thresh_upper), 2);
|
||||
// Safeguard in case the computation is somehow off!
|
||||
|
@ -340,7 +346,7 @@ void loop() {
|
|||
pixels.setPixelColor(i, pixels.Color(power, 0, 0)); // closed -> red
|
||||
break;
|
||||
case SpaceState::Open:
|
||||
pixels.setPixelColor(i, pixels.Color(0, power, 0)); // open -> green
|
||||
pixels.setPixelColor(i, pixels.Color(0, power, power/8)); // open -> green
|
||||
break;
|
||||
case SpaceState::Invalid:
|
||||
pixels.setPixelColor(i, pixels.Color(power, power/2, 0)); // invalid response -> orange
|
||||
|
|
Loading…
Reference in a new issue