From fe8d3df4214aa5dcb5208e45ef1070b297887703 Mon Sep 17 00:00:00 2001 From: legop3 Date: Sat, 18 Apr 2026 18:22:42 -0400 Subject: [PATCH] prebubtotn --- buttonbox/src/main.cpp | 98 +++++++++++++++++++++++++++++++++++++++--- plans/espbuttonbox.md | 52 +++++++++++++++++----- 2 files changed, 133 insertions(+), 17 deletions(-) diff --git a/buttonbox/src/main.cpp b/buttonbox/src/main.cpp index 2be9e944..66a9d9f5 100644 --- a/buttonbox/src/main.cpp +++ b/buttonbox/src/main.cpp @@ -4,6 +4,61 @@ #include +// button pin defs +const int buttonPins[] = {15, 16, 17, 18}; +const int buttonCount = sizeof(buttonPins) / sizeof(buttonPins[0]); +const int beeperPin = 13; + +// Using INPUT_PULLUP means idle = HIGH, pressed = LOW (button to GND). +const int buttonPressedState = LOW; +const unsigned long debounceMs = 40; +const int toneDurationMs = 90; + +// One tone per button (1-4). +const int buttonTonesHz[buttonCount] = {262, 330, 392, 523}; + +int lastStableState[buttonCount]; +int lastReading[buttonCount]; +unsigned long lastDebounceTime[buttonCount]; + +void PlayButtonTone(int buttonNumber) { + if (buttonNumber < 1 || buttonNumber > buttonCount) { + return; + } + + int frequencyHz = buttonTonesHz[buttonNumber - 1]; + tone(beeperPin, frequencyHz, toneDurationMs); +} + +// button request function +bool SendButtonPressRequest(int buttonNumber) { + Serial.println("attempting to send button press"); + bool success = false; + if (WiFi.status() == WL_CONNECTED) { + HTTPClient http; + http.begin(SERVER_URL); + http.addHeader("Content-Type", "text/plain"); + + int httpResponseCode = http.POST(String(buttonNumber)); + + if (httpResponseCode > 0) { + Serial.println("http response code: "); + Serial.print(httpResponseCode); + Serial.println(http.getString()); + success = true; + } else { + Serial.println("HTTP ERROR!!! "); + Serial.print(httpResponseCode); + success = false; + } + http.end(); + + } else { + Serial.println("Not ocnnectec to wifi! cant send request!"); + } + return success; +} + void setup() { Serial.begin(115200); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); @@ -13,14 +68,43 @@ void setup() { } Serial.println("WIFI CONNENCTED !!!! :3"); - pinMode(37, OUTPUT); + for (int i = 0; i < buttonCount; i++) { + pinMode(buttonPins[i], INPUT_PULLUP); + int initial = digitalRead(buttonPins[i]); + lastStableState[i] = initial; + lastReading[i] = initial; + lastDebounceTime[i] = 0; + } + + pinMode(beeperPin, OUTPUT); + noTone(beeperPin); } void loop() { - Serial.println("looping..."); - delay(500); + unsigned long now = millis(); - digitalWrite(37, HIGH); - delay(400); - digitalWrite(37, LOW); -} \ No newline at end of file + for (int i = 0; i < buttonCount; i++) { + int reading = digitalRead(buttonPins[i]); + + if (reading != lastReading[i]) { + lastDebounceTime[i] = now; + } + + if ((now - lastDebounceTime[i]) > debounceMs) { + if (reading != lastStableState[i]) { + lastStableState[i] = reading; + + // Trigger once on press edge. + if (reading == buttonPressedState) { + if (SendButtonPressRequest(i + 1)) { + PlayButtonTone(i + 1); + } + } + } + } + + lastReading[i] = reading; + } + + delay(5); +} diff --git a/plans/espbuttonbox.md b/plans/espbuttonbox.md index 54631675..e477c955 100644 --- a/plans/espbuttonbox.md +++ b/plans/espbuttonbox.md @@ -1,11 +1,43 @@ -# esp32 button box -- 4 buttons each has a light -- also a beeper -- maybe some other indicator lights -- each button has its own tone that plays when pressed -- each button has it's own counter +# button box mechanic +- a box with 4 buttons which sends web requests to the server when a button is pressed +- each button has a counter in the server +- when the counter's goal is met, the reward happens -## api stuff -- each button press sends a web request to the server's IP containing: - - the button number (1 - 4) -- when the server gets this request, it adds 1 to that button's counter +## rewards +- theres a list of rewards in the server +- rewards create chaos in different ways using the physical things that already exist +- rewards have actions and a counter goal set per reward to assign value to better rewards +- when a reward is met, the button gets a new goal, reset counter, and new reward + +## UI +- a new full-width panel above the room cameras in the main tab +- divided into columns, one for each of the 4 buttons + - each columns shows: + - button number + - current count + - reward and reward number + - column flashes when button gets upped + - column plays a sound when button gets upped. same tone as the button. +- match styling and layout rules of the rest of the ui + +### reward ideas +1. dock panic + force all online rovers to run seek-dock immediately, interrupting whatever it was doing and causing sudden behavior change +2. camera whiplash + apply a short burst of random camera servo nudges on all rovers so the view jerks around rapidly for a moment +3. light strobe + toggle all configured room controls on and off repeatedly for 10 seconds +4. ghost typing spam + emit fake typing events into chat so users see rapid typing indicators from fake/ghost senders without actual messages +5. darkness + turn room lights off for 1 minute and force rover night-vision/headlight state off for that same window, then restore normal state +6. discord stalker ping + send a chaos alert message to the configured discord general channel and ping the configured stalker role +7. rogue event spam + push a burst of fake alert events with random titles/colors into the web ui alert feed for jump-scare style noise +8. mode jam + switch server mode to admin for a short timed window, set admin reason to a chaos message at activation, then restore previous mode and previous admin reason +9. assignment roulette + forcibly release current user rover assignments/drivers and let assignment logic re-place users, causing sudden rover ownership reshuffle +10. chat spam + spam random letters in chat as an injected spectator user with a random letter name