class GroveBoard(Board): """ Board class for Grove hardware. """ def __init__(self): super(GroveBoard, self).__init__() # pin mappings self.pin_mappings = PinMappings( air_pin=0, speaker_pin=5 ) if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata: addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0") self.pin_mappings += 512 self.air = TP401(self.pin_mappings.air_pin) self.speaker = Speaker(self.pin_mappings.speaker_pin) def update_hardware_state(self): """ Update hardware state. """ current_air_quality = self.sample_air() self.trigger_hardware_event(AIR_QUALITY, current_air_quality) # hardware functions def play_chime(self): """ Play chime. """ self.speaker.playSound("a", True, "low") self.speaker.playSound("c", True, "low") self.speaker.playSound("g", True, "low") def sample_air(self): """ Sample air. """ return self.air.getSample()
class GroveBoard(Board): """ Board class for Grove hardware. """ def __init__(self): super(GroveBoard, self).__init__() # pin mappings self.pin_mappings = PinMappings(moisture_pin=0, speaker_pin=5) if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata: addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0") self.pin_mappings += 512 self.moisture = Moisture(self.pin_mappings.moisture_pin) self.speaker = Speaker(self.pin_mappings.speaker_pin) def update_hardware_state(self): """ Update hardware state. """ moisture_reading = self.read_moisture() self.trigger_hardware_event(MOISTURE_SAMPLE, moisture_reading) # hardware functions def read_moisture(self): return self.moisture.value() def play_sound(self): self.speaker.playSound("a", True, "low") self.speaker.playSound("c", True, "low") self.speaker.playSound("g", True, "low")
class GroveBoard(Board): """ Board class for Grove hardware. """ def __init__(self): super(GroveBoard, self).__init__() # pin mappings self.pin_mappings = PinMappings(speaker_pin=5, flame_pin=4, temp_obj_pin=3, temp_ambient_pin=2, i2c_bus=6, reference_voltage=5.0) if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata: addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0") self.pin_mappings += 512 self.pin_mappings.i2c_bus = 512 self.pin_mappings.reference_voltage = 3.3 self.speaker = Speaker(self.pin_mappings.speaker_pin) self.flame = YG1006(self.pin_mappings.flame_pin) self.temp = OTP538U(self.pin_mappings.temp_ambient_pin, self.pin_mappings.temp_obj_pin, self.pin_mappings.reference_voltage) def update_hardware_state(self): """ Update hardware state. """ obj_temp = self.read_obj_temp() self.trigger_hardware_event(TEMP_READING, obj_temp) flame_detected = self.detect_flame() self.trigger_hardware_event(FLAME_DETECTED, flame_detected) # hardware functions def read_obj_temp(self): return self.temp.objectTemperature() def detect_flame(self): return self.flame.flameDetected() def play_temp(self): self.speaker.playSound("a", True, "low") self.speaker.playSound("c", True, "low") self.speaker.playSound("d", True, "low") self.speaker.playSound("b", False, "low") def play_flame(self): for _ in range(0, 10): self.speaker.playSound("a", True, "high") self.speaker.playSound("c", True, "high") self.speaker.playSound("g", True, "med")