diff options
author | 2019-05-12 17:18:22 +0300 | |
---|---|---|
committer | 2019-05-12 17:40:31 +0300 | |
commit | 6246a3f7f7ac3d76f95b4296dea48f4e1b098888 (patch) | |
tree | ec38ed39c125c833db3acae4cc632f4c9b05e76a /src/device/main.ino | |
parent | d51604d94e66d400376091aa2a735a238bb74f20 (diff) | |
download | usurpation-6246a3f7f7ac3d76f95b4296dea48f4e1b098888.tar.gz usurpation-6246a3f7f7ac3d76f95b4296dea48f4e1b098888.tar.bz2 usurpation-6246a3f7f7ac3d76f95b4296dea48f4e1b098888.zip |
device: Device prints first meaningful data.
Device prints its own IP address and that of server daemon.
This commit is part of ticket #28.
Signed-off-by: Ramūnas Mažeikis <ramunasnezinomas@gmail.com>
Diffstat (limited to 'src/device/main.ino')
-rw-r--r-- | src/device/main.ino | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/device/main.ino b/src/device/main.ino index 7e1cd54..77d4d28 100644 --- a/src/device/main.ino +++ b/src/device/main.ino @@ -25,6 +25,7 @@ #include <stdlib.h> #include <stddef.h> #include "SSD1306Wire.h" +#include "DejaVu_Sans_Mono_13.h" static char udppacketbuffer[32] = {0}; static char *udppacketcursor = NULL; @@ -33,7 +34,7 @@ static unsigned int led_state = 0; static const char servermagic[] = "I love coffee!"; static const char clientmagic[] = "I love tea!"; static const int com_port = 6996; -IPAddress ip; +IPAddress ip; /* Daemon IP */ WiFiUDP Udp; SSD1306Wire display(0x3c, 4, 5, GEOMETRY_128_32); @@ -51,6 +52,7 @@ void setup(void) extern const char * const ssid; extern const char * const password; pinMode(internal_led, OUTPUT); + toggle_led(internal_led); init_OLED(); display.fillCircle(32, 16, 12); @@ -67,32 +69,41 @@ void setup(void) /* the logic is a placeholder right now */ void loop(void) { - /* sleep length to use */ - static unsigned int delta = 2000; - static int dot_idx = 0; + static const String devstr = "Device IP:"; + static const String daemonstr = "Daemon IP:"; + static String prefix; + static IPAddress ip_to_print; + int print_dev_ip = 0; + + static unsigned int delta = 2000; /* sleep length to use */ + /* static int dot_idx = 0; */ + delay(delta); udp_init_packet(ip, com_port); udp_push(clientmagic, sizeof(clientmagic)); udp_flush(); - +#if 0 if (dot_idx >= 2) { display.clear(); dot_idx = 0; } display.fillCircle(32 * (dot_idx + 1), 16, 12); dot_idx++; +#endif + prefix = (print_dev_ip) ? devstr : daemonstr; + ip_to_print = (print_dev_ip) ? ip : WiFi.localIP(); + display.drawString(4, 4, prefix); + display.drawString(24, 24, ip_to_print.toString()); + display.display(); + print_dev_ip != print_dev_ip; } static void init_OLED(void) { display.init(); display.flipScreenVertically(); - - /* Won't be useful until later on. */ - /* display.setTextAlignment(TEXT_ALIGN_LEFT); - display.setFont(DejaVu_Sans_28); - */ + display.setFont((uint8_t *)DejaVu_Sans_Mono_13); } /* toggle the bult-in led and return current state */ |