EMF_Camp_Badge/sms/main.py

58 lines
1.6 KiB
Python
Raw Normal View History

2018-08-28 18:12:57 -04:00
"""SMS app for reading and sending messages
"""
2018-09-03 09:59:37 -04:00
___title___ = "SMS"
2018-08-28 18:12:57 -04:00
___license___ = "MIT"
2018-08-28 18:35:45 -04:00
___dependencies___ = ["app", "dialogs", "sim800", "ugfx_helper"]
2018-08-28 18:12:57 -04:00
___categories___ = ["System"]
___bootstrapped___ = True
from app import *
from dialogs import *
2018-08-28 18:35:45 -04:00
import ugfx
import ugfx_helper
import sim800
2018-08-28 18:12:57 -04:00
sim800.poweron()
2018-08-28 18:12:57 -04:00
ugfx_helper.init()
ugfx.clear()
menuset = []
messages = sim800.listsms(4)
2018-08-29 14:58:04 -04:00
def send_message():
number = ""
message = ""
while True:
number = prompt_text("Number to message:", init_text=number, numeric=True)
2018-09-01 11:34:56 -04:00
if number is None:
2018-08-29 14:58:04 -04:00
return
message = prompt_text("Message:", init_text=message)
if message is not None:
if sim800.sendsms(number, message):
return
2018-08-28 18:12:57 -04:00
for message in messages:
splitmessage = message.split(",")
menuset.insert(0, { "title" : splitmessage[5] + " " + splitmessage[4] + " from " + splitmessage[2], "index" : splitmessage[0] })
2018-08-29 14:58:04 -04:00
menuset.insert(0, { "title" : "Send message...", "index" : -1 })
2018-08-28 18:12:57 -04:00
while True:
2018-08-29 14:58:04 -04:00
selection = prompt_option(menuset, text="Select message", select_text="Read", none_text="Exit")
2018-08-31 12:43:14 -04:00
if (selection):
if (selection["index"]==-1):
send_message()
else:
message = sim800.readsms(selection["index"])
notice(message, title=selection["title"])
2018-08-31 13:18:52 -04:00
if prompt_boolean("Delete this message?", title=selection["title"]):
sim800.deletesms(selection["index"])
for menuitem in menuset:
if menuitem["index"]==selection["index"]:
menuset.remove(menuitem)
2018-08-29 14:58:04 -04:00
else:
break
restart_to_default()