Show correct rssi strength on homescreen
parent
01d5c2dc5c
commit
02d3c1512b
1
boot.py
1
boot.py
|
@ -29,6 +29,7 @@ def any_home():
|
||||||
return h[0] if len(h) else False
|
return h[0] if len(h) else False
|
||||||
|
|
||||||
if "no_boot" in root:
|
if "no_boot" in root:
|
||||||
|
os.remove("no_boot")
|
||||||
print("no_boot found, aborting boot sequence")
|
print("no_boot found, aborting boot sequence")
|
||||||
elif "bootstrap.py" in root:
|
elif "bootstrap.py" in root:
|
||||||
print("Bootstrapping...")
|
print("Bootstrapping...")
|
||||||
|
|
|
@ -34,5 +34,12 @@ status = ugfx.Label(0, 130, ugfx.width(), 40, "") # , justification=ugfx.Label.C
|
||||||
|
|
||||||
# update loop
|
# update loop
|
||||||
while True:
|
while True:
|
||||||
status.text("wifi: %s%%\nbattery: %s%%" % (int(wifi_strength() * 100), int(battery() * 100)))
|
text = "";
|
||||||
|
value_wifi_strength = wifi_strength()
|
||||||
|
value_battery = battery()
|
||||||
|
if value_wifi_strength:
|
||||||
|
text += "wifi: %s%%\n" % int(value_wifi_strength)
|
||||||
|
if value_battery:
|
||||||
|
text += "battery: %s%%\n" % int(value_battery)
|
||||||
|
status.text(text)
|
||||||
sleep_or_exit(0.5)
|
sleep_or_exit(0.5)
|
||||||
|
|
|
@ -19,7 +19,7 @@ They also *may*:
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["database", "buttons", "random", "app", "sleep", "ugfx_helper", "wifi"]
|
___dependencies___ = ["database", "buttons", "random", "app", "sleep", "ugfx_helper", "wifi"]
|
||||||
|
|
||||||
import database, ugfx, random, buttons, tilda, sleep, ugfx_helper, wifi
|
import database, ugfx, random, buttons, tilda, sleep, ugfx_helper, wifi, time
|
||||||
from app import App
|
from app import App
|
||||||
|
|
||||||
_state = None
|
_state = None
|
||||||
|
@ -41,6 +41,12 @@ def set_state(key, value = True):
|
||||||
def clean_up():
|
def clean_up():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def time_as_string(seconds=False):
|
||||||
|
t = time.localtime()
|
||||||
|
if seconds:
|
||||||
|
return "%d:%02d:%02d" % (t[3], t[4], t[5])
|
||||||
|
return "%d:%02d" % (t[3], t[4]) #todo: add a setting for AM/PM mode
|
||||||
|
|
||||||
def sleep_or_exit(interval = 0.5):
|
def sleep_or_exit(interval = 0.5):
|
||||||
# todo: do this better - check button multiple times and sleep for only a short while
|
# todo: do this better - check button multiple times and sleep for only a short while
|
||||||
if buttons.is_triggered(tilda.Buttons.BTN_Menu):
|
if buttons.is_triggered(tilda.Buttons.BTN_Menu):
|
||||||
|
@ -52,9 +58,12 @@ def sleep_or_exit(interval = 0.5):
|
||||||
def name(default = None):
|
def name(default = None):
|
||||||
return database.get("homescreen.name", default)
|
return database.get("homescreen.name", default)
|
||||||
|
|
||||||
|
# Strength in %, None if unavailable
|
||||||
def wifi_strength():
|
def wifi_strength():
|
||||||
return random.random()
|
return wifi.get_strength()
|
||||||
|
|
||||||
|
# Charge in %, None if unavailable
|
||||||
def battery():
|
def battery():
|
||||||
return random.random()
|
return None # todo: fix me, we can get this from the sim800
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,19 +18,19 @@ class TestDialogs(unittest.TestCase):
|
||||||
def tearDownClass(self):
|
def tearDownClass(self):
|
||||||
ugfx_helper.deinit()
|
ugfx_helper.deinit()
|
||||||
|
|
||||||
# def test_waiting(self):
|
def test_waiting(self):
|
||||||
# count_max = 3
|
count_max = 3
|
||||||
# with WaitingMessage("Testing...", "Foo") as c:
|
with WaitingMessage("Testing...", "Foo") as c:
|
||||||
# for i in range(1, count_max):
|
for i in range(1, count_max):
|
||||||
# c.text = "%d/%d" % (i, count_max)
|
c.text = "%d/%d" % (i, count_max)
|
||||||
#
|
|
||||||
# print("done")
|
|
||||||
|
|
||||||
def test_(self):
|
print("done")
|
||||||
|
|
||||||
|
def test_text(self):
|
||||||
prompt_text("description")
|
prompt_text("description")
|
||||||
|
|
||||||
def test_option(self):
|
def test_option(self):
|
||||||
print(prompt_option(["foo", "bar", "baz"]))
|
print(prompt_option(["foo", "bar", "baz"]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
"""Tests for hall effect sensor"""
|
||||||
|
|
||||||
|
___license___ = "MIT"
|
||||||
|
___dependencies___ = ["upip:unittest", "homescreen", "database"]
|
||||||
|
|
||||||
|
import unittest, homescreen, database
|
||||||
|
|
||||||
|
class TestHomescreen(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_name(self):
|
||||||
|
o = database.get("homescreen.name")
|
||||||
|
database.delete("homescreen.name")
|
||||||
|
self.assertEqual(homescreen.name("default"), "default")
|
||||||
|
database.set("homescreen.name", "foo")
|
||||||
|
self.assertEqual(homescreen.name("default"), "foo")
|
||||||
|
database.set("homescreen.name", o)
|
||||||
|
|
||||||
|
def test_time(self):
|
||||||
|
self.assertIn(len(homescreen.time_as_string()), [4, 5])
|
||||||
|
self.assertIn(len(homescreen.time_as_string(True)), [7, 8])
|
||||||
|
|
||||||
|
def test_wifi_strength(self):
|
||||||
|
# test that it doesn't throw an exception
|
||||||
|
homescreen.wifi_strength()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
10
lib/wifi.py
10
lib/wifi.py
|
@ -87,12 +87,16 @@ def connect_wifi(details, timeout, wait=False):
|
||||||
def is_connected():
|
def is_connected():
|
||||||
return nic().isconnected()
|
return nic().isconnected()
|
||||||
|
|
||||||
|
# returns wifi strength in %, None if unavailable
|
||||||
def get_strength():
|
def get_strength():
|
||||||
n = nic()
|
n = nic()
|
||||||
if n.isconnected():
|
if n.isconnected():
|
||||||
r
|
v = n.status("rssi");
|
||||||
else:
|
if v:
|
||||||
return None
|
# linear range: -60 =100%; -100= 20%
|
||||||
|
# todo: it's probably not linear, improve me.
|
||||||
|
return v * 2 + 220
|
||||||
|
return None
|
||||||
|
|
||||||
def get_security_level(ap):
|
def get_security_level(ap):
|
||||||
#todo: fix this
|
#todo: fix this
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
___name___ = "Sponsors"
|
___name___ = "Sponsors"
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["wifi", "http", "ugfx_helper", "sleep"]
|
___dependencies___ = ["wifi", "http", "ugfx_helper", "sleep", "app"]
|
||||||
___categories___ = ["EMF"]
|
___categories___ = ["EMF"]
|
||||||
___bootstrapped___ = True
|
___bootstrapped___ = True
|
||||||
|
|
||||||
import ugfx_helper, os, wifi, ugfx, http, time, sleep
|
import ugfx_helper, os, wifi, ugfx, http, time, sleep, app
|
||||||
from tilda import Buttons
|
from tilda import Buttons
|
||||||
|
|
||||||
ugfx_helper.init()
|
ugfx_helper.init()
|
||||||
|
@ -24,3 +24,4 @@ while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed(Button
|
||||||
sleep.wfi()
|
sleep.wfi()
|
||||||
|
|
||||||
ugfx.clear()
|
ugfx.clear()
|
||||||
|
app.restart_to_default()
|
||||||
|
|
Loading…
Reference in New Issue