From 6246a3f7f7ac3d76f95b4296dea48f4e1b098888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Sun, 12 May 2019 17:18:22 +0300 Subject: device: Device prints first meaningful data. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/device/main.ino | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src/device/main.ino') 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 #include #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 */ -- cgit v1.2.3