EMF_Camp_Badge/sms/main.py

52 lines
1.3 KiB
Python
Raw Normal View History

2018-08-28 18:12:57 -04:00
"""SMS app for reading and sending messages
"""
2018-08-28 18:35:45 -04:00
___name___ = "Phone"
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:
num = prompt_text("Number to message:", init_text=number)
if num is None:
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")
if (selection["index"]==-1):
send_message()
elif (selection):
message = sim800.readsms(selection["index"])
notice(message, title=selection["title"])
else:
break
restart_to_default()