Skip to content

Commit

Permalink
Merge pull request #493 from majadesignz/main
Browse files Browse the repository at this point in the history
Add 'swap_buttons' and 'ldr_on_ground' settings for dev.json
  • Loading branch information
Blueforcer authored Jan 4, 2025
2 parents 3d0aab1 + 1f65c22 commit 3079aaa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ void loadDevSettings()
NEWYEAR = doc["new_year"].as<bool>();
}

if (doc.containsKey("swap_buttons"))
{
SWAP_BUTTONS = doc["swap_buttons"].as<bool>();
}

if (doc.containsKey("ldr_on_ground"))
{
LDR_ON_GROUND = doc["ldr_on_ground"].as<bool>();
}

if (doc.containsKey("button_callback"))
{
BUTTON_CALLBACK = doc["button_callback"].as<String>();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 16 additions & 8 deletions src/PeripheryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -445,7 +445,8 @@ void PeripheryManager_::setup()
#else

#endif
photocell.setPhotocellPositionOnGround(false);
if (!LDR_ON_GROUND)
photocell.setPhotocellPositionOnGround(false);
}

void PeripheryManager_::tick()
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3079aaa

Please sign in to comment.