arduino-2020-07-04-1459.py
01234567890123456789012345678901234567890123456789012345678901234567890123456789









809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876











                            <----SKIPPED LINES---->




  d['led_red'] = led[0]
  d['led_green'] = led[1]
  d['led_blue'] = led[2]
  d['arduino_reset'] = reset

  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 PerceivedBrightness(rgb, gamma, brightness):
  """Calculates the perceived brightness when RGB scaled by 0..1 brightness."""
  total = sum([(color * brightness)**gamma for color in rgb]) ** (1/gamma)
  return total


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)
  if brightness == 1.0:
    return r, g, b

  perceived_full_brightness = PerceivedBrightness(rgb, gamma, 1.00)
  desired_brightness = perceived_full_brightness * brightness
  best_error = float('inf')
  for scaling_factor in range(101):
    perceived_brightness = PerceivedBrightness(rgb, gamma, scaling_factor / 100)
    error = abs(perceived_brightness - desired_brightness)
    if error < best_error:
      best_error = error
      best_scaling_factor = scaling_factor
  return (
      r * best_scaling_factor, g * best_scaling_factor, b * best_scaling_factor)


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
  # #multiprocessing.Queue.cancel_join_thread




                            <----SKIPPED LINES---->





01234567890123456789012345678901234567890123456789012345678901234567890123456789









809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843             844845846847848849850851852853854855856857858859860861862863











                            <----SKIPPED LINES---->




  d['led_red'] = led[0]
  d['led_green'] = led[1]
  d['led_blue'] = led[2]
  d['arduino_reset'] = reset

  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 ((c / MAX_PWM) ** gamma) * MAX_PWM


def PerceivedBrightness(rgb, gamma, multiplier):
  """Calculates the perceived brightness when RGB scaled by multiplier."""
  total = sum([(color * multiplier)**gamma for color in rgb]) ** (1/gamma)
  return total


def GammaRGB(rgb, gamma, brightness=1.0):
  """Gamma converts an RGB tuple at a selected brightness 0%..100%."""
  r = Gamma(rgb[0], gamma)
  g = Gamma(rgb[1], gamma)
  b = Gamma(rgb[2], gamma)
  return round(r * brightness), round(g * brightness), round(b * brightness)















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
  # #multiprocessing.Queue.cancel_join_thread




                            <----SKIPPED LINES---->