aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortcsullivan <tullivan99@gmail.com>2019-03-14 10:14:40 -0400
committertcsullivan <tullivan99@gmail.com>2019-03-14 10:14:40 -0400
commit31e115f7e72532fbfd456709e95d440e3be46fa1 (patch)
treee937395624efecf99eb4f58f1cd7f57d2efc7997
parentdd33956654589ded6644a75088e50069b1744ef9 (diff)
app communication working
-rwxr-xr-xsource/controller.cpp27
-rw-r--r--source/driverSharp.cpp10
-rw-r--r--source/driverSharp.h5
-rw-r--r--source/rtc.hpp4
4 files changed, 43 insertions, 3 deletions
diff --git a/source/controller.cpp b/source/controller.cpp
index bd316b5..fc1b70b 100755
--- a/source/controller.cpp
+++ b/source/controller.cpp
@@ -7,6 +7,8 @@
BLEUart bleuart;
+void handlePacket(void);
+
void app_error_handler_bare([[maybe_unused]] uint32_t error_code)
{
Serial.println("Received an error");
@@ -48,7 +50,30 @@ void setup(void)
void loop(void)
{
if (bleuart.available())
- Serial.print((char)bleuart.read());
+ handlePacket();
delay(10);
}
+
+void handlePacket(void)
+{
+ char buf[64];
+ char *p = buf;
+ do {
+ *p++ = bleuart.read();
+ } while (bleuart.available());
+ *p = '\0';
+
+ switch (buf[0]) {
+ case 'L':
+ Sharp::setMessage(buf + 1);
+ break;
+ case 'T':
+ Serial.println("Setting time!");
+ RTC::setTicks(std::atoi(buf + 1) * 60);
+ break;
+ default:
+ break;
+ }
+}
+
diff --git a/source/driverSharp.cpp b/source/driverSharp.cpp
index c68790e..4cdc6f1 100644
--- a/source/driverSharp.cpp
+++ b/source/driverSharp.cpp
@@ -8,6 +8,7 @@ constexpr unsigned int SHARP_SS = 14;
Adafruit_SharpMem Sharp::display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);
TaskHandle_t Sharp::taskHandle;
bool Sharp::holdRendering = false;
+char Sharp::message[16] = "";
#define BLACK 0
#define WHITE 1
@@ -33,8 +34,13 @@ void Sharp::updateTask([[maybe_unused]] void *arg)
if (auto t = RTC::ticks(); t != old) {
old = t;
- display.setCursor(0, 60);
- display.printf("%2d:%02d", t / 60, t % 60);
+ display.setCursor(0, 10);
+ display.printf("%2d:%02d:%02d", t / 3600, (t % 3600) /
+ 60, t % 60);
+ if (*message != '\0') {
+ display.setCursor(0, 100);
+ display.printf("%-16s", message);
+ }
display.refresh();
}
}
diff --git a/source/driverSharp.h b/source/driverSharp.h
index 799c828..986205b 100644
--- a/source/driverSharp.h
+++ b/source/driverSharp.h
@@ -5,6 +5,7 @@ private:
static Adafruit_SharpMem display;
static TaskHandle_t taskHandle;
static bool holdRendering;
+ static char message[16];
public:
static void begin(void);
@@ -17,6 +18,10 @@ public:
holdRendering = false;
}
+ inline static void setMessage(const char *s) {
+ strncpy(message, s, 16);
+ }
+
private:
static void updateTask(void *);
};
diff --git a/source/rtc.hpp b/source/rtc.hpp
index 1eb71a8..7f64100 100644
--- a/source/rtc.hpp
+++ b/source/rtc.hpp
@@ -12,6 +12,10 @@ public:
return rtcCount;
}
+ inline static void setTicks(unsigned int t) {
+ rtcCount = t;
+ }
+
private:
static void handler(nrf_drv_rtc_int_type_t type);
};