summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-01-11 21:30:14 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2024-01-11 21:30:14 +0100
commit7e8ada78b865cb286fb178945d1339b1f21cd25b (patch)
tree6d8662af2a2ccc5be7eb553f857f2e6052656a39
parent3c8a52e9df6bbd08c1d66064ffdb2b51d883b2a2 (diff)
Show a plot of past 128 readings in the bottom half of the OLED
-rw-r--r--src/init.lua47
1 files changed, 31 insertions, 16 deletions
diff --git a/src/init.lua b/src/init.lua
index d2e8cef..8e81ca1 100644
--- a/src/init.lua
+++ b/src/init.lua
@@ -16,13 +16,16 @@ gpio.mode(ledpin, gpio.OUTPUT)
gpio.write(ledpin, 0)
ssd1306.init(128, 64)
-ssd1306.contrast(255)
+ssd1306.contrast(128)
fb.init(128, 64)
wifi_index = 1
no_wifi_count = 0
publish_count = 0
+past_pos = 1
+past = {}
+
-- cal 2023-01-06
-- 4.2V -> "4.36V" (raw ~ 948)
-- 4.0V -> "4.16V" (raw ~ 905)
@@ -68,22 +71,11 @@ function measure()
local co2, raw_temp, raw_humi = scd4x.read()
local bat_mv = get_battery_mv()
local bat_p = get_battery_percent(bat_mv)
- local line1 = ""
- local line2 = ""
- if co2 == nil then
- line1 = "SCD4x error"
- fb.print(fn, line1)
- ssd1306.show(fb.buf)
- return
- end
- line1 = string.format("%8d ppm\n", co2)
- line2 = string.format("%8d.%d c\n%8d.%d %%", raw_temp/65536 - 45, (raw_temp%65536)/6554, raw_humi/65536, (raw_humi%65536)/6554)
- fb.y = 16
- fb.print(fn, line1)
- fb.print(fn, line2)
- fb.draw_battery_8(114, 0, bat_p)
+
+ fb.draw_battery_8(0, 0, bat_p)
if have_wifi then
- fb.x = 100
+ fb.x = 96
+ fb.y = 16
fb.print(fn, string.format("%d", wifi.sta.getrssi()))
else
if no_wifi_count == 5 then
@@ -97,6 +89,29 @@ function measure()
connect_wifi()
end
end
+
+ fb.x = 0
+ fb.y = 16
+ if co2 == nil then
+ fb.print(fn, "SCD4x error")
+ ssd1306.show(fb.buf)
+ return
+ end
+ fb.x = 16
+ fb.print(fn, string.format("%5d ppm", co2))
+ fb.x = 16
+ fb.y = 0
+ fb.print(fn, string.format("%4d.%d c %3d.%d %%", raw_temp/65536 - 45, (raw_temp%65536)/6554, raw_humi/65536, (raw_humi%65536)/6554))
+
+ past[past_pos] = (co2 - 400) / 64
+ past[past_pos] = past[past_pos] >= 0 and past[past_pos] or 0
+ past[past_pos] = past[past_pos] <= 31 and past[past_pos] or 31
+ past_pos = (past_pos) % 128 + 1
+
+ for i = 1, 128 do
+ fb.buf[i * 2] = bit.lshift(1, 31 - (past[(past_pos + (i-2)) % 128 + 1] or 0))
+ end
+
ssd1306.show(fb.buf)
fb.init(128, 64)
publish_count = publish_count + 1