diff --git a/docs/dev.md b/docs/dev.md index 6c76444..d04b82d 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -38,6 +38,8 @@ The JSON object has the following properties: | `buzzer_volume` | boolean | Activates the volume control for the buzzer, doesnt work with every tones | false | | `button_callback` | string | http callback url for button presses. | - | | `new_year` | boolean | Displays fireworks and plays a jingle at newyear. | false | +| `swap_buttons` | boolean | Swaps the left and right hardware button. | false | +| `ldr_on_ground` | boolean | Sets the LDR configuration to LDR-on-ground. | false | #### Example: diff --git a/src/Globals.cpp b/src/Globals.cpp index 5315599..a59e7f0 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -191,6 +191,16 @@ void loadDevSettings() NEWYEAR = doc["new_year"].as(); } + if (doc.containsKey("swap_buttons")) + { + SWAP_BUTTONS = doc["swap_buttons"].as(); + } + + if (doc.containsKey("ldr_on_ground")) + { + LDR_ON_GROUND = doc["ldr_on_ground"].as(); + } + if (doc.containsKey("button_callback")) { BUTTON_CALLBACK = doc["button_callback"].as(); @@ -445,6 +455,8 @@ String AUTH_USER = ""; String AUTH_PASS = "awtrix"; String BUTTON_CALLBACK = ""; bool NEWYEAR = false; +bool SWAP_BUTTONS = false; +bool LDR_ON_GROUND = false; float LDR_GAMMA = 3.0; float LDR_FACTOR = 1.0; bool GAME_ACTIVE = false; diff --git a/src/Globals.h b/src/Globals.h index a88eded..87b344a 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -142,6 +142,8 @@ extern String AUTH_USER; extern String AUTH_PASS; extern String BUTTON_CALLBACK; extern bool NEWYEAR; +extern bool SWAP_BUTTONS; +extern bool LDR_ON_GROUND; extern bool GAME_ACTIVE; extern uint32_t AP_TIMEOUT; extern OverlayEffect GLOBAL_OVERLAY; diff --git a/src/PeripheryManager.cpp b/src/PeripheryManager.cpp index c7c186b..c15bcc6 100644 --- a/src/PeripheryManager.cpp +++ b/src/PeripheryManager.cpp @@ -393,7 +393,7 @@ void PeripheryManager_::setup() button_select.begin(); button_reset.begin(); - if (ROTATE_SCREEN) + if ((ROTATE_SCREEN && !SWAP_BUTTONS) || (!ROTATE_SCREEN && SWAP_BUTTONS)) { Serial.println("Button rotation"); button_left.onPressed(right_button_pressed); @@ -445,7 +445,8 @@ void PeripheryManager_::setup() #else #endif - photocell.setPhotocellPositionOnGround(false); + if (!LDR_ON_GROUND) + photocell.setPhotocellPositionOnGround(false); } void PeripheryManager_::tick() @@ -532,18 +533,25 @@ void PeripheryManager_::tick() } unsigned long currentMillis_LDR = millis(); - if (currentMillis_LDR - previousMillis_LDR >= interval_LDR) + if (currentMillis_LDR - previousMillis_LDR >= interval_LDR) { previousMillis_LDR = currentMillis_LDR; + TotalLDRReadings[sampleIndex] = analogRead(LDR_PIN); - uint16_t LDRVALUE = analogRead(LDR_PIN); - - // Send LDR values through median filter to get rid of the remaining spikes and then calculate the average - LDR_RAW = meanFilterLDR.AddValue(medianFilterLDR.AddValue(LDRVALUE)); + sampleIndex = (sampleIndex + 1) % LDRReadings; + sampleSum = 0.0; + for (int i = 0; i < LDRReadings; i++) + { + sampleSum += TotalLDRReadings[i]; + } + sampleAverage = sampleSum / (float)LDRReadings; + if (LDR_ON_GROUND) + sampleAverage = 1023.0 - sampleAverage; + LDR_RAW = sampleAverage; CURRENT_LUX = (roundf(photocell.getSmoothedLux() * 1000) / 1000); if (AUTO_BRIGHTNESS && !MATRIX_OFF) { - brightnessPercent = (LDR_RAW * LDR_FACTOR) / 1023.0 * 100.0; + brightnessPercent = (sampleAverage * LDR_FACTOR) / 1023.0 * 100.0; brightnessPercent = pow(brightnessPercent, LDR_GAMMA) / pow(100.0, LDR_GAMMA - 1); BRIGHTNESS = map(brightnessPercent, 0, 100, MIN_BRIGHTNESS, MAX_BRIGHTNESS); DisplayManager.setBrightness(BRIGHTNESS);