Skip to content

Commit

Permalink
fix detector duck (ClusterDuck-Protocol#462)
Browse files Browse the repository at this point in the history
Signed-off-by: faradaym <[email protected]>
  • Loading branch information
faradaym authored Jan 7, 2025
1 parent ef12fe2 commit d3ea87a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
31 changes: 29 additions & 2 deletions examples/Basic-Ducks/DetectorDuck/DetectorDuck.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
#include <arduino-timer.h>
#include <string>
#include <DuckDetect.h>
#include "FastLED.h"

// Setup for W2812 (LED)
#define LED_TYPE WS2812
#define DATA_PIN 4
#define NUM_LEDS 1
#define COLOR_ORDER GRB
#define BRIGHTNESS 128
#include <pixeltypes.h>
CRGB leds[NUM_LEDS];

// Needed if using a board with built-in USB, such as Arduiono Zero
#ifdef SERIAL_PORT_USBVIRTUAL
Expand Down Expand Up @@ -45,10 +55,17 @@ void setup() {
// Initialize the timer. The timer thread runs separately from the main loop
// and will trigger sending a counter message.
timer.every(INTERVAL_MS, pingHandler);

FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 );
FastLED.setBrightness( BRIGHTNESS );
leds[0] = CRGB::Gold;
FastLED.show();

Serial.println("[DETECTOR] Setup OK!");
}

void handleReceiveRssi(const int rssi) {
Serial.print("rssi callback called");
showSignalQuality(rssi);
}

Expand All @@ -59,8 +76,7 @@ void loop() {

// Periodically sends a ping message
bool pingHandler(void *) {
Serial.println("[DETECTOR] Says ping!");
duck.sendPing(true);
duck.sendPing();

return true;
}
Expand All @@ -74,11 +90,22 @@ void showSignalQuality(int incoming) {

if (rssi > -95) {
Serial.println(" - GOOD");
leds[0] = CRGB::Green;
FastLED.show();
}
else if (rssi <= -95 && rssi > -108) {
Serial.println(" - OKAY");
leds[0] = CRGB::Yellow;
FastLED.show();
}
else if (rssi <= -108) {
Serial.println(" - BAD");
Serial.println(" - BAD");
leds[0] = CRGB::Orange;
FastLED.show();
}
else {
leds[0] = CRGB::Red;
FastLED.show();
}
}
11 changes: 10 additions & 1 deletion examples/Basic-Ducks/DetectorDuck/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ description = DetectorDuck CDP examples
SPI
contrem/arduino-timer@^3.0.1
bblanchon/ArduinoJson@^7.0.3
FastLED/FastLED@^3.6.0

[env:esp32]
lib_deps =
lib_deps = FastLED/FastLED@^3.6.0

[env:local_cdp]
lib_deps = symlink://../../../ ; local CDP library
Expand All @@ -67,6 +68,7 @@ description = DetectorDuck CDP examples
lib_deps =
${env:esp32.lib_deps}
${env:release_cdp.lib_deps}
FastLED/FastLED@^3.6.0

; PRODUCTION HELTEC_WIFI_LORA_32_V3
[env:prod_heltec_wifi_lora_32_V3]
Expand All @@ -78,6 +80,7 @@ description = DetectorDuck CDP examples
lib_deps =
${env:esp32.lib_deps}
${env:release_cdp.lib_deps}
FastLED/FastLED@^3.6.0

; PRODUCTION LILYGO_T_BEAM_SX1262
[env:prod_lilygo_t_beam_sx1262]
Expand All @@ -89,6 +92,7 @@ description = DetectorDuck CDP examples
lib_deps =
${env:esp32.lib_deps}
${env:release_cdp.lib_deps}
FastLED/FastLED@^3.6.0

; PRODUCTION TTGO_LORA32_V1
[env:prod_ttgo_lora32_v1]
Expand All @@ -100,6 +104,7 @@ description = DetectorDuck CDP examples
lib_deps =
${env:esp32.lib_deps}
${env:release_cdp.lib_deps}
FastLED/FastLED@^3.6.0

; -------------------------------------------------------------------------------------------------------
; ---- LOCAL ENVIRONMENTS
Expand All @@ -115,6 +120,7 @@ description = DetectorDuck CDP examples
lib_deps =
${env:esp32.lib_deps}
${env:local_cdp.lib_deps}
FastLED/FastLED@^3.6.0

; LOCAL HELTEC_WIFI_LORA_32_V3
[env:local_heltec_wifi_lora_32_V3]
Expand All @@ -126,6 +132,7 @@ description = DetectorDuck CDP examples
lib_deps =
${env:esp32.lib_deps}
${env:local_cdp.lib_deps}
FastLED/FastLED@^3.6.0

; LOCAL LILYGO_T_BEAM_SX1262
[env:local_lilygo_t_beam_sx1262]
Expand All @@ -137,6 +144,7 @@ description = DetectorDuck CDP examples
lib_deps =
${env:esp32.lib_deps}
${env:local_cdp.lib_deps}
FastLED/FastLED@^3.6.0

; LOCAL TTGO_LORA32_V1
[env:local_ttgo_lora32_v1]
Expand All @@ -148,4 +156,5 @@ description = DetectorDuck CDP examples
lib_deps =
${env:esp32.lib_deps}
${env:local_cdp.lib_deps}
FastLED/FastLED@^3.6.0

2 changes: 2 additions & 0 deletions src/CdpPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class CdpPacket {
return "pir";
case topics::bmp180:
return "bmp180";
case reservedTopic::ping:
return "ping";
default:
return "unknown";
}
Expand Down
2 changes: 1 addition & 1 deletion src/DuckDetect.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DuckDetect : public Duck {
* @param startReceive `true` if the device must to be ready to receive a response immediately,
* `false` if response needs to be deffered.
*/
void sendPing(bool startReceive);
void sendPing();

/**
* @brief Provide the DuckDetect specific implementation of the base `run()`
Expand Down
9 changes: 2 additions & 7 deletions src/Ducks/DuckDetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,14 @@ void DuckDetect::handleReceivedPacket() {
}
}

void DuckDetect::sendPing(bool startReceive) {
void DuckDetect::sendPing() {
Serial.println(String("send ping actually called from detector"));
int err = DUCK_ERR_NONE;
std::vector<byte> data(1, 0);
err = txPacket->prepareForSending(&filter, BROADCAST_DUID, DuckType::DETECTOR, reservedTopic::ping, data);

if (err == DUCK_ERR_NONE) {
err = duckRadio.sendData(txPacket->getBuffer());
if (startReceive) {
duckRadio.startReceive();
}
if (err != DUCK_ERR_NONE) {
logerr("ERROR Failed to ping, err = %s\n",err);
}
} else {
logerr("ERROR Failed to build packet, err = %s\n",err);
}
Expand Down

0 comments on commit d3ea87a

Please sign in to comment.