Show correct rssi strength on homescreen

andrejusk/bday
Marek Ventur 2018-08-31 14:22:55 +01:00
parent 01d5c2dc5c
commit 02d3c1512b
7 changed files with 67 additions and 18 deletions

View File

@ -29,6 +29,7 @@ def any_home():
return h[0] if len(h) else False
if "no_boot" in root:
os.remove("no_boot")
print("no_boot found, aborting boot sequence")
elif "bootstrap.py" in root:
print("Bootstrapping...")

View File

@ -34,5 +34,12 @@ status = ugfx.Label(0, 130, ugfx.width(), 40, "") # , justification=ugfx.Label.C
# update loop
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)

View File

@ -19,7 +19,7 @@ They also *may*:
___license___ = "MIT"
___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
_state = None
@ -41,6 +41,12 @@ def set_state(key, value = True):
def clean_up():
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):
# todo: do this better - check button multiple times and sleep for only a short while
if buttons.is_triggered(tilda.Buttons.BTN_Menu):
@ -52,9 +58,12 @@ def sleep_or_exit(interval = 0.5):
def name(default = None):
return database.get("homescreen.name", default)
# Strength in %, None if unavailable
def wifi_strength():
return random.random()
return wifi.get_strength()
# Charge in %, None if unavailable
def battery():
return random.random()
return None # todo: fix me, we can get this from the sim800

View File

@ -18,15 +18,15 @@ class TestDialogs(unittest.TestCase):
def tearDownClass(self):
ugfx_helper.deinit()
# def test_waiting(self):
# count_max = 3
# with WaitingMessage("Testing...", "Foo") as c:
# for i in range(1, count_max):
# c.text = "%d/%d" % (i, count_max)
#
# print("done")
def test_waiting(self):
count_max = 3
with WaitingMessage("Testing...", "Foo") as c:
for i in range(1, count_max):
c.text = "%d/%d" % (i, count_max)
def test_(self):
print("done")
def test_text(self):
prompt_text("description")
def test_option(self):

27
lib/test_homescreen.py Normal file
View File

@ -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()

View File

@ -87,11 +87,15 @@ def connect_wifi(details, timeout, wait=False):
def is_connected():
return nic().isconnected()
# returns wifi strength in %, None if unavailable
def get_strength():
n = nic()
if n.isconnected():
r
else:
v = n.status("rssi");
if v:
# 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):

View File

@ -2,11 +2,11 @@
___name___ = "Sponsors"
___license___ = "MIT"
___dependencies___ = ["wifi", "http", "ugfx_helper", "sleep"]
___dependencies___ = ["wifi", "http", "ugfx_helper", "sleep", "app"]
___categories___ = ["EMF"]
___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
ugfx_helper.init()
@ -24,3 +24,4 @@ while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed(Button
sleep.wfi()
ugfx.clear()
app.restart_to_default()