01234567890123456789012345678901234567890123456789012345678901234567890123456789
633634635636637638639640641642643644645646647648649650651652 653654655656657658659660661662663664665666667668669670671672 918919920921922923924925926927928929930931932933934935936937 938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979 12251226122712281229123012311232123312341235123612371238123912401241124212431244 12451246124712481249125012511252125312541255125612571258125912601261126212631264 |
<----SKIPPED LINES---->
*SERVO_CONNECTION, read_timeout=7,
error_pin=messageboard.GPIO_ERROR_ARDUINO_SERVO_CONNECTION, to_parent_q=to_parent_q,
read_format='l', write_format='ff???', name='Servo')
link.Open()
last_flight = {}
last_angles = (0, 0)
flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
to_arduino_q)
next_read = 0
next_write = 0
now = GetNow(json_desc_dict, additional_attr)
while not shutdown.value:
if not to_arduino_q.empty():
flight, json_desc_dict, configuration, additional_attr = to_arduino_q.get(
block=False)
if 'test_servos' in configuration:
messageboard.RemoveSetting(configuration, 'test_servos')
link.Write((0, 0, *LASER_RGB_OFF))
time.sleep(1)
link.Write((90, 0, *LASER_RED))
time.sleep(1)
link.Write((180, 0, *LASER_GREEN))
time.sleep(1)
link.Write((270, 0, *LASER_BLUE))
time.sleep(1)
new_flight = DifferentFlights(flight, last_flight)
if new_flight:
Log('Flight changed from %s to %s' % (
messageboard.DisplayFlightNumber(last_flight),
messageboard.DisplayFlightNumber(flight)
), ser=link)
# Turn off laser so that line isn't traced while it moves to new position
link.Write((*last_angles, *LASER_RGB_OFF))
last_flight = flight
<----SKIPPED LINES---->
- Display a histogram
- Send information for a different display mode
- Indicate that the battery is low
Args:
command: dictionary representing all data fields from remote.
configuration: dictionary representing the current state of the messageboard
configuration.
display_mode: current display mode; only passed so that we may identify changes.
low_battery: current battery status; only passed so that we may identify changes.
to_parent_q: multiprocessing queue, where instructions to send back to messageboard,
if any, can be placed.
link: the open serial link.
Returns:
A 2-tuple of potentially-updated display_mode, and low_battery.
"""
# command might update a setting; see if there's a change, and if so, write to disk
setting_change = False
log_lines = []
setting_keys = ['setting_max_distance', 'setting_max_altitude',
'setting_on_time', 'setting_off_time', 'setting_delay']
for key in setting_keys:
if command.get(key) != configuration.get(key):
log_lines.append(' |-->Setting %s updated from %s to %s' % (
key, str(configuration.get(key)), str(command[key])))
setting_change = True
configuration[key] = command[key]
remote_key = 'setting_screen_enabled_bool'
system_key = 'setting_screen_enabled'
# remote sees T/F whereas messageboard.py & the web interface expect 'on'/absent key
if command[remote_key] and system_key not in configuration:
setting_change = True
configuration[system_key] = 'on'
log_lines.append(' |-->Setting %s updated from None to on' % system_key)
elif not command[remote_key] and system_key in configuration:
setting_change = True
configuration.pop(system_key)
log_lines.append(' |-->Setting %s updated from on to None' % system_key)
if setting_change:
settings_string = messageboard.BuildSettings(configuration)
to_parent_q.put(('update_configuration', (settings_string, )))
# a command might request info about flight to be (re)displayed, irrespective of
# whether the screen is on; if so, let's put that message at the front of the message
# queue, and delete any subsequent messages in queue because presumably the button
# was pushed either a) when the screen was off (so no messages in queue), or b)
# because the screen was on, but the last flight details got lost after other screens!
if command['last_plane']:
to_parent_q.put(('replay', ()))
log_lines.append(' |-->Requested last flight (re)display')
# a command might request a histogram; simply generate and save a histogram file to disk
if command['histogram_enabled']:
h_type = GetName(HISTOGRAM_TYPES, command['current_hist_type'])
h_history = GetName(HISTOGRAM_HISTORY, command['current_hist_history'])
to_parent_q.put(('histogram', (h_type, h_history)))
log_lines.append(' |-->Requested %s histogram with %s data' % (h_type, h_history))
# a command might update us on the display mode; based on the display mode, we might
# pass different attributes back to the remote
<----SKIPPED LINES---->
last_configuration = configuration
while not shutdown.value:
if not to_arduino_q.empty():
to_arduino_message = to_arduino_q.get(block=False)
flight, json_desc_dict, configuration, additional_attr = to_arduino_message
if 'setting_screen_enabled' not in last_configuration and 'setting_screen_enabled' in configuration:
Log('setting_screen_enabled changed from NOT PRESENT to ON')
if 'setting_screen_enabled' in last_configuration and 'setting_screen_enabled' not in configuration:
Log('setting_screen_enabled changed from ON to NOT PRESENT')
last_configuration = configuration
if 'test_remote' in configuration:
messageboard.RemoveSetting(configuration, 'test_remote')
def TestDisplayMode(m):
SendRemoteMessage(
flight, json_desc_dict, configuration, additional_attr,
m, write_keys, write_format_tuple, link)
time.sleep(1)
TestDisplayMode(DISP_LAST_FLIGHT_NUMB_ORIG_DEST)
TestDisplayMode(DISP_LAST_FLIGHT_AZIMUTH_ELEVATION)
TestDisplayMode(DISP_FLIGHT_COUNT_LAST_SEEN)
TestDisplayMode(DISP_RADIO_RANGE)
if time.time() >= next_write:
next_write = SendRemoteMessage(
flight, json_desc_dict, configuration, additional_attr,
display_mode, write_keys, write_format_tuple, link)
if time.time() >= next_read:
bytes_read = []
values_t = link.Read(bytes_read=bytes_read)
<----SKIPPED LINES---->
|
01234567890123456789012345678901234567890123456789012345678901234567890123456789
633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956 957958959960961962963964965966967968969970971972973974975976977978979980 12261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266 |
<----SKIPPED LINES---->
*SERVO_CONNECTION, read_timeout=7,
error_pin=messageboard.GPIO_ERROR_ARDUINO_SERVO_CONNECTION, to_parent_q=to_parent_q,
read_format='l', write_format='ff???', name='Servo')
link.Open()
last_flight = {}
last_angles = (0, 0)
flight, json_desc_dict, configuration, additional_attr = InitialMessageValues(
to_arduino_q)
next_read = 0
next_write = 0
now = GetNow(json_desc_dict, additional_attr)
while not shutdown.value:
if not to_arduino_q.empty():
flight, json_desc_dict, configuration, additional_attr = to_arduino_q.get(
block=False)
if 'test_servos' in configuration:
messageboard.RemoveSetting(configuration, 'test_servos')
configuration.pop('test_servos') # ensure that this is triggered only once
link.Write((0, 0, *LASER_RGB_OFF))
time.sleep(1)
link.Write((90, 0, *LASER_RED))
time.sleep(1)
link.Write((180, 0, *LASER_GREEN))
time.sleep(1)
link.Write((270, 0, *LASER_BLUE))
time.sleep(1)
new_flight = DifferentFlights(flight, last_flight)
if new_flight:
Log('Flight changed from %s to %s' % (
messageboard.DisplayFlightNumber(last_flight),
messageboard.DisplayFlightNumber(flight)
), ser=link)
# Turn off laser so that line isn't traced while it moves to new position
link.Write((*last_angles, *LASER_RGB_OFF))
last_flight = flight
<----SKIPPED LINES---->
- Display a histogram
- Send information for a different display mode
- Indicate that the battery is low
Args:
command: dictionary representing all data fields from remote.
configuration: dictionary representing the current state of the messageboard
configuration.
display_mode: current display mode; only passed so that we may identify changes.
low_battery: current battery status; only passed so that we may identify changes.
to_parent_q: multiprocessing queue, where instructions to send back to messageboard,
if any, can be placed.
link: the open serial link.
Returns:
A 2-tuple of potentially-updated display_mode, and low_battery.
"""
# command might update a setting; see if there's a change, and if so, write to disk
setting_change = False
log_lines = []
new_configuration = {}
setting_keys = ['setting_max_distance', 'setting_max_altitude',
'setting_on_time', 'setting_off_time', 'setting_delay']
for key in setting_keys:
if command.get(key) != configuration.get(key):
log_lines.append(' |-->Setting %s updated from %s to %s' % (
key, str(configuration.get(key)), str(command[key])))
setting_change = True
new_configuration[key] = command[key]
remote_key = 'setting_screen_enabled_bool'
system_key = 'setting_screen_enabled'
# remote sees T/F whereas messageboard.py & the web interface expect 'on'/absent key
if command[remote_key] and system_key not in configuration:
setting_change = True
new_configuration[system_key] = 'on'
log_lines.append(' |-->Setting %s updated from None to on' % system_key)
elif not command[remote_key] and system_key in configuration:
setting_change = True
log_lines.append(' |-->Setting %s updated from on to None' % system_key)
if setting_change:
settings_string = messageboard.BuildSettings(new_configuration)
to_parent_q.put(('update_configuration', (settings_string, )))
# a command might request info about flight to be (re)displayed, irrespective of
# whether the screen is on; if so, let's put that message at the front of the message
# queue, and delete any subsequent messages in queue because presumably the button
# was pushed either a) when the screen was off (so no messages in queue), or b)
# because the screen was on, but the last flight details got lost after other screens!
if command['last_plane']:
to_parent_q.put(('replay', ()))
log_lines.append(' |-->Requested last flight (re)display')
# a command might request a histogram; simply generate and save a histogram file to disk
if command['histogram_enabled']:
h_type = GetName(HISTOGRAM_TYPES, command['current_hist_type'])
h_history = GetName(HISTOGRAM_HISTORY, command['current_hist_history'])
to_parent_q.put(('histogram', (h_type, h_history)))
log_lines.append(' |-->Requested %s histogram with %s data' % (h_type, h_history))
# a command might update us on the display mode; based on the display mode, we might
# pass different attributes back to the remote
<----SKIPPED LINES---->
last_configuration = configuration
while not shutdown.value:
if not to_arduino_q.empty():
to_arduino_message = to_arduino_q.get(block=False)
flight, json_desc_dict, configuration, additional_attr = to_arduino_message
if 'setting_screen_enabled' not in last_configuration and 'setting_screen_enabled' in configuration:
Log('setting_screen_enabled changed from NOT PRESENT to ON')
if 'setting_screen_enabled' in last_configuration and 'setting_screen_enabled' not in configuration:
Log('setting_screen_enabled changed from ON to NOT PRESENT')
last_configuration = configuration
if 'test_remote' in configuration:
messageboard.RemoveSetting(configuration, 'test_remote')
configuration.pop('test_remote') # ensure that this is triggered only once
def TestDisplayMode(m):
SendRemoteMessage(
flight, json_desc_dict, configuration, additional_attr,
m, write_keys, write_format_tuple, link)
time.sleep(1)
TestDisplayMode(DISP_LAST_FLIGHT_NUMB_ORIG_DEST)
TestDisplayMode(DISP_LAST_FLIGHT_AZIMUTH_ELEVATION)
TestDisplayMode(DISP_FLIGHT_COUNT_LAST_SEEN)
TestDisplayMode(DISP_RADIO_RANGE)
if time.time() >= next_write:
next_write = SendRemoteMessage(
flight, json_desc_dict, configuration, additional_attr,
display_mode, write_keys, write_format_tuple, link)
if time.time() >= next_read:
bytes_read = []
values_t = link.Read(bytes_read=bytes_read)
<----SKIPPED LINES---->
|