def turn_on_off_led(status): geniePi.genieSetup(PORT, BAUD_RATE) if (status == 1): print("Turning on LED!") time.sleep(0.1) geniePi.genieWriteObj(19, 0, 1) time.sleep(0.1) geniePi.genieWriteStr(0, MESSAGE_ON) else: print("Turning off LED!") time.sleep(0.1) geniePi.genieWriteObj(19, 0, 0) time.sleep(0.1) geniePi.genieWriteStr(0, MESSAGE_OFF) geniePi.genieClose()
def opening_serial_communication(): geniePi.genieSetup(PORT, BAUD_RATE) geniePi.genieWriteStr(0, 'Conexao Local') geniePi.genieWriteObj(0x0E, 0x00, 0x01) #time.sleep(1) geniePi.genieWriteStr(1, 'Pronto para operar!') while True: event = geniePi.genieReadObj(geniePi.GENIE_OBJ_WINBUTTON, 1) if event == 1: break #time.sleep(0.2) geniePi.genieWriteStr(2, 'Procurando Placas...') for i in range(1,5): devices = bus.scan(i) geniePi.genieWriteStr(i+2, str(devices)) geniePi.genieWriteStr(2, 'Placas encontradas!')
#print ("load form 1") #vgWriteObject(vgObject.Form, 0, 0) # load Form 0 #time.sleep(1) #while(1): # rsp=vgReadObject(21,0) # print("rsp="+str(rsp)) # print(ser.read(1)) # time.sleep(1) #print "load form 0" #time.sleep(1) #ser.close() reply=gp.genieReplyStruct() gp.genieSetup(display_port,9600) print("GPLIBRARY LOADED") go=True num="" sms="" while (go): while gp.genieReplyAvail(): gp.genieGetReply(reply) print(reply.cmd,reply.object,reply.index,reply.data) if(reply.object == 13) and (reply.index==1): if(reply.data==107): #num='' #num=num+"+" print("nouveau sms") if(reply.data==13): print(num)
def run(self): # Connect to the display if geniePi.genieSetup('/dev/serial0', 115200) < 0: # Error occurred self._logger.error( ' Cannot connect to the display - it will be updated') self._display_error = True else: # Run the thread self._logger.debug(' Connected to the display') # Create the reply structure reply = geniePi.genieReplyStruct() # Start the clock thread clock_thread = ClockController(self._kill_event, self._display_error) clock_thread.start() # Start the weather display thread weather_thread = WeatherDisplay(self._kill_event, self._display_error) weather_thread.start() # Start infinite loop listening for messages from the display while not self._kill_event.is_set(): # Handle any data coming from the display while geniePi.genieReplyAvail(): geniePi.genieGetReply( reply) # Read next reply for message handling # Handle the message type - only expecting report events if reply.cmd == geniePi.GENIE_REPORT_EVENT: if reply.object == geniePi.GENIE_OBJ_4DBUTTON: # Button pressed if reply.index == PROGRAM_BTN_ADD: self._update_power_status(reply.data) elif reply.index == OVER_BTN_ADD: # Only allow this to change state if the thermostat power is on thermo_status = geniePi.genieReadObj( geniePi.GENIE_OBJ_4DBUTTON, PROGRAM_BTN_ADD) if thermo_status: self._update_override( reply.data, self._setpoint) else: # Revert the override status to its initial state prev_override_status = BTN_OFF if reply.data else BTN_ON geniePi.genieWriteObj( geniePi.GENIE_OBJ_4DBUTTON, OVER_BTN_ADD, prev_override_status) else: self._logger.error( ' Unknown button pressed: %i. No action taken', reply.index) elif reply.object == geniePi.GENIE_OBJ_TRACKBAR: # Slider interacted with if reply.index == TRACKBAR_ADD: # Update the internal setpoint register self._setpoint = 15 + reply.data # Update the thermostat controller iff override mode is on override_status = geniePi.genieReadObj( geniePi.GENIE_OBJ_4DBUTTON, OVER_BTN_ADD) self._logger.debug( ' Current display override status: %i', override_status) if override_status: # The override mode is on self._update_override( override_status, self._setpoint) else: self._logger.error( ' Unknown trackbar changes: %i. No action taken', reply.index) else: self._logger.error( ' Unknown object changed: %i. No action taken', reply.object) else: # Unknown item self._logger.error( ' Unknown display message type: %i. No action taken', reply.cmd) # Wait for next message self._kill_event.wait(0.02) # Check every 20 milliseconds # Cleanup the clock thread weather_thread.join() clock_thread.join() # Indicate the thread is ending self._logger.debug('Display thread closing')
def setup_port(): geniePi.genieSetup(PORT, BAUD_RATE)
while True: event = geniePi.genieReadObj(geniePi.GENIE_OBJ_WINBUTTON, 1) if event == 1: break scan_boards() def scan_boards(): geniePi.genieWriteStr(2, 'Searching boards...') devices = bus.scan() print devices for i in range(1,5): time.sleep(0.1) geniePi.genieWriteStr(i+2, str(devices[i-1])) geniePi.genieWriteStr(2, 'Found boards!') print >>sys.stderr, ("Scan realizado com sucesso!\n") if __name__ == '__main__': print("Iniciated program to scan boards!\n") geniePi.genieSetup(PORT, BAUD_RATE) handler()