diff --git a/lib/sim800.py b/lib/sim800.py index 983e63e..518ad86 100644 --- a/lib/sim800.py +++ b/lib/sim800.py @@ -29,6 +29,7 @@ callbacks = [] # Globals for remembering callback data clip = "" btpairing = '' +holdoffirq=False # Check if the SIM800 is powered up def ison(): @@ -119,6 +120,9 @@ def processbuffer(): # The same interface as and called by command() but without power so can be called from power() def command_internal(command="AT", response_timeout=default_response_timeout, required_response=None, custom_endofdata=None): global dirtybuffer + global holdoffirq + # Don't let the interupt process the buffer mid command + holdoffirq = True # Process anything remaining in the buffer processbuffer() # Send the command @@ -142,12 +146,14 @@ def command_internal(command="AT", response_timeout=default_response_timeout, re customcomplete = True # Check if we are done if complete and customcomplete: + holdoffirq = False return result # We ran out of time # set the dirty buffer flag is an out of date end of responcs cound end up in the buffer if required_response is None: dirtybuffer = True result.append("TIMEOUT") + holdoffirq = False return result # Send the command to set the default configuration to the SIM800 @@ -174,7 +180,7 @@ def power(onoroff, asyncro): if not asyncro and pwr_key_pin.value(): pwr_key_pin.off() time.sleep(3) - # Press the virtual power key if we are off + # Press the virtual power key if we are off if not (ison()==onoroff): pwr_key_pin.on() if not asyncro: @@ -217,7 +223,8 @@ def netlightscheduled_internal(pinstate): if pwr_key_pin.value() and ison(): poweron() # Check for incomming commands - processbuffer() + if holdoffirq==False: + processbuffer() # Netlight IRQ (called for polling uart) def netlightirq_internal(pinstate): @@ -669,6 +676,8 @@ def btsppwrite(connection, data): # Receive data from a Bluetooth serial connection def btsppread(connection): command() + # Don't let the interupt process the buffer mid command + holdoffirq = True request = "AT+BTSPPGET=3," + str(connection) + "\n" uart.write(request) data = uart.read() @@ -677,6 +686,7 @@ def btsppread(connection): if uart.any()==0: break data += uart.read() + holdoffirq = False if not data.endswith("ERROR\r\n"): return data[len(request)+2:-6] else: @@ -770,6 +780,8 @@ def fscreate(filename): def fsreadpart(filename, size=256, start=0): mode=int(start>0) command() + # Don't let the interupt process the buffer mid command + holdoffirq = True request = "AT+FSREAD=" + str(filename) + "," + str(mode) + "," + str(size) + "," + str(start) + "\n" uart.write(request) data = uart.read() @@ -778,6 +790,7 @@ def fsreadpart(filename, size=256, start=0): if uart.any()==0: break data += uart.read() + holdoffirq = False if not data.endswith("ERROR\r\n"): return data[len(request)+2:-6] else: diff --git a/phone/external.py b/phone/external.py new file mode 100644 index 0000000..6104659 --- /dev/null +++ b/phone/external.py @@ -0,0 +1,4 @@ +"""Load the SIM800 library at start so it starts in the background while turning on +""" + +import sim800 diff --git a/phone/main.py b/phone/main.py new file mode 100644 index 0000000..d2fe6e5 --- /dev/null +++ b/phone/main.py @@ -0,0 +1,21 @@ +"""Phone app for baic calling functions +""" +___name___ = "Phone" +___license___ = "MIT" +___dependencies___ = ["app", "dialogs", "sim800", "ugfx_helper"] +___categories___ = ["System"] +___bootstrapped___ = True + +from app import * +from dialogs import * +import ugfx +import ugfx_helper +import sim800 + +ugfx_helper.init() +ugfx.clear() + +notocall = prompt_text("Number to call:") + +if (notocall): + sim800.call(notocall) diff --git a/sms/main.py b/sms/main.py new file mode 100644 index 0000000..39c042b --- /dev/null +++ b/sms/main.py @@ -0,0 +1,31 @@ +"""SMS app for reading and sending messages +""" +___name___ = "Phone" +___license___ = "MIT" +___dependencies___ = ["app", "dialogs", "sim800", "ugfx_helper"] +___categories___ = ["System"] +___bootstrapped___ = True + +from app import * +from dialogs import * +import ugfx +import ugfx_helper +import sim800 + +ugfx_helper.init() +ugfx.clear() + +menuset = [] +messages = sim800.listsms(4) + +for message in messages: + splitmessage = message.split(",") + menuset.insert(0, { "title" : splitmessage[5] + " " + splitmessage[4] + " from " + splitmessage[2], "index" : splitmessage[0] }) + +while True: + selection = prompt_option(menuset, text="Select message", select_text="Read", none_text="Exit") + if (selection): + message = sim800.readsms(selection["index"]) + notice(message, title=selection["title"]) + else: + break