keypad class
This commit is contained in:
45
src/main.cpp
45
src/main.cpp
@@ -17,6 +17,7 @@
|
||||
static WiFiUDP ntpUDP;
|
||||
static NTPClient timeClient(ntpUDP);
|
||||
static MQTT *mqtt;
|
||||
static Keypad *keypad;
|
||||
|
||||
static bool is_disarmed = false;
|
||||
|
||||
@@ -28,13 +29,13 @@ void mqtt_callback(char *topic, byte *payload, unsigned int length)
|
||||
String state((const char *)payload);
|
||||
is_disarmed = state == "disarmed";
|
||||
|
||||
Serial.println(state);
|
||||
keypad_write(state);
|
||||
}
|
||||
if (state == "armed_away")
|
||||
{
|
||||
keypad->draw();
|
||||
}
|
||||
|
||||
void setupTime()
|
||||
{
|
||||
timeClient.begin();
|
||||
Serial.println(state);
|
||||
keypad->write(state);
|
||||
}
|
||||
|
||||
void lock()
|
||||
@@ -55,18 +56,18 @@ void initWifi(Settings *settings)
|
||||
{
|
||||
if (!settings)
|
||||
{
|
||||
keypad_write("no settings");
|
||||
keypad->write("no settings");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isConnecting)
|
||||
{
|
||||
keypad_write("already connecting");
|
||||
keypad->write("already connecting");
|
||||
return;
|
||||
}
|
||||
|
||||
isConnecting = true;
|
||||
keypad_write("connecting");
|
||||
keypad->write("connecting");
|
||||
|
||||
WiFi.begin(settings->gettext("wifi:ssid"), settings->gettext("wifi:password"));
|
||||
|
||||
@@ -88,11 +89,11 @@ void initWifi(Settings *settings)
|
||||
Serial.print("Local IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
isConnecting = false;
|
||||
keypad_write("connected");
|
||||
keypad->write("connected");
|
||||
}
|
||||
else
|
||||
{
|
||||
keypad_write("failed to connect");
|
||||
keypad->write("failed to connect");
|
||||
isConnecting = false;
|
||||
return;
|
||||
}
|
||||
@@ -115,14 +116,14 @@ void setup()
|
||||
{
|
||||
M5.begin();
|
||||
|
||||
keypad_init();
|
||||
keypad_write("loading");
|
||||
keypad = new Keypad();
|
||||
keypad->write("loading");
|
||||
|
||||
auto settings = new Settings();
|
||||
|
||||
if (!settings)
|
||||
{
|
||||
keypad_write("unable to load settings");
|
||||
keypad->write("unable to load settings");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -130,7 +131,7 @@ void setup()
|
||||
|
||||
initWifi(settings);
|
||||
mqtt->connect();
|
||||
setupTime();
|
||||
timeClient.begin();
|
||||
initTOTP(settings);
|
||||
}
|
||||
|
||||
@@ -148,24 +149,12 @@ void submit(String code)
|
||||
lock();
|
||||
}
|
||||
|
||||
// unsigned long lastBtnPressed = millis();
|
||||
// void checkForButton()
|
||||
// {
|
||||
// M5.BtnP.read();
|
||||
// if (M5.BtnP.isPressed() && millis() - lastBtnPressed > 1000)
|
||||
// {
|
||||
// lastBtnPressed = millis(); // try and debouce, not really working i guess
|
||||
// initWifi();
|
||||
// }
|
||||
// }
|
||||
|
||||
void loop()
|
||||
{
|
||||
timeClient.update();
|
||||
mqtt->loop();
|
||||
|
||||
// checkForButton();
|
||||
auto value = keypad_loop();
|
||||
auto value = keypad->get_input();
|
||||
if (value.has_value())
|
||||
submit(value.value());
|
||||
}
|
||||
|
Reference in New Issue
Block a user