diff --git a/examples/README.md b/examples/README.md index b622665..72f7f7b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -13,12 +13,12 @@ ### Inbox -| key | description | values | -|---------|--------------------------------------------------------------------|----------------------------| -| sleep | Start sleep cycles lasting `value` seconds each | 0 (stop sleeping), 1-13612 | -| battery | Ask for battery value | | -| ota | `pio run -t upload --upload-port 192.168.4.1` when connected to AP | | -| skills | Get a list of actions the Brick responds to | | +| key | description | values | +|------------|--------------------------------------------------------------------|----------------------------| +| setSleep | Start sleep cycles lasting `value` seconds each | 0 (stop sleeping), 1-13612 | +| setOta | `pio run -t upload --upload-port 192.168.4.1` when connected to AP | | +| getBattery | Ask for battery value | | +| getSkills | Get a list of actions the Brick responds to | | ### Outbox diff --git a/examples/ble/src/main.cpp b/examples/ble/src/main.cpp index 8864e39..d8809d1 100644 --- a/examples/ble/src/main.cpp +++ b/examples/ble/src/main.cpp @@ -28,13 +28,13 @@ void scan(const uint8_t scanTime, const bool activeScan = false) { Log.notice("BLES: Scan done" CR); } -void passiveScan(const uint8_t *macAddr, const Message message) { +void passiveScan(BRICKS_CALLBACK_SIGNATURE) { const uint8_t scanTime = atoi(message.value); scan(scanTime, false); } // active scan required to get names? -void activeScan(const uint8_t *macAddr, const Message message) { +void activeScan(BRICKS_CALLBACK_SIGNATURE) { const uint8_t scanTime = atoi(message.value); scan(scanTime, true); } diff --git a/examples/buzzer/src/main.cpp b/examples/buzzer/src/main.cpp index be1442d..a666751 100644 --- a/examples/buzzer/src/main.cpp +++ b/examples/buzzer/src/main.cpp @@ -7,7 +7,7 @@ using namespace Bricks; const int BUZZER = D5; // Bricks callbacks -void playTone(const uint8_t *macAddr, const Message message) { +void playTone(BRICKS_CALLBACK_SIGNATURE) { int frequency; int duration; sscanf(message.value, "%d,%d", &frequency, &duration); diff --git a/examples/ir/src/main.cpp b/examples/ir/src/main.cpp index 99dee29..773873b 100644 --- a/examples/ir/src/main.cpp +++ b/examples/ir/src/main.cpp @@ -24,7 +24,7 @@ decode_results results; IRCode *code; // Bricks callbacks -void sendCode(const uint8_t *macAddr, const Message message) { +void sendCode(BRICKS_CALLBACK_SIGNATURE) { code = codes[atoi(message.value)]; } diff --git a/examples/led-matrix/src/main.cpp b/examples/led-matrix/src/main.cpp index f4f2dae..3036d31 100644 --- a/examples/led-matrix/src/main.cpp +++ b/examples/led-matrix/src/main.cpp @@ -9,7 +9,7 @@ using namespace Bricks; MLED matrix(7); // Bricks callbacks -void setValue(const uint8_t *macAddr, const Message message) { +void setValue(BRICKS_CALLBACK_SIGNATURE) { matrix.clear(); matrix.setCursor(2, 1); matrix.print(message.value); diff --git a/examples/led-rgb/src/main.cpp b/examples/led-rgb/src/main.cpp index e679f23..67a89bd 100644 --- a/examples/led-rgb/src/main.cpp +++ b/examples/led-rgb/src/main.cpp @@ -10,15 +10,15 @@ using namespace Bricks; Lumi::Animator animator; // Bricks callbacks -void setPattern(const uint8_t *macAddr, const Message message) { +void setPattern(BRICKS_CALLBACK_SIGNATURE) { animator.currentPattern = atoi(message.value); } -void setVariation(const uint8_t *macAddr, const Message message) { +void setVariation(BRICKS_CALLBACK_SIGNATURE) { animator.currentVariation = atoi(message.value); } -void setDelay(const uint8_t *macAddr, const Message message) { +void setDelay(BRICKS_CALLBACK_SIGNATURE) { animator.currentDelay = atoi(message.value); } diff --git a/examples/led/src/main.cpp b/examples/led/src/main.cpp index ea41e37..3c46c6e 100644 --- a/examples/led/src/main.cpp +++ b/examples/led/src/main.cpp @@ -5,7 +5,7 @@ using namespace Bricks; const int ledPin = LED_BUILTIN; -void setPattern(const uint8_t *macAddr, const Message message) { +void setPattern(BRICKS_CALLBACK_SIGNATURE) { if(atoi(message.value)) { digitalWrite(ledPin, LOW); } diff --git a/src/Bricks.BatterySkill.cpp b/src/Bricks.BatterySkill.cpp index 775ccf4..025cb7f 100644 --- a/src/Bricks.BatterySkill.cpp +++ b/src/Bricks.BatterySkill.cpp @@ -1,7 +1,7 @@ #include namespace Bricks { - BatterySkill::BatterySkill(const uint8_t pin) : Skill("battery") { + BatterySkill::BatterySkill(const uint8_t pin) : Skill("getBattery") { this->pin = pin; } diff --git a/src/Bricks.ListSkill.cpp b/src/Bricks.ListSkill.cpp index 623581d..f55e4f0 100644 --- a/src/Bricks.ListSkill.cpp +++ b/src/Bricks.ListSkill.cpp @@ -1,7 +1,7 @@ #include "Bricks.ListSkill.h" namespace Bricks { - ListSkill::ListSkill() : Skill("skills") { + ListSkill::ListSkill() : Skill("getSkills") { } void ListSkill::callback(BRICKS_CALLBACK_SIGNATURE) { diff --git a/src/Bricks.OtaSkill.cpp b/src/Bricks.OtaSkill.cpp index 9e06a0e..cb636ad 100644 --- a/src/Bricks.OtaSkill.cpp +++ b/src/Bricks.OtaSkill.cpp @@ -1,7 +1,7 @@ #include "Bricks.OtaSkill.h" namespace Bricks { - OtaSkill::OtaSkill() : Skill("ota") { + OtaSkill::OtaSkill() : Skill("setOta") { } void OtaSkill::loop() { diff --git a/src/Bricks.PublishSkill.cpp b/src/Bricks.PublishSkill.cpp index 1ff8a9d..cb58962 100644 --- a/src/Bricks.PublishSkill.cpp +++ b/src/Bricks.PublishSkill.cpp @@ -1,7 +1,7 @@ #include "Bricks.PublishSkill.h" namespace Bricks { - PublishSkill::PublishSkill() : Skill("*") { + PublishSkill::PublishSkill() : Skill("*", nullptr, false) { gEvents.publish(BRICKS_MESSAGES_IN "/gateway/awake"); } diff --git a/src/Bricks.Skill.cpp b/src/Bricks.Skill.cpp index a4550d7..36556f9 100644 --- a/src/Bricks.Skill.cpp +++ b/src/Bricks.Skill.cpp @@ -1,9 +1,10 @@ #include namespace Bricks { - Skill::Skill(const char *key, std::function customCallback) { + Skill::Skill(const char *key, std::function customCallback, bool sendAck) { this->key = key; this->customCallback = customCallback; + this->sendAck = sendAck; } bool Skill::respondsTo(const char *compareKey) { @@ -12,16 +13,16 @@ namespace Bricks { void Skill::process(const uint8_t *macAddr, const Message message) { char response[100]; + strcpy(response, message.value); callback(macAddr, message, response); - // Doesn't work yet. Always true. - if(response) { + if(sendAck) { ack(response); } } void Skill::callback(BRICKS_CALLBACK_SIGNATURE) { - customCallback(macAddr, message); + customCallback(macAddr, message, response); } void Skill::loop() { diff --git a/src/Bricks.Skill.h b/src/Bricks.Skill.h index af2ba32..d1b496b 100644 --- a/src/Bricks.Skill.h +++ b/src/Bricks.Skill.h @@ -14,7 +14,7 @@ namespace Bricks { const char *ACK_PREFIX = "ack"; public: - Skill(const char *key = "", std::function customCallback = nullptr); + Skill(const char *key = "", std::function customCallback = nullptr, bool sendAck = true); bool respondsTo(const char* compareKey); void process(const uint8_t *macAddr, const Message message); virtual void callback(BRICKS_CALLBACK_SIGNATURE); @@ -22,7 +22,8 @@ namespace Bricks { const char *key; private: void ack(const char *response); - std::function customCallback; + bool sendAck; + std::function customCallback; }; } #endif diff --git a/src/Bricks.SleepSkill.cpp b/src/Bricks.SleepSkill.cpp index afc0c56..58d669b 100644 --- a/src/Bricks.SleepSkill.cpp +++ b/src/Bricks.SleepSkill.cpp @@ -5,7 +5,7 @@ namespace Bricks { RTC_DATA_ATTR uint32_t rtcSleepTime = 0; #endif - SleepSkill::SleepSkill(const char *name) : Skill("sleep") { + SleepSkill::SleepSkill(const char *name) : Skill("setSleep") { this->name = name; sendAwakeMessage(); diff --git a/test/inbox/test_inbox.cpp b/test/inbox/test_inbox.cpp index 4080972..0df7874 100644 --- a/test/inbox/test_inbox.cpp +++ b/test/inbox/test_inbox.cpp @@ -13,7 +13,7 @@ void setUp(void) { void test_battery() { const uint8_t macAddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; Message message; - strcpy(message.key, "battery"); + strcpy(message.key, "getBattery"); gInbox.skills[0] = new BatterySkill(); gInbox.process(macAddr, message); @@ -22,7 +22,7 @@ void test_battery() { void test_list_skills() { gInbox.skills[0] = new BatterySkill(); - TEST_ASSERT_EQUAL_STRING("battery", gInbox.listSkills().c_str()); + TEST_ASSERT_EQUAL_STRING("getBattery", gInbox.listSkills().c_str()); } void setup() {