123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- #include <HardwareSerial.h>
- #include <Preferences.h>
- #include <WiFi.h>
- #include <MacroDebugger.h>
- #include "WS_Bluetooth.h"
- #include "WS_GPIO.h"
- //#define ENABLE_DEBUG /* <-- Commenting this line will remove any trace of debug printing */
- /******************************************************** Data Analysis ********************************************************/
- unsigned long timers[6] = { 0, 0, 0, 0, 0, 0 };
- bool isOverride = false;
- Preferences preferences;
- String macAddress;
- String devicename;
- String equipmentid;
- String warningnotice;
- String contactinfo;
- bool btConnected;
- void Restart()
- {
- ESP.restart();
- }
- void Configure(String name, String warning, String contact, String id)
- {
- preferences.begin("prs-digital-key", false);
- devicename = name;
- preferences.putString("device-name", name.c_str());
- warningnotice = warning;
- preferences.putString("warning-notice", warning.c_str());
- contactinfo = contact;
- preferences.putString("contact-info", contact.c_str());
- equipmentid = id;
- preferences.putString("id", id.c_str());
- preferences.end();
- }
- String GetMacAddress()
- {
- return macAddress;
- }
- String GetDeviceName()
- {
- return devicename;
- }
- String GetWarningNotice()
- {
- return warningnotice;
- }
- String GetContactInfo()
- {
- return contactinfo;
- }
- String GetEquipmentId()
- {
- return equipmentid;
- }
- void SetRelay(int relay, long time)
- {
- if (time < 0L)
- {
- TriggerRelay(relay,true);
- timers[relay] = 0;
-
- }
- else if (time==0L)
- {
- TriggerRelay(relay,false);
- timers[relay] = 0;
- }
- else
- {
- TriggerRelay(relay,true);
- timers[relay] = millis() + time;
- }
- }
- bool GetRelay(int relay)
- {
- return RelayStatus(relay);
- }
- int i = 0;
- /******************************************************** Initializing ********************************************************/
- void setup()
- {
- DEBUG_BEGIN();
-
- WiFi.mode(WIFI_STA);
- macAddress = WiFi.macAddress().c_str();
- preferences.begin("prs-digital-key", true);
-
- devicename = preferences.getString("device-name","PRS Digital Key");
- warningnotice = preferences.getString("warning-notice","(No information available)");
- contactinfo = preferences.getString("contact-info","(Not available)");
- equipmentid = preferences.getString("id","00000000-0000-0000-0000-000000000000");
- preferences.end();
- GPIO_Init();
-
- Bluetooth_Init();
- }
- /********************************************************** While **********************************************************/
- void loop()
- {
-
- if (btConnected && !IsConnected())
- {
- RGB_Light(0, 0, 0);
- btConnected = false;
- } else if (!btConnected && IsConnected())
- {
- RGB_Light(0, 0, 60);
- btConnected = true;
- }
- unsigned long ms = millis();
- bool bChanged = false;
- for (int relay=0; relay<6; relay++)
- {
- if ((timers[relay] > 0L) && (timers[relay] <= ms))
- {
- SetRelay(relay,0L);
- bChanged = true;
- }
- }
- if (bChanged && !IsConnected())
- UpdateAdvertising();
- }
|