Skip to content

Commit

Permalink
fix: add debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
silvelo committed Jul 19, 2024
1 parent 9c5f4e0 commit fdb2e95
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
12 changes: 11 additions & 1 deletion data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@
<section class="flex ">
<h1 class="flex-1 text-center text-4xl font-bold my-8">7 Segment Clock</h1>

<a href="/update">UPDATE</a>
<div class="flex gap-4">
<div>
<button class="mt-4 p-4 middle w-full none center rounded-lg bg-pink-500 font-sans text-xs font-bold uppercase text-white shadow-md shadow-pink-500/20 transition-all hover:shadow-lg hover:shadow-pink-500/40 focus:opacity-[0.85] focus:shadow-none active:opacity-[0.85] active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none">
<a href="/update">UPDATE</a>
</button>
</div>
<div>
<button onclick="setDebug()" class="mt-4 p-4 middle w-full none center rounded-lg bg-pink-500 py-3 px-6 font-sans text-xs font-bold uppercase text-white shadow-md shadow-pink-500/20 transition-all hover:shadow-lg hover:shadow-pink-500/40 focus:opacity-[0.85] focus:shadow-none active:opacity-[0.85] active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none">Enable Debug</button>
</div>
</div>
<button></button>
</section>
<section class="flex flex-col gap-4 items-center h-full">
<div
Expand Down
32 changes: 32 additions & 0 deletions data/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
window.onload = onLoad

debugMode = false;

function onLoad() {
getColors();
getDeepSleep();
getLedsPerSegment();
getTimeZone();
getDebug()
}

function getColors() {
Expand Down Expand Up @@ -33,6 +36,20 @@ async function setColors(event){
await setData("/colors", formElement);
}

function getDebug() {
fetch("/debug")
.then((response) => response.json())
.then((data) => {
debugMode = data.debug;
});
}

async function setDebug(){
debugMode = !debugMode;
console.log(debugMode)
await makePost("/debug", {debug: debugMode});
}

function getLedsPerSegment() {
fetch("/leds")
.then((response) => response.json())
Expand Down Expand Up @@ -84,6 +101,21 @@ async function setDeepSleep(event){

}

async function makePost(url, data) {
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
//console.log(await response.json());
} catch (e) {
console.error(e);
}
}

async function setData(url, formElement) {
const formData = new FormData(formElement);

Expand Down
28 changes: 15 additions & 13 deletions include/LedManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class LedManager {
void begin();
void end();
void showHours(int hour);
void showHoursTest(int hour);
void showMinutesTest(int minutes);
void showMinutes(int minutes);
void showColon();
void updateColorsFromPreferences();
Expand Down Expand Up @@ -54,25 +56,25 @@ class LedManager {
{true, true, true, true, true, true, false},
};

/* bool minuteSegments[10][7] = {
{true, true, true, false, true, true, true},
{false, false, true, false, false, false, true},
{true, true, false, true, false, true, true},
{false, true, true, true, false, true, true},
{false, false, true, true, true, false, true},
{false, true, true, true, true, true, false},
{true, true, true, true, true, true, false},
{false, false, true, false, false, true, true},
{true, true, true, true, true, true, true},
{false, true, true, true, true, true, true},
}; */
/* bool minuteSegments[10][7] = {
{true, true, true, false, true, true, true},
{false, false, true, false, false, false, true},
{true, true, false, true, false, true, true},
{false, true, true, true, false, true, true},
{false, false, true, true, true, false, true},
{false, true, true, true, true, true, false},
{true, true, true, true, true, true, false},
{false, false, true, false, false, true, true},
{true, true, true, true, true, true, true},
{false, true, true, true, true, true, true},
}; */

bool minuteSegments[10][7] = {
{true, true, true, false, true, true, true},
{false, false, true, false, false, false, true},
{false, true, true, true, true, true, false},
{false, true, true, true, false, true, true},
{true, false, true, true, false, true, true},
{true, false, true, true, false, false, true},
{true, true, false, true, false, true, true},
{true, true, false, true, true, true, true},
{false, true, true, false, false, false, true},
Expand Down
3 changes: 3 additions & 0 deletions include/PreferencesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define MINUTES_LED_1_COLOR "ml1c"
#define MINUTES_LED_2_COLOR "ml2c"
#define LEDS_PER_SEGMENT "lps"
#define DEBUG "debug"

#include <Preferences.h>
#include <SPIFFS.h>
Expand Down Expand Up @@ -42,6 +43,8 @@ class PreferencesManager {
void setMinutesLed2Color(uint32_t color);
int getLedsPerSegment();
void setLedsPerSegment(int numLeds);
bool getDebug();
void setDebug(bool debug);

private:
PreferencesManager() = default;
Expand Down
3 changes: 3 additions & 0 deletions include/ServerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class ServerManager {
void getColors(AsyncWebServerRequest *request);
void updateColors(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index,
size_t total);
void getDebug(AsyncWebServerRequest *request);
void updateDebug(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index,
size_t total);
void getLedsPerSegment(AsyncWebServerRequest *request);
void updateLedsPerSegment(AsyncWebServerRequest *request, uint8_t *data, size_t len,
size_t index, size_t total);
Expand Down

0 comments on commit fdb2e95

Please sign in to comment.