def main(): init_logging('power_controlled_lights.log') logging.info('Reading settings configuration file') cfg = ConfigParser() cfg.read('settings.cfg') device_cfg = ConfigParser() device_cfg.read('device_settings.cfg') logging.info('Initializing LED strip driver') color_strip = ColorStrip(device_cfg, LED_FREQ_HZ) signal.signal(signal.SIGTERM, lambda: color_strip.set_color(RgbColor(0, 0, 0))) logging.info('Creating ANT+ node') node = AntPlusNode(NETWORK_KEY) try: logging.info('Attaching ANT+ power meter') pwr_meter = node.attach_power_meter() logging.info('Initializing power light controller') plc = PowerLightController(node.stop, None, cfg, pwr_meter, color_strip) logging.info('Starting ANT+ node') node.start() except Exception as e: logging.error('Caught exception "%s"' % str(e)) raise finally: logging.info('Turning off LED strip') color_strip.set_color(RgbColor(0, 0, 0)) logging.info('Stopping ANT+ node') node.stop()
def main(): node = AntPlusNode(NETWORK_KEY) try: power_meter = node.attach_power_meter() power_meter.on_power_data = print_power power_meter.on_cadence_data = print_cadence node.start() finally: node.stop()
def main(): init_logging('control_fan_and_lights.log') logging.info('Reading settings configuration file') cfg = ConfigParser() cfg.read('settings.cfg') device_cfg = ConfigParser() device_cfg.read('device_settings.cfg') logging.info('Initializing fan driver') fan = FourSpeedRealayFan(device_cfg) logging.info('Initializing LED strip driver') color_strip = ColorStrip(device_cfg, LED_FREQ_HZ) signal.signal(signal.SIGTERM, lambda: color_strip.set_color(RgbColor(0, 0, 0))) logging.info('Creating ANT+ node') node = AntPlusNode(NETWORK_KEY) try: node_stopper = TwoClientNodeStopper(node) logging.info('Attaching ANT+ heart rate monitor') hrm = node.attach_hrm() logging.info('Initializing heart rate fan controller') hfc = HRFanController(node_stopper.stop_client1, node_stopper.cancel_stop_client1, cfg, hrm, fan) logging.info('Attaching ANT+ power meter') pwr_meter = node.attach_power_meter() meter_id = node.check_id_of_power_meter() logging.info('Initializing power light controller') plc = PowerLightController(node_stopper.stop_client2, node_stopper.cancel_stop_client2, cfg, pwr_meter, color_strip) logging.info('Starting ANT+ node') node.start() except Exception as e: logging.error('Caught exception "%s"' % str(e)) raise finally: logging.info('Turning off fan') fan.select_speed(0) logging.info('Turning off LED strip') color_strip.set_color(RgbColor(0, 0, 0)) logging.info('Stopping ANT+ node') node.stop()