Skip to content

Commit

Permalink
Merge pull request #9 from blackcoffeexbt/added-buzzer-support
Browse files Browse the repository at this point in the history
Addded buzzer disable bool flag
  • Loading branch information
blackcoffeexbt authored Oct 9, 2023
2 parents 500f204 + 361e119 commit 438fcd0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
5 changes: 5 additions & 0 deletions code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
10 changes: 10 additions & 0 deletions code/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
26 changes: 18 additions & 8 deletions code/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "freertos/task.h"

#define BUZZER_PIN 2 // Connect the piezo buzzer to this GPIO pin.
#define CLICK_DURATION 10 // Duration in milliseconds.
#define CLICK_DURATION 20 // Duration in milliseconds.

#define PARAM_FILE "/elements.json"

Expand Down Expand Up @@ -56,6 +56,8 @@ NostrRequestOptions* eventRequestOptions;

bool hasSentEvent = false;

bool isBuzzerEnabled = false;

extern char npubHexString[80];
extern char relayString[80];

Expand Down Expand Up @@ -105,9 +107,9 @@ void WiFiEvent(WiFiEvent_t event) {
switch(event) {
case SYSTEM_EVENT_STA_GOT_IP:
Serial.println("Connected to WiFi and got an IP");
click(250);
click(225);
delay(100);
click(250);
click(225);
connectToNostrRelays();
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
Expand Down Expand Up @@ -162,7 +164,13 @@ void lampControlTask(void *pvParameters) {
zapAmountsFlashQueue.erase(zapAmountsFlashQueue.begin());
xSemaphoreGive(zapMutex);

// Click the buzzer zapAmount many times in a for loop with 100 ms delay
for (int i = 0; i < zapAmount; i++) {
click(225);
delay(100);
}
doLightningFlash(zapAmount);

// vTaskDelay(500 / portTICK_PERIOD_MS);
}
vTaskDelay(100 / portTICK_PERIOD_MS);
Expand Down Expand Up @@ -389,11 +397,11 @@ void relayConnectedEvent(const std::string& key, const std::string& message) {
socketDisconnectedCount = 0;
Serial.println("Relay connected: ");

click(250);
click(225);
delay(100);
click(250);
click(225);
delay(100);
click(250);
click(225);

Serial.print(F("Requesting events:"));
Serial.println(serialisedEventRequest);
Expand Down Expand Up @@ -515,7 +523,6 @@ uint16_t getRandomNum(uint16_t min, uint16_t max) {

void zapReceiptEvent(const std::string& key, const char* payload) {
if(lastPayload != payload) { // Prevent duplicate events from multiple relays triggering the same logic, as we are using multiple relays, this is likely to happen
click(150);
lastPayload = payload;
String bolt11 = getBolt11InvoiceFromEvent(payload);
// Serial.println("BOLT11: " + bolt11);
Expand All @@ -542,6 +549,9 @@ void initLamp() {

void click(int period)
{
if(!isBuzzerEnabled) {
return;
}
for (int i = 0; i < CLICK_DURATION; i++)
{
digitalWrite(BUZZER_PIN, HIGH);
Expand All @@ -556,7 +566,7 @@ void setup() {
Serial.println("boot");

pinMode(BUZZER_PIN, OUTPUT); // Set the buzzer pin as an output.
click(250);
click(225);

FlashFS.begin(FORMAT_ON_FAIL);
// init spiffs
Expand Down

0 comments on commit 438fcd0

Please sign in to comment.