summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/common/tlv.c2
-rw-r--r--src/device/device_network.cpp6
-rw-r--r--src/device/main.ino8
-rw-r--r--src/device/screen.cpp9
4 files changed, 12 insertions, 13 deletions
diff --git a/src/common/tlv.c b/src/common/tlv.c
index bf8a99c..84b20ca 100755
--- a/src/common/tlv.c
+++ b/src/common/tlv.c
@@ -88,7 +88,7 @@ int tlv_pack(struct tlv_packet *pack, struct tlv *tlv)
/* packed tlv loses the pointer, so only take the header part into account */
raw_size = sizeof(tlv->head) + tlv->head.size;
- if ((raw_size + pack->cursor + sizeof(tlv->head)) >= TLV_SZ_MAX) {
+ if ((raw_size + pack->cursor + tlv->head.type ? sizeof(tlv->head) : 0) >= TLV_SZ_MAX) {
ret = ERROR;
} else {
if (pack->size < pack->cursor + raw_size) {
diff --git a/src/device/device_network.cpp b/src/device/device_network.cpp
index 1810852..e526519 100644
--- a/src/device/device_network.cpp
+++ b/src/device/device_network.cpp
@@ -63,10 +63,8 @@ int udp_flush(void)
size_t udp_get_data(char *buf, size_t size)
{
size_t ret;
- if (state.udp.available() != 0) {
- ret = state.udp.read(buf, size);
- } else {
- ret = 0;
+ if ((ret = state.udp.available())) {
+ state.udp.read(buf, size);
}
return ret;
}
diff --git a/src/device/main.ino b/src/device/main.ino
index 0835906..bfd365a 100644
--- a/src/device/main.ino
+++ b/src/device/main.ino
@@ -33,6 +33,7 @@
static const unsigned int internal_led = 2;
static unsigned int led_state = 0;
+static char *fugg = "O Fugg, ids an errror :DDDDD";
SSD1306Wire display(0x3c, 4, 5, GEOMETRY_128_32);
static void init_OLED(void);
@@ -77,6 +78,7 @@ void setup(void)
tlv_pack(&progstate.heartbeat, &field);
tlv_packet_finalize(&progstate.heartbeat);
tlv_destroy(&field);
+ display_status_init(&display, &progstate.ds, fugg);
}
void loop(void)
@@ -107,7 +109,7 @@ void loop(void)
}
prefix = (progstate.ip_print_count % 2) ? devstr : daemonstr;
- ip_to_print = (progstate.ip_print_count) ? WiFi.localIP() : *daemon_ip;
+ ip_to_print = (progstate.ip_print_count % 2) ? WiFi.localIP() : *daemon_ip;
display.clear();
display.drawString(0, 0, prefix);
display.drawString(0, 16, ip_to_print.toString());
@@ -135,6 +137,7 @@ void loop(void)
void handle_tlv(const struct tlv *in)
{
+ static char *fugg = "O Fugg, ids an errror :DDDDD";
/* Currently just dealing with text.
* */
switch (in->head.type) {
@@ -142,8 +145,7 @@ void handle_tlv(const struct tlv *in)
display_status_init(&display, &progstate.ds, in->data);
break;
default:
- display.clear();
- display.drawString(0, 0, "Fugg :DDD");
+ display_status_init(&display, &progstate.ds, fugg);
break;
}
}
diff --git a/src/device/screen.cpp b/src/device/screen.cpp
index 8504ef2..076640f 100644
--- a/src/device/screen.cpp
+++ b/src/device/screen.cpp
@@ -9,8 +9,7 @@ void draw_lines(OLEDDisplay *screen, struct display_status *status);
void update_lines(struct display_status *status);
void init_msg(char *msg, size_t size);
-/* Effectively const. For type safety reasons. */
-static char NOTHING[] = {'\0'};
+static char empty_string[] = "";
void display_status_init(OLEDDisplay *screen, struct display_status *status, char *msg)
{
@@ -58,7 +57,7 @@ int display_update_scroll(struct display_status *status)
update_lines(status);
draw_lines(status->screen, status);
}
- if (status->first_line == NOTHING && status->second_line == NOTHING) {
+ if (!(*status->first_line) && !(*(status->second_line))) {
return END_OF_MESSAGE;
} else {
return 0;
@@ -77,8 +76,8 @@ void update_lines(struct display_status *status)
{
status->first_line = (status->line_cursor * SCREEN_MAX_CHARS < status->message_len)
? status->message + status->line_cursor * SCREEN_MAX_CHARS
- : NOTHING;
+ : empty_string;
status->second_line = (status->line_cursor * SCREEN_MAX_CHARS < status->message_len)
? status->message + (status->line_cursor + 1) * SCREEN_MAX_CHARS
- : NOTHING;
+ : empty_string;
}