diff --git a/config-generic.py b/config-generic.py index 7a210f7..a2127ad 100644 --- a/config-generic.py +++ b/config-generic.py @@ -27,3 +27,7 @@ # Sleep time for wake/sleep cycle in milliseconds SLEEP = 60 * 1000 + +# Capacitive Touch Parameters +TOUCH_PIN = 14 +TOUCH_THRESHOLD = 100 diff --git a/main.py b/main.py new file mode 100644 index 0000000..2fe4e0e --- /dev/null +++ b/main.py @@ -0,0 +1,44 @@ +# GNU General Public License +# STIA436 Course - Spring 2019 +# Professor Colin McCormick & Father Chris Wagner +# Copyright (c) 2019 F. Pascal Girard + +import machine +from machine import Timer, TouchPad, Pin +from config import TOUCH_PIN, TOUCH_THRESHOLD + + +TIMER_0 = Timer(0) +TOUCH_PAD = TouchPad(Pin(TOUCH_PIN)) + + +def run(timer): + + touch_value = TOUCH_PAD.read() + print("Touch Value: {}, Touch Threshold {}".format(touch_value, TOUCH_THRESHOLD)) + + # When the touch value is above the threshold, then it is not being touched + if touch_value > TOUCH_THRESHOLD: + print("Running Sensors...") + import wake + + wake.main() + else: + print("Starting AP and Web REPL...") + import webrepl + import iot + + iot.init_sta(False) + iot.init_ap(True) + webrepl.start() + + +if machine.reset_cause() == machine.DEEPSLEEP_RESET: + print("Woke from a deep sleep...") + import wake + + wake.main() + +else: # an opportunity to enter WebREPL after hard reset + print("Hard reset") + TIMER_0.init(period=5000, mode=Timer.ONE_SHOT, callback=run) diff --git a/main~.py b/main~.py deleted file mode 100644 index d9cad79..0000000 --- a/main~.py +++ /dev/null @@ -1,61 +0,0 @@ -# GNU General Public License -# STIA436 Course - Spring 2019 -# Professor Colin McCormick & Father Chris Wagner -# Copyright (c) 2019 F. Pascal Girard - -import machine -from machine import Timer - -""" -# ESP32 Code - see below -# from machine import TouchPad -pad = TouchPad(Pin(14)) -""" - -timer = Timer(0) -upgrade = False - -print("Running main") - - -def callback(pin): - global upgrade - upgrade = True - return upgrade - - -def run(timer): - if not upgrade: - print("Running sensors...") - import wake - - wake.main() - else: - print("Upgrading...") - import webrepl - import iot - - iot.init_sta(False) - iot.init_ap(True) - webrepl.start() - - -if machine.reset_cause() == machine.DEEPSLEEP_RESET: - print("Woke from a deep sleep...") - import wake - - wake.main() - -else: # an opportunity to enter WebREPL after hard reset - print("Hard reset") - # ESP8266 Code - """ - pin0 = Pin(0, Pin.IN, Pin.PULL_UP) # set GPIO0 as input with pullup - pin0.irq(trigger=Pin.IRQ_RISING, handler=callback) - """ - # ESP32 Code - """ - """ - timer.init(period=5000, mode=Timer.ONE_SHOT, callback=run) - - # ESP32 Code