def read_all(self): results = [] for pin_num, pin_values in self.pins.items(): data = self.pin_response(pin_num, pin_values) logger.debug('Append:', data) results.append(data) return results
def pin_write(data): logger.debug('Recieved pin:write', data) result = PIN_MANAGER.update_value(data['num'], data['value']) if not result: emit('pin:write', {'message': 'Pin not found'}) else: response = PIN_MANAGER.read_one(data['num']) emit('pin:write', response)
def load_json(self): try: with open(PINS_JSON) as file_data: self.configs = json.load(file_data) logger.info('Initialization: JSON loaded') logger.debug(self.configs) except ValueError as e: logger.error("JSON error: %s", e)
def dutycycles_write(datas): logger.debug('Recieved PWM data:', datas) for data in datas: result = PIN_MANAGER.update_dutycycles(data['num'], data['dutycycle']) if not result: logger.error('UPD DC - FAIL') emit('pin:dutycycle', {'message': 'Pin not found'}) else: logger.info('UPD DC - OK')
def read_config(self): res = [] pins = {'pins': []} arch = {'architecture': self.architecture} logger.info('Read: assembling response: config') for pin_num, pin_values in self.pins.items(): data = self.pin_response(pin_num, pin_values) pins['pins'].append(data) res.append(pins) res.append(arch) logger.info('Read: assembled response: config') logger.debug(res) return res
def update_dutycycles(self, num, dutycycle): try: logger.info('Trying to set PWM dutycycle at pin %s: %s', num, dutycycle) self.gpio.set_mode(int(num), pigpio.OUTPUT) self.gpio.set_PWM_dutycycle(int(num), dutycycle) logger.debug('Update dc: %s', num) # Updating value in object self.pins[num]['dutycycle'] = int(dutycycle) return True except KeyError: return None def update_servo(self, num, pulsewidth): pass