01234567890123456789012345678901234567890123456789012345678901234567890123456789
811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853 941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981 |
<----SKIPPED LINES---->
return d
def HexColorToRGBTuple(hex_color):
"""Converts i.e.: #329a43 to (50, 154, 67)."""
r = hex_color[1:3]
g = hex_color[3:5]
b = hex_color[5:7]
return (int(r, 16), int(g, 16), int(b, 16))
def Gamma(c, gamma):
"""Converts a desired brightness 0..255 to a gamma-corrected PWM 0..255."""
# Based on https://hackaday.com/2016/08/23/
# rgb-leds-how-to-master-gamma-and-hue-for-perfect-brightness/
return round(((c / MAX_PWM) ** gamma) * MAX_PWM)
def GammaRGB(rgb, gamma, brightness=1.0):
"""Gamma converts an RGB tuple at a selected brightness 0%..100%."""
r = Gamma(rgb[0], gamma) * brightness
g = Gamma(rgb[1], gamma) * brightness
b = Gamma(rgb[2], gamma) * brightness
return r, g, b
def GetGamma(configuration):
"""Returns gamma stored in configuration file."""
return configuration['servo_rgb_gamma'] / 10 # gamma saved as whole number
def ServoMain(to_arduino_q, to_parent_q, shutdown):
"""Main servo controller for projecting the plane position on a hemisphere.
Takes the latest flight from the to_arduino_q and converts that to the current
azimuth and altitude of the plane on a hemisphere.
"""
sys.stderr = open(messageboard.STDERR_FILE, 'a')
Log('Process started with process id %d' % os.getpid())
# Ensures that the child can exit if the parent exits unexpectedly
# docs.python.org/2/library/multiprocessing.html
<----SKIPPED LINES---->
configuration['servo_mode'] in ('laser_only', 'both')):
if VERBOSE:
Log('Flight #: %s current_angles: %s' % (
messageboard.DisplayFlightNumber(flight), str(current_angles)))
laser_rgb = LaserRGBFlight(flight)
message_dict = GenerateServoMessage(
laser=laser_rgb, angles=current_angles, led=LED_OFF)
elif configuration['servo_mode'] == 'laser_only':
message_dict = GenerateServoMessage(laser=LASER_OFF, led=LED_OFF)
else:
rgb_tuple = GammaRGB(
HexColorToRGBTuple(configuration['led_color']), gamma)
message_dict = GenerateServoMessage(laser=LASER_OFF, led=rgb_tuple)
message_tuple = DictToValueTuple(
message_dict, write_keys, write_format_tuple)
Log(message_tuple)
link.Write(message_tuple)
next_write = time.time() + WRITE_DELAY_TIME
# One final write telling Arduino to do a software reset
message_dict = GenerateServoMessage(laser=LASER_OFF, reset=True)
message_tuple = DictToValueTuple(message_dict, write_keys, write_format_tuple)
link.Write(message_tuple)
link.Close(SHUTDOWN_TEXT)
def LaserRGBFlight(flight):
"""Based on flight attributes, set the laser."""
# Possible assignment based on:
# - ascending / descending / level
# - to SFO / from SFO / other
# - big plane / med plane / small plane
# - low alt / med alt / high alt
# - low speed / med speed / high speed
<----SKIPPED LINES---->
|
01234567890123456789012345678901234567890123456789012345678901234567890123456789
811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853 941942943944945946947948949950951952953954955956957958959960 961962963964965966967968969970971972973974975976977978979980 |
<----SKIPPED LINES---->
return d
def HexColorToRGBTuple(hex_color):
"""Converts i.e.: #329a43 to (50, 154, 67)."""
r = hex_color[1:3]
g = hex_color[3:5]
b = hex_color[5:7]
return (int(r, 16), int(g, 16), int(b, 16))
def Gamma(c, gamma):
"""Converts a desired brightness 0..255 to a gamma-corrected PWM 0..255."""
# Based on https://hackaday.com/2016/08/23/
# rgb-leds-how-to-master-gamma-and-hue-for-perfect-brightness/
return round(((c / MAX_PWM) ** gamma) * MAX_PWM)
def GammaRGB(rgb, gamma, brightness=1.0):
"""Gamma converts an RGB tuple at a selected brightness 0%..100%."""
r = round(Gamma(rgb[0], gamma) * brightness)
g = round(Gamma(rgb[1], gamma) * brightness)
b = round(Gamma(rgb[2], gamma) * brightness)
return r, g, b
def GetGamma(configuration):
"""Returns gamma stored in configuration file."""
return configuration['servo_rgb_gamma'] / 10 # gamma saved as whole number
def ServoMain(to_arduino_q, to_parent_q, shutdown):
"""Main servo controller for projecting the plane position on a hemisphere.
Takes the latest flight from the to_arduino_q and converts that to the current
azimuth and altitude of the plane on a hemisphere.
"""
sys.stderr = open(messageboard.STDERR_FILE, 'a')
Log('Process started with process id %d' % os.getpid())
# Ensures that the child can exit if the parent exits unexpectedly
# docs.python.org/2/library/multiprocessing.html
<----SKIPPED LINES---->
configuration['servo_mode'] in ('laser_only', 'both')):
if VERBOSE:
Log('Flight #: %s current_angles: %s' % (
messageboard.DisplayFlightNumber(flight), str(current_angles)))
laser_rgb = LaserRGBFlight(flight)
message_dict = GenerateServoMessage(
laser=laser_rgb, angles=current_angles, led=LED_OFF)
elif configuration['servo_mode'] == 'laser_only':
message_dict = GenerateServoMessage(laser=LASER_OFF, led=LED_OFF)
else:
rgb_tuple = GammaRGB(
HexColorToRGBTuple(configuration['led_color']), gamma)
message_dict = GenerateServoMessage(laser=LASER_OFF, led=rgb_tuple)
message_tuple = DictToValueTuple(
message_dict, write_keys, write_format_tuple)
link.Write(message_tuple)
next_write = time.time() + WRITE_DELAY_TIME
# One final write telling Arduino to do a software reset
message_dict = GenerateServoMessage(laser=LASER_OFF, reset=True)
message_tuple = DictToValueTuple(message_dict, write_keys, write_format_tuple)
link.Write(message_tuple)
link.Close(SHUTDOWN_TEXT)
def LaserRGBFlight(flight):
"""Based on flight attributes, set the laser."""
# Possible assignment based on:
# - ascending / descending / level
# - to SFO / from SFO / other
# - big plane / med plane / small plane
# - low alt / med alt / high alt
# - low speed / med speed / high speed
<----SKIPPED LINES---->
|