From f3b78e366907984630d4910f402a6204e45a9c7e Mon Sep 17 00:00:00 2001 From: fauresystems <34378695+fauresystems@users.noreply.github.com> Date: Thu, 30 Apr 2020 16:48:56 +0200 Subject: [PATCH] Complete reanme Props to Prop --- EXAMPLES.md | 1 - keywords.txt | 6 ++-- src/ArduinoProps.cpp | 1 - src/ArduinoProps.h | 1 - src/BridgeProp.cpp | 5 ++-- src/BridgeProp.h | 5 ++-- src/EthernetProp.cpp | 5 ++-- src/EthernetProp.h | 5 ++-- src/Prop.cpp | 67 ++++++++++++++++++++++---------------------- src/Prop.h | 11 ++++---- src/PropAction.cpp | 1 - src/PropAction.h | 7 ++--- src/PropData.cpp | 1 - src/PropData.h | 5 ++-- src/WifiProp.cpp | 5 ++-- src/WifiProp.h | 5 ++-- 16 files changed, 58 insertions(+), 73 deletions(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index 21b45f3..75ce8f0 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -224,7 +224,6 @@ However, this can help in special cases. ```csharp /* Name: BlinkOnBridgePubSub.ino - Created: 29/10/2019 16:51:55 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure diff --git a/keywords.txt b/keywords.txt index 81555f4..05c62ae 100644 --- a/keywords.txt +++ b/keywords.txt @@ -6,7 +6,7 @@ # Datatypes (KEYWORD1) ####################################### -Props KEYWORD1 +Prop KEYWORD1 BridgeProp KEYWORD1 EthernetProp KEYWORD1 WifiProp KEYWORD1 @@ -16,8 +16,8 @@ PropDataDecimal KEYWORD1 PropDataInteger KEYWORD1 PropDataLogical KEYWORD1 PropDataText KEYWORD1 -PropsCallback KEYWORD1 -PropsMessageReceived KEYWORD1 +PropCallback KEYWORD1 +PropMessageReceived KEYWORD1 InboxMessage KEYWORD1 ####################################### diff --git a/src/ArduinoProps.cpp b/src/ArduinoProps.cpp index 1023262..e3e5791 100644 --- a/src/ArduinoProps.cpp +++ b/src/ArduinoProps.cpp @@ -1,6 +1,5 @@ /* Name: ArduinoProps.h - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure diff --git a/src/ArduinoProps.h b/src/ArduinoProps.h index 6d70729..ab31298 100644 --- a/src/ArduinoProps.h +++ b/src/ArduinoProps.h @@ -1,6 +1,5 @@ /* Name: ArduinoProps.h - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure diff --git a/src/BridgeProp.cpp b/src/BridgeProp.cpp index 87832be..25888bd 100644 --- a/src/BridgeProp.cpp +++ b/src/BridgeProp.cpp @@ -1,17 +1,16 @@ /* Name: BridgeProp.cpp - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure - Class Props for Arduino Yun and Dragino Yun shield. + Prop for Arduino Yun and Dragino Yun shield. */ #include "BridgeProp.h" BridgeProp::BridgeProp(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port) - : Props(client_id, in_box, out_box, broker, port) + : Prop(client_id, in_box, out_box, broker, port) { _client.setClient(_bridgeClient); } diff --git a/src/BridgeProp.h b/src/BridgeProp.h index 0e03a46..7daa622 100644 --- a/src/BridgeProp.h +++ b/src/BridgeProp.h @@ -1,11 +1,10 @@ /* Name: BridgeProp.h - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure - Class Props for Arduino Yun and Dragino Yun shield. + Prop for Arduino Yun and Dragino Yun shield. */ #ifndef BRIDGEPROP_H #define BRIDGEPROP_H @@ -14,7 +13,7 @@ #include #include "Prop.h" -class BridgeProp : public Props +class BridgeProp : public Prop { public: BridgeProp(const char*, const char*, const char*, const char*, const int); diff --git a/src/EthernetProp.cpp b/src/EthernetProp.cpp index 44eb589..4e0d076 100644 --- a/src/EthernetProp.cpp +++ b/src/EthernetProp.cpp @@ -1,17 +1,16 @@ /* Name: EthernetProp.cpp - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure - Class Props for Arduino with Ethernet shield. + Prop for Arduino with Ethernet shield. */ #include "EthernetProp.h" EthernetProp::EthernetProp(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port) - : Props(client_id, in_box, out_box, broker, port) + : Prop(client_id, in_box, out_box, broker, port) { _client.setClient(_ethernetClient); } diff --git a/src/EthernetProp.h b/src/EthernetProp.h index 2f9044c..5fa3142 100644 --- a/src/EthernetProp.h +++ b/src/EthernetProp.h @@ -1,11 +1,10 @@ /* Name: EthernetProp.h - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure - Class Props for Arduino with Ethernet shield. + Prop for Arduino with Ethernet shield. */ #ifndef ETHERNETPROP_H #define ETHERNETPROP_H @@ -16,7 +15,7 @@ #include #include "Prop.h" -class EthernetProp : public Props +class EthernetProp : public Prop { public: EthernetProp(const char*, const char*, const char*, const char*, const int); diff --git a/src/Prop.cpp b/src/Prop.cpp index 4e30049..fa6acf9 100644 --- a/src/Prop.cpp +++ b/src/Prop.cpp @@ -1,6 +1,5 @@ /* - Name: Props.cpp - Created: 29/10/2019 09:20:31 + Name: Prop.cpp Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure @@ -14,7 +13,7 @@ #include #endif -void PropsCallback::run(char* topic, byte* payload, unsigned int len) +void PropCallback::run(char* topic, byte* payload, unsigned int len) { if (len) { @@ -24,17 +23,17 @@ void PropsCallback::run(char* topic, byte* payload, unsigned int len) if (String(p) == "@PING") client->publish(outbox, "PONG"); else - Props::onInboxMessageReceived(p); + Prop::onInboxMessageReceived(p); free(p); } } -void PropsMessageReceived::run(String a) +void PropMessageReceived::run(String a) { client->publish(outbox, String("OMIT " + a).c_str()); } -Props::Props(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port) +Prop::Prop(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port) { clientId = client_id; inbox = in_box; @@ -43,27 +42,27 @@ Props::Props(const char* client_id, const char* in_box, const char* out_box, con _nextReconAttempt = 0; _dataSentCount = 0; _maximumSilentPeriod = 30; // 30 seconds - _payloadMax = MQTT_MAX_PACKET_SIZE - (1 + 2 + strlen(Props::outbox)); + _payloadMax = MQTT_MAX_PACKET_SIZE - (1 + 2 + strlen(Prop::outbox)); _brokerIpAddress.fromString(broker); _client.setServer(_brokerIpAddress, port); - PropsCallback::client = &_client; - PropsCallback::outbox = outbox; - _client.setCallback(PropsCallback::run); + PropCallback::client = &_client; + PropCallback::outbox = outbox; + _client.setCallback(PropCallback::run); - PropsMessageReceived::client = &_client; - PropsMessageReceived::outbox = outbox; + PropMessageReceived::client = &_client; + PropMessageReceived::outbox = outbox; _sendDataAction.reset(400); // check data changes every 400 milliseconds } -void Props::addData(PropData* d) +void Prop::addData(PropData* d) { _dataTable.Add(d); } -void Props::loop() +void Prop::loop() { if (_client.connected()) { @@ -84,7 +83,7 @@ void Props::loop() if (_sendDataAction.tick()) checkDataChanges(); // send data changes if any } -void Props::checkDataChanges() +void Prop::checkDataChanges() { if (_dataSentCount) { sendDataChanges(); @@ -98,7 +97,7 @@ void Props::checkDataChanges() if (_dataSentCount > (_maximumSilentPeriod * 1000 / _sendDataAction.getInterval())) _dataSentCount = 0; } -void Props::resetMcu() +void Prop::resetMcu() { #if defined(ARDUINO_ARCH_SAMD) NVIC_SystemReset(); @@ -108,7 +107,7 @@ void Props::resetMcu() #endif } -void Props::sendAllData() +void Prop::sendAllData() { String data("DATA "), str; for (int i = 0; i < _dataTable.Count(); i++) { @@ -121,7 +120,7 @@ void Props::sendAllData() } } -void Props::sendDataChanges() +void Prop::sendDataChanges() { String data("DATA "), str; for (int i = 0; i < _dataTable.Count(); i++) { @@ -134,7 +133,7 @@ void Props::sendDataChanges() } } -void Props::send(String* d, String* s) +void Prop::send(String* d, String* s) { if (d->length() + s->length() <= _payloadMax) { *d += *s; @@ -146,49 +145,49 @@ void Props::send(String* d, String* s) } } -void Props::sendData(String data) { +void Prop::sendData(String data) { if (data.length() > 5) { _client.publish(outbox, String("DATA " + data).c_str()); } } -void Props::sendDone(String action) { +void Prop::sendDone(String action) { _client.publish(outbox, String("DONE " + action).c_str()); } -void Props::sendMesg(String mesg) { +void Prop::sendMesg(String mesg) { if (mesg.length() > 5) { _client.publish(outbox, String("MESG " + mesg).c_str()); } } -void Props::sendMesg(String mesg, char *topic) { +void Prop::sendMesg(String mesg, char *topic) { if (mesg.length() > 5) { _client.publish(topic, String("MESG " + mesg).c_str()); } } -void Props::sendOmit(String action) { +void Prop::sendOmit(String action) { _client.publish(outbox, String("OMIT " + action).c_str()); } -void Props::sendOver(String challenge) { +void Prop::sendOver(String challenge) { _client.publish(outbox, String("OVER " + challenge).c_str()); } -void Props::sendProg(String program) { +void Prop::sendProg(String program) { _client.publish(outbox, String("PROG " + program).c_str()); } -void Props::sendRequ(String request) { +void Prop::sendRequ(String request) { _client.publish(outbox, String("REQU " + request).c_str()); } -void Props::sendRequ(String action, char* topic) { +void Prop::sendRequ(String action, char* topic) { _client.publish(topic, String("REQU " + action).c_str()); } -void Props::resetIntervals(const int changes, const int silent) +void Prop::resetIntervals(const int changes, const int silent) { _nextReconAttempt = 0; _dataSentCount = 0; @@ -197,8 +196,8 @@ void Props::resetIntervals(const int changes, const int silent) } -PubSubClient *PropsCallback::client; -const char *PropsCallback::outbox; -PubSubClient *PropsMessageReceived::client; -const char *PropsMessageReceived::outbox; -void (*Props::onInboxMessageReceived)(String) = PropsMessageReceived::run; +PubSubClient *PropCallback::client; +const char *PropCallback::outbox; +PubSubClient *PropMessageReceived::client; +const char *PropMessageReceived::outbox; +void (*Prop::onInboxMessageReceived)(String) = PropMessageReceived::run; diff --git a/src/Prop.h b/src/Prop.h index bceecf0..b5d9636 100644 --- a/src/Prop.h +++ b/src/Prop.h @@ -1,6 +1,5 @@ /* Name: Prop.h - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure @@ -26,7 +25,7 @@ #define MQTT_MAX_PACKET_SIZE 128 // Bridge tranfer stuff (see PubSubClient) #endif -class PropsCallback +class PropCallback { public: static PubSubClient *client; @@ -34,7 +33,7 @@ class PropsCallback static void run(char* topic, byte* payload, unsigned int len); }; -class PropsMessageReceived +class PropMessageReceived { public: static PubSubClient *client; @@ -42,16 +41,16 @@ class PropsMessageReceived static void run(String); }; -class InboxMessage : public PropsMessageReceived +class InboxMessage : public PropMessageReceived { public: static void run(String); // to be implemented in .ino sketch }; -class Props +class Prop { public: - Props(const char*, const char*, const char*, const char*, const int=1883); + Prop(const char*, const char*, const char*, const char*, const int=1883); virtual void begin(void(*)(String) = NULL) = 0; void addData(PropData*); void loop(); diff --git a/src/PropAction.cpp b/src/PropAction.cpp index 9ba792f..4caecf5 100644 --- a/src/PropAction.cpp +++ b/src/PropAction.cpp @@ -1,6 +1,5 @@ /* Name: PropAction.h - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure diff --git a/src/PropAction.h b/src/PropAction.h index 6f38bb1..3cc8738 100644 --- a/src/PropAction.h +++ b/src/PropAction.h @@ -1,6 +1,5 @@ /* Name: PropAction.h - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure @@ -8,8 +7,8 @@ Provide an easy way of triggering functions at a set interval. */ -#ifndef PROPSACTION_H -#define PROPSACTION_H +#ifndef PROPACTION_H +#define PROPACTION_H #if defined(ARDUINO) && ARDUINO >= 100 #include "arduino.h" @@ -17,7 +16,7 @@ #include "WProgram.h" #endif -class Props; +class Prop; class PropAction { diff --git a/src/PropData.cpp b/src/PropData.cpp index 071a8d0..ae53463 100644 --- a/src/PropData.cpp +++ b/src/PropData.cpp @@ -1,6 +1,5 @@ /* Name: PropData.cpp - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure diff --git a/src/PropData.h b/src/PropData.h index 555e45e..33a9a7e 100644 --- a/src/PropData.h +++ b/src/PropData.h @@ -1,14 +1,13 @@ /* Name: PropData.h - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure Variable wrapper for connected prop. */ -#ifndef PROPSDATA_H -#define PROPSDATA_H +#ifndef PROPDATA_H +#define PROPDATA_H #if defined(ARDUINO) && ARDUINO >= 100 #include "arduino.h" diff --git a/src/WifiProp.cpp b/src/WifiProp.cpp index 79f1cdc..c02e1bc 100644 --- a/src/WifiProp.cpp +++ b/src/WifiProp.cpp @@ -1,11 +1,10 @@ /* Name: WifiProp.cpp - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure - Class Props for Arduino with WiFiNINA. + Prop for Arduino with WiFiNINA. */ #include "WifiProp.h" @@ -15,7 +14,7 @@ WifiProp::WifiProp(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port) - : Props(client_id, in_box, out_box, broker, port) + : Prop(client_id, in_box, out_box, broker, port) { _client.setClient(_wifiClient); } diff --git a/src/WifiProp.h b/src/WifiProp.h index c67dbb3..202c4c6 100644 --- a/src/WifiProp.h +++ b/src/WifiProp.h @@ -1,11 +1,10 @@ /* Name: WifiProp.h - Created: 29/10/2019 09:20:31 Author: Marie Faure Editor: https://github.com/fauresystems License: MIT License (c) Marie Faure - Class Props for Arduino with WiFiNINA. + Prop for Arduino with WiFiNINA. */ #ifndef WIFIPROP_H #define WIFIPROP_H @@ -20,7 +19,7 @@ #include #include "Prop.h" -class WifiProp : public Props +class WifiProp : public Prop { public: WifiProp(const char*, const char*, const char*, const char*, const int);