def _update_scale(self, address, setting):
     # types: (int, int) -> None
     # Only update if the display is connected
     if not self._display_error:
         scale_index = int(
             setting - 15.0
         )  # This is set for now assuming a single trackbar - may need to be changed if more trackbars added
         geniePi.genieWriteObj(geniePi.GENIE_OBJ_TRACKBAR, address,
                               scale_index)
Example #2
0
def turn_led(status):

	if (status == ON):
		print >>sys.stderr, ("Turning on LED!")
		geniePi.genieWriteObj(19, 0, 1)
		geniePi.genieWriteStr(0, MESSAGE_ON)
	else:
		print >>sys.stderr, ("Turning off LED!")
		geniePi.genieWriteObj(19, 0, 0)
		geniePi.genieWriteStr(0, MESSAGE_OFF)
 def _update_led(self, address, status):
     # types: (int, int) -> None
     # Only update if the display is connected
     if not self._display_error:
         if status == LED_ON:
             self._logger.debug('  Received message to turn on a LED')
             geniePi.genieWriteObj(geniePi.GENIE_OBJ_USER_LED, address,
                                   LED_ON)
         else:
             self._logger.debug('  Received message to turn off a LED')
             geniePi.genieWriteObj(geniePi.GENIE_OBJ_USER_LED, address,
                                   LED_OFF)
 def _update_btn(self, address, status):
     # types: (int, int) -> None
     # Only update is the display is connected
     if not self._display_error:
         if status == BTN_ON:
             self._logger.debug(
                 '  Received message to turn on a power button')
             geniePi.genieWriteObj(geniePi.GENIE_OBJ_4DBUTTON, address,
                                   BTN_ON)
         else:
             self._logger.debug(
                 '  Received message to turn off a power button')
             geniePi.genieWriteObj(geniePi.GENIE_OBJ_4DBUTTON, address,
                                   BTN_OFF)
Example #5
0
def printing_ip_on_display():

	s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	s.connect(("gmail.com",90))
	local_ip = s.getsockname()[0]
	time.sleep(0.1)
	geniePi.genieWriteStr(1, local_ip)
	time.sleep(0.1)
	geniePi.genieWriteObj(19, 0, 1)
	time.sleep(0.1)
	geniePi.genieWriteStr(0, MESSAGE_ON)
	s.close()
	
	return local_ip
Example #6
0
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()
Example #7
0
def recover_data(ip):
	
	while True:
		# Add all the return bottons here.
		event = geniePi.genieReadObj(geniePi.GENIE_OBJ_WINBUTTON, 7)
		
		if event == 1:
			print ("valor de event: %d") % event
		if (event == 1):
			print >>sys.stderr, ("Recovering info to display!")
			time.sleep(0.1)
			geniePi.genieWriteObj(19, 0, 1)
			time.sleep(0.1)
			geniePi.genieWriteStr(0, MESSAGE_ON)
			time.sleep(0.1)
			geniePi.genieWriteStr(1, ip)
			time.sleep(0.1)
			event = 0
Example #8
0
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!')
    def run(self):
        # Infinite look until event signalling exit
        self._logger.debug('Starting weather display thread')
        while not self._kill_event.is_set():
            # Get the latest weather as an xml printout
            url_address = 'https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=cytz&hoursBeforeNow=2'
            try:
                self._logger.debug('  Getting weather from internet')
                url_response = urllib2.urlopen(url_address)
                xml_data = url_response.read()
            except urllib2.URLError as url_error:
                if hasattr(url_error, 'reason'):
                    self._logger.error('  Could not reach the server: %s',
                                       url_error.reason)
                elif hasattr(url_error, 'code'):
                    self._logger.error(
                        '  The server could not fulfill the request: %s',
                        url_error.code)
            except:
                self._logger.error(
                    '  Unknown error thrown by attempt to read weather from the internet - skipping update'
                )
            else:
                # Get the node with the most recent weather data
                xml_root = ET.fromstring(xml_data)
                metar_list = xml_root.findall('./data/METAR')
                if len(metar_list) > 0:
                    metar = metar_list[
                        0]  # Get the latest METAR update despite type (can include SPECI's)
                    new_icon = None

                    # Determine if there is precipitation (implies that we don't have to worry about cloud type, just type of precip)
                    self._logger.debug(
                        '  METAR present, checking for any precipitation')
                    if metar.find(
                            './wx_string'
                    ) is not None:  # We have possible precipitation, need to check the remarks
                        wx_string = metar.find(
                            './wx_string'
                        ).text  # Get the string describing conditions
                        self._logger.debug('    Found weather string: %s',
                                           wx_string)

                        # Check for types of rain
                        if 'TS' in wx_string:  # Check for thunderstorms
                            new_icon = WX_TSTORM
                            self._logger.debug('    Thunderstorms present')
                        elif 'FZ' in wx_string:  # Check for freezing rain
                            new_icon = WX_FZ_RAIN
                            self._logger.debug('    Freezing rain present')
                        elif 'SN' in wx_string:  # Check for snow
                            if 'SH' in wx_string:  # Further check for snow showers
                                new_icon = WX_SCAT_SNOW
                                self._logger.debug(
                                    '    Scattered snow showers present')
                            else:
                                new_icon = WX_SNOW
                                self._logger.debug('    Snow present')
                        elif ('RA' in wx_string) or (
                                'DZ' in wx_string
                        ):  # Finally, see if there is plain old rain
                            if 'SH' in wx_string:  # Further check for showers
                                new_icon = WX_SHOWERS
                                self._logger.debug('    Rain showers present')
                            else:
                                new_icon = WX_RAIN
                                self._logger.debug('    Rain present')

                    # If no icon found for precipitation, check cloud types
                    if new_icon is None:
                        # Get all sky conditions and iterate through them
                        self._logger.debug(
                            '  No precipitation present, checking cloud layers (assuming sunny skies to start)'
                        )
                        new_icon = WX_SUNNY  # Default to no coverage, or sunny skies
                        for layer in metar.findall('./sky_condition'):
                            if 'cloud_base_ft_agl' not in layer.keys(
                            ):  # Check that a cloud base is defined - won't be for clear skies
                                self._logger.debug('    Evaluating layer %s',
                                                   layer.attrib['sky_cover'])
                                if layer.attrib[
                                        'sky_cover'] == 'SKC' or layer.attrib[
                                            'sky_cover'] == 'CLR':
                                    # Call this condition sunny skies and break out of the loop (not likely needed)
                                    new_icon = WX_SUNNY
                                    self._logger.debug(
                                        '    Confirmed clear skies')
                                    break
                            elif int(
                                    layer.attrib['cloud_base_ft_agl']
                            ) <= 12000:  # Need to evaluate the sky condition below 12,000 ft
                                self._logger.debug(
                                    '    Evaluating layer %s at %s',
                                    layer.attrib['sky_cover'],
                                    layer.attrib['cloud_base_ft_agl'])
                                if layer.attrib['sky_cover'] == 'FEW':
                                    self._logger.debug(
                                        '    Evaluating this few clouds layer')
                                    if new_icon < WX_FEW_CLOUDS:
                                        new_icon = WX_FEW_CLOUDS  # Treat this as sunny skies
                                        self._logger.debug(
                                            '      Icon will be updated to WX_FEW_CLOUDS based on this layer'
                                        )
                                elif layer.attrib['sky_cover'] == 'SCT':
                                    self._logger.debug(
                                        '    Evaluating this scattered layer')
                                    if new_icon < WX_SCT_CLOUDS:
                                        new_icon = WX_SCT_CLOUDS
                                        self._logger.debug(
                                            '      Icon will be updated to WX_SCT_CLOUDS based on this layer'
                                        )
                                elif layer.attrib['sky_cover'] == 'BKN':
                                    self._logger.debug(
                                        '    Evaluating this broken layer')
                                    if new_icon < WX_OVC_CLOUDS:
                                        new_icon = WX_OVC_CLOUDS
                                        self._logger.debug(
                                            '      Icon will be updated to WX_OVC_CLOUDS based on this layer'
                                        )
                                elif layer.attrib['sky_cover'] == 'OVC':
                                    self._logger.debug(
                                        '    Evaluating this overcast layer')
                                    if new_icon < WX_OVC_CLOUDS:
                                        new_icon = WX_OVC_CLOUDS
                                        self._logger.debug(
                                            '      Icon will be updated to WX_OVC_CLOUDS based on this layer'
                                        )
                            else:  # Level too high
                                self._logger.debug(
                                    '  Layer %s with bases at %s ignored due to height',
                                    layer.attrib['sky_cover'],
                                    layer.attrib['cloud_base_ft_agl'])

                    # Update the weather display if a new icon is needed
                    if self._current_icon != new_icon:
                        self._logger.debug(
                            '  Icon is different than currently displayed - display updating'
                        )
                        self._current_icon = new_icon
                        geniePi.genieWriteObj(geniePi.GENIE_OBJ_USERIMAGES,
                                              WEATHER_ADD, self._current_icon)
                    else:
                        self._logger.debug(
                            '  Icon is same as currently displayed - no display update'
                        )

                else:  # No METAR information, so do not update the display
                    self._logger.debug(
                        '  No METAR data to update weather display.')

            # Delay between date string updates - will give reasonable lag for the clock update
            self._kill_event.wait(15 * 60)  # 15 minutes

        self._logger.debug('Weather display thread exiting.')
    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')