summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2015-11-12 12:20:30 -0600
committerMike Fiore <mfiore@multitech.com>2015-11-12 12:20:30 -0600
commitf0f9fc2601dc3421aa3f4d9747748c3bee93f703 (patch)
tree3d884e151729be7fec59af504cb4dfadf31276ac /main.cpp
parent0bc27ddeae03930deb6106144b49e0614fe002da (diff)
downloadmtdot-box-evb-factory-firmware-f0f9fc2601dc3421aa3f4d9747748c3bee93f703.tar.gz
mtdot-box-evb-factory-firmware-f0f9fc2601dc3421aa3f4d9747748c3bee93f703.tar.bz2
mtdot-box-evb-factory-firmware-f0f9fc2601dc3421aa3f4d9747748c3bee93f703.zip
add class for handling button events - signals main thread when event occurs and main thread can check event - supports SW1 press, SW2 press, and SW1 hold
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/main.cpp b/main.cpp
index 2bf100d..5049cc2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -13,9 +13,14 @@
#include "DOGS102.h"
#include "NCP5623B.h"
#include "LayoutStartup.h"
+// button header
+#include "ButtonHandler.h"
// misc heders
#include <string>
+// only here for button handling example code in main
+#include "font_6x8.h"
+
// LCD and backlight controllers
SPI lcd_spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK);
I2C backlight_i2c(I2C_SDA, I2C_SCL);
@@ -24,6 +29,9 @@ DigitalOut lcd_cd(XBEE_ON_SLEEP, 1);
DOGS102* lcd;
NCP5623B* lcd_backlight;
+// Button controller
+ButtonHandler* buttons;
+
// Serial debug port
Serial debug(USBTX, USBRX);
@@ -33,14 +41,39 @@ int main() {
lcd = new DOGS102(lcd_spi, lcd_spi_cs, lcd_cd);
lcd_backlight = new NCP5623B(backlight_i2c);
- logInfo("starting...");
+ // display startup screen for 3 seconds
LayoutStartup ls(lcd);
ls.display();
+ osDelay(3000);
+
+ osThreadId main_id = Thread::gettid();
+ buttons = new ButtonHandler(main_id);
while (true) {
- logInfo("in loop");
- osDelay(5000);
+ char buf[16];
+ size_t size;
+
+ osEvent e = Thread::signal_wait(buttonSignal);
+ if (e.status == osEventSignal) {
+ ButtonEvent ev = buttons->getButtonEvent();
+ switch (ev) {
+ case sw1_press:
+ size = snprintf(buf, sizeof(buf), "SW1 press");
+ break;
+ case sw1_hold:
+ size = snprintf(buf, sizeof(buf), "SW1 hold");
+ break;
+ case sw2_press:
+ size = snprintf(buf, sizeof(buf), "SW2 press");
+ break;
+ }
+
+ lcd->clearBuffer();
+ lcd->startUpdate();
+ lcd->writeText(0, 0, font_6x8, buf, size);
+ lcd->endUpdate();
+ }
}
return 0;