def printCgmData(): tswG = True tswT = True while True: tnow = datetime.now() if (tnow.hour >= 22) or (tnow.hour <= 10): if tswG: mat.clear8Mat() mat.clear16Mat() mat.dispGluc() time.sleep(10) mat.clear16Mat() tswG = False tswT = True queryCgmData() mat.dispBsArr() mat.printArrow() else: if tswT: mat.clear8Mat() mat.clear16Mat() mat.dispTim() time.sleep(10) mat.clear16Mat() tswG = True tswT = False mat.dispTime() time.sleep(60)
def initGlucMode(): print('Terminating Idle mode, starting Glucalarm', flush=True) cfg.targetWack = random.randint(0, 2) mat.clear8Mat() mat.fill16Mat(0) time.sleep(1) mat.dispGluc() time.sleep(1) cfg.switchModes = False cfg.bsHighFl = False cfg.bsHighLatch = False cfg.bsLowFl = False cfg.bsLowLatch = False cfg.bsUrLowFl = False cfg.bsUrLowLatch = False cfg.bsDrop2Fl = False cfg.bsFrop2Latch = False cfg.bsDrop1Fl = False cfg.bsFrop1Latch = False cfg.wackPressed = False cfg.alarmSound = False cfg.noDataLatch = False cfg.soundTim = datetime.now() cfg.queryTim = datetime.now() cfg.noDataTim = datetime.now() cfg.glucTim = datetime.now() if (cfg.glucTim.hour < cfg.glucStopTim): cfg.glucTim.replace(hour=cfg.glucStopTim) else: cfg.glucTim = cfg.glucTim + timedelta(days=1) cfg.glucTim.replace(hour=cfg.glucStopTim)
def init(): #set gpio mode GPIO.setmode(GPIO.BCM) #state of wack buttons/leds GPIO.setup(pinWackBt1, GPIO.IN) GPIO.setup(pinWackBt2, GPIO.IN) GPIO.setup(pinWackBt3, GPIO.IN) GPIO.setup(pinWackLed1, GPIO.OUT, initial=0) GPIO.setup(pinWackLed2, GPIO.OUT, initial=0) GPIO.setup(pinWackLed3, GPIO.OUT, initial=0) #state of timer buttons GPIO.setup(pinLampBt, GPIO.IN) GPIO.setup(pinModeBt, GPIO.IN) #state of power button GPIO.setup(pinPowerBt, GPIO.IN) GPIO.setup(pinPowerLed, GPIO.OUT, initial=0) #highpower led GPIO.setup(pinHighPowerLed, GPIO.OUT, initial=0) #turn off led matrices mat.setDisp8Brightness(1) mat.setDisp16Brightness(0) mat.clear8Mat() mat.clear16Mat()
def shutDown(): mat.dispShd() print('shutting down glucalarm') time.sleep(2) mat.clear8Mat() mat.fill16Mat(0) GPIO.output(cfg.pinPowerLed, 0) GPIO.output(cfg.pinHighPowerLed, 0) turnAllLed(0) subprocess.call("sudo shutdown now", shell=True)
def initIdleMode(): print('Terminating Glucalarm, starting Idle mode') GPIO.output(cfg.pinPowerLed, 0) cfg.pwrBtPress = False cfg.pwrCntDispT = time.time() cfg.powerTim = time.time() mat.clear8Mat() mat.fill16Mat(0) time.sleep(1) mat.dispTim() time.sleep(2) mat.fill16Mat(0) cfg.switchModes = False
def initServ(): #init pi state cfg.init() mat.clear8Mat() mat.clear16Mat() #init state machine flags switchIdleMode() #switchGlucMode() #define interrupt callbacks initPwdInterrupts() initLampInterrupts() initModeInterrupts() initGlucInterrupts()