def sample(channel):
    """ Callback function for button interrupt that causes a sample to 
	be taken from both sensors.
	"""
    time.sleep(0.1)

    print("Button pushed!")

    DAQC.getINTflags(0)  # clear the interrupt

    # use light strobes to indicate measurement
    DAQC.setDOUTall(0, 0)
    for j in range(7):
        DAQC.setDOUTbit(0, j)
        time.sleep(0.1)
        DAQC.clrDOUTbit(0, j)
        time.sleep(0.1)

    # measure from the BME280 (ORDER MATTERS!)
    temp = sensor.read_temperature()
    pressure = sensor.read_pressure() / 100.  # convert to hectopascals
    humidity = sensor.read_humidity()
    t = sensor.t_fine

    # measure from the (analog) photo-sensor
    light = DAQC.getADC(0, 0)

    global data
    data.append([t, temp, pressure, humidity, light])

    # turn off LEDs
    DAQC.setDOUTall(0, 0)
Example #2
0
def triggerINT():
    """Callback rountine when a Digital Input has been triggered.
  """
    logger.debug("triggerINT")

    DAQC.setDOUTbit(0, 0)
    DAQC.getINTflags(0)
    if DEBUG:
        print("\033[94m _-*xmit triggered!*-_ \033[0m")
    vswr()
    DAQC.clrDOUTbit(0, 0)
Example #3
0
def leds():
    DAQC.enableSWint(0)
    DAQC.intEnable(0)
    while True:
        DAQC.setLED(0, 0)
        if DAQC.getINTflags(0) == 256:
            break
        time.sleep(.25)
        if DAQC.getINTflags(0) == 256:
            break
        DAQC.clrLED(0, 0)
        if DAQC.getINTflags(0) == 256:
            break
        time.sleep(.25)
        if DAQC.getINTflags(0) == 256:
            break
    for i in range(0, 100):
        DAQC.clrLED(0, 0)
        DAQC.clrLED(0, 1)
    def run(self, *args):
        logger.info("ButtonPushedThread run start")

        DAQC.enableSWint(self.daqcBoard)
        DAQC.intEnable(self.daqcBoard)
        while True:
            if self.isShutdown:
                break
            if DAQC.getINTflags(self.daqcBoard) == 256:
                self.pillDispenser.setDispenseState('CONFIRMING')
                break
            time.sleep(.25)
Example #5
0
 def createIote2eRequest(self):
     iote2eRequest = None
     if DAQC.getINTflags(0) == 256:
         logger.info("ProcessLedGreen createIote2eRequest {}".format(
             self.sensorName))
         pairs = {self.sensorName: self.btnPressed}
         iote2eRequest = Iote2eRequest(
             login_name=self.loginVo.loginName,
             source_name=self.loginVo.sourceName,
             source_type='switch',
             request_uuid=str(uuid.uuid4()),
             request_timestamp=ClientUtils.nowIso8601(),
             pairs=pairs,
             operation='SENSORS_VALUES')
         if self.btnPressed == '1':
             self.btnPressed = '0'
         else:
             self.btnPressed = '1'
     return iote2eRequest
Example #6
0
def main():
    try:
        """Main program loop."""
        logger.debug("Main loop start")

        cursor.execute("SHOW TABLES LIKE 'swr'")
        result = cursor.fetchone()
        if result:
            if DEBUG:
                print("\033[92mDB: database and tables exist \033[0m")
        else:
            if DEBUG:
                print("\033[91mDB: no tables, creating database \033[0m")
            createDB()

        while True:
            if GPIO.event_detected(22):
                triggerINT()
            rm_utils.clr_all()
            # Two red flashes denotes start of cycle
            rm_utils.blink_red()
            rm_utils.blink_red()
            if DEBUG:
                print(time.ctime())
                print("INT flags: {}".format(DAQC.getINTflags(0)))
            db_analog()
            db_din()
            rm_utils.blink_red()
            rm_utils.blink_red()
            # Two red flashes denotes end of cycle
            rm_utils.clr_all()
            if DEBUG:
                print("\033[91mDEBUG sleep 10s\033[0m")
                sleep(10)
            else:
                # sleep for 30 minutes
                sleep(900)
    except KeyboardInterrupt:
        cursor.close()
        mariadb_connection.close()
        GPIO.cleanup()
    t = sensor.t_fine

    # measure from the (analog) photo-sensor
    light = DAQC.getADC(0, 0)

    global data
    data.append([t, temp, pressure, humidity, light])

    # turn off LEDs
    DAQC.setDOUTall(0, 0)


# set up GPIO interface for pushbotton on PiDAQC
DAQC.enableSWint(0)  # enable pushbutton interrupt
DAQC.intEnable(0)  # enable global interrupts
DAQC.getINTflags(0)  # clear any flags

# GPIO event detection must be set up AFTER clearing DAQC interrupt flag
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(22, GPIO.FALLING, callback=sample)
DAQC.getINTflags(0)

# set up BME280
sensor = BME280(mode=BME280_OSAMPLE_8)

try:
    while (1):
        # wait for button
        DAQC.setLED(0, 0)
        time.sleep(0.5)