cellular: First version, shows operator name and registration state

This commit is contained in:
Pavel Machek
2026-03-07 23:50:35 +01:00
parent d3e90c5bb4
commit 89bb472364
3 changed files with 127 additions and 0 deletions
@@ -0,0 +1,24 @@
{
"name": "Xxx",
"publisher": "Pavel Machek",
"short_description": "Xxx",
"long_description": "Simple xxx app.",
"icon_url": "https://apps.micropythonos.com/apps/cz.ucw.pavel.xxx/icons/cz.ucw.pavel.xxx_0.0.1_64x64.png",
"download_url": "https://apps.micropythonos.com/apps/cz.ucw.pavel.xxx/mpks/cz.ucw.pavel.xxx_0.0.1.mpk",
"fullname": "cz.ucw.pavel.xxx",
"version": "0.0.1",
"category": "utilities",
"activities": [
{
"entrypoint": "assets/main.py",
"classname": "Main",
"intent_filters": [
{
"action": "main",
"category": "launcher"
}
]
}
]
}
@@ -0,0 +1,103 @@
from mpos import Activity
"""
"""
import time
import os
import json
try:
import lvgl as lv
except ImportError:
pass
from mpos import Activity, MposKeyboard
TMP = "/tmp/cmd.json"
def run_cmd_json(cmd):
rc = os.system(cmd + " > " + TMP)
if rc != 0:
raise RuntimeError("command failed")
with open(TMP, "r") as f:
data = f.read().strip()
return json.loads(data)
def dbus_json(cmd):
return run_cmd_json("sudo /home/mobian/g/MicroPythonOS/phone.py " + cmd)
class CellularManager:
def init(self):
v = dbus_json("loc_on")
def poll(self):
v = dbus_json("signal")
print(v)
self.signal = v
cm = CellularManager()
# ------------------------------------------------------------
#
# ------------------------------------------------------------
class Main(Activity):
def __init__(self):
super().__init__()
# --------------------
def onCreate(self):
self.screen = lv.obj()
#self.screen.remove_flag(lv.obj.FLAG.SCROLLABLE)
# Top labels
self.lbl_time = lv.label(self.screen)
self.lbl_time.set_style_text_font(lv.font_montserrat_24, 0)
self.lbl_time.set_text("Startup...")
self.lbl_time.align(lv.ALIGN.TOP_LEFT, 6, 22)
self.lbl_date = lv.label(self.screen)
self.lbl_date.align(lv.ALIGN.TOP_LEFT, 6, 48)
self.lbl_month = lv.label(self.screen)
self.lbl_month.align(lv.ALIGN.TOP_RIGHT, -6, 10)
self.setContentView(self.screen)
cm.init()
def onResume(self, screen):
self.timer = lv.timer_create(self.tick, 3000, None)
self.tick(0)
def onPause(self, screen):
if self.timer:
self.timer.delete()
self.timer = None
# --------------------
def tick(self, t):
now = time.localtime()
y, m, d = now[0], now[1], now[2]
hh, mm, ss = now[3], now[4], now[5]
cm.poll()
s = "\n"
s += cm.signal["OperatorName"] + "\n"
s += "RegistrationState %d\n" % cm.signal["RegistrationState"]
s += "State %d\n" % cm.signal["State"]
self.lbl_time.set_text("%02d:%02d" % (hh, mm))
self.lbl_date.set_text("%04d-%02d-%02d %s" % (y, m, d, s))
# --------------------
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB