class DfrobotBoard(Board):

    """
    Board class for drobot hardware.
    """

    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(
            buzzer_pin=15,
            button_pin=16,
            rotary_pin=3,
            screen_register_select_pin=8,
            screen_enable_pin=9,
            screen_data_0_pin=4,
            screen_data_1_pin=5,
            screen_data_2_pin=6,
            screen_data_3_pin=7,
            screen_analog_input_pin=0,
        )

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512

        self.screen = SAINSMARTKS(
            self.pin_mappings.screen_register_select_pin,
            self.pin_mappings.screen_enable_pin,
            self.pin_mappings.screen_data_0_pin,
            self.pin_mappings.screen_data_1_pin,
            self.pin_mappings.screen_data_2_pin,
            self.pin_mappings.screen_data_3_pin,
            self.pin_mappings.screen_analog_input_pin,
        )

        self.buzzer = Gpio(self.pin_mappings.buzzer_pin)
        self.rotary = Rotary(self.pin_mappings.rotary_pin)
        self.button = Button(self.pin_mappings.button_pin)

        self.buzzer.dir(DIR_OUT)

        self.rotary_value = 0
        self.button_state = False

    def update_hardware_state(self):

        """
        Update hardware state.
        """

        current_rotary_value = self.read_rotary()
        if current_rotary_value != self.rotary_value:
            self.trigger_hardware_event(ROTARY, current_rotary_value)
            self.rotary_value = current_rotary_value

        current_button_state = self.button.value()
        if current_button_state != self.button_state:
            if not current_button_state:
                self.trigger_hardware_event(BUTTON_RELEASED)
            self.button_state = current_button_state

    # hardware functions
    def start_buzzer(self):

        """
        Start the hardware buzzer.
        """

        self.buzzer.write(1)

    def stop_buzzer(self):

        """
        Stop the hardware buzzer.
        """

        self.buzzer.write(0)

    def read_rotary(self):

        """
        Read rotary value.
        """

        return self.rotary.abs_value()

    def write_message(self, message, line=0):

        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)

    def change_background(self, color):

        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass

    def change_brightness(self, value):

        """
        Change LCD screen brightness.
        Only supports on (value < 512) and off (value >= 512) on the dfrobot.
        """

        if value < 512:
            self.screen.displayOff()
        else:
            self.screen.displayOn()
class DfrobotBoard(Board):

    """
    Board class for drobot hardware.
    """

    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(
            buzzer_pin=15,
            button_pin=16,
            rotary_pin=3,
            screen_register_select_pin=8,
            screen_enable_pin=9,
            screen_data_0_pin=4,
            screen_data_1_pin=5,
            screen_data_2_pin=6,
            screen_data_3_pin=7,
            screen_analog_input_pin=0
        )

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512

        self.screen = SAINSMARTKS(
            self.pin_mappings.screen_register_select_pin,
            self.pin_mappings.screen_enable_pin,
            self.pin_mappings.screen_data_0_pin,
            self.pin_mappings.screen_data_1_pin,
            self.pin_mappings.screen_data_2_pin,
            self.pin_mappings.screen_data_3_pin,
            self.pin_mappings.screen_analog_input_pin
        )

        self.buzzer = Gpio(self.pin_mappings.buzzer_pin)
        self.rotary = Rotary(self.pin_mappings.rotary_pin)
        self.button = Button(self.pin_mappings.button_pin)

        self.buzzer.dir(DIR_OUT)

        self.rotary_value = 0
        self.button_state = False

    def update_hardware_state(self):

        """
        Update hardware state.
        """

        current_rotary_value = self.read_rotary()
        if current_rotary_value != self.rotary_value:
            self.trigger_hardware_event(ROTARY, current_rotary_value)
            self.rotary_value = current_rotary_value

        current_button_state = self.button.value()
        if current_button_state != self.button_state:
            if not current_button_state:
                self.trigger_hardware_event(BUTTON_RELEASED)
            self.button_state = current_button_state

    # hardware functions
    def start_buzzer(self):

        """
        Start the hardware buzzer.
        """

        self.buzzer.write(1)

    def stop_buzzer(self):

        """
        Stop the hardware buzzer.
        """

        self.buzzer.write(0)

    def read_rotary(self):

        """
        Read rotary value.
        """

        return self.rotary.abs_value()

    def write_message(self, message, line=0):

        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)

    def change_background(self, color):

        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass

    def change_brightness(self, value):

        """
        Change LCD screen brightness.
        Only supports on (value < 512) and off (value >= 512) on the dfrobot.
        """

        if value < 512:
            self.screen.displayOff()
        else:
            self.screen.displayOn()
class DfrobotBoard(Board):

    """
    Board class for drobot hardware.
    """

    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(
            motion_pin=16,
            screen_register_select_pin=8,
            screen_enable_pin=9,
            screen_data_0_pin=4,
            screen_data_1_pin=5,
            screen_data_2_pin=6,
            screen_data_3_pin=7,
            screen_analog_input_pin=0
        )

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512

        self.motion = BISS0001(self.pin_mappings.motion_pin)

        self.screen = SAINSMARTKS(
            self.pin_mappings.screen_register_select_pin,
            self.pin_mappings.screen_enable_pin,
            self.pin_mappings.screen_data_0_pin,
            self.pin_mappings.screen_data_1_pin,
            self.pin_mappings.screen_data_2_pin,
            self.pin_mappings.screen_data_3_pin,
            self.pin_mappings.screen_analog_input_pin
        )

        self.last_motion = False

    def update_hardware_state(self):

        """
        Update hardware state.
        """

        # detect motion change
        current_motion = self.detect_motion()
        if current_motion != self.last_motion:
            if current_motion:
                self.trigger_hardware_event(MOTION_DETECTED)

            self.last_motion = current_motion

    # hardware functions
    def detect_motion(self):

        """
        Check PIR motion sensor.
        """

        return self.motion.motionDetected()

    def write_message(self, message, line=0):

        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)

    def change_background(self, color):

        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass
class DfrobotBoard(Board):

    """
    Board class for drobot hardware.
    """

    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(
            mic_pin=2,
            screen_register_select_pin=8,
            screen_enable_pin=9,
            screen_data_0_pin=4,
            screen_data_1_pin=5,
            screen_data_2_pin=6,
            screen_data_3_pin=7,
            screen_analog_input_pin=0
        )

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512

        self.screen = SAINSMARTKS(
            self.pin_mappings.screen_register_select_pin,
            self.pin_mappings.screen_enable_pin,
            self.pin_mappings.screen_data_0_pin,
            self.pin_mappings.screen_data_1_pin,
            self.pin_mappings.screen_data_2_pin,
            self.pin_mappings.screen_data_3_pin,
            self.pin_mappings.screen_analog_input_pin
        )

        self.mic = Loudness(self.pin_mappings.mic_pin)

    def update_hardware_state(self):

        """
        Update hardware state.
        """

        self.trigger_hardware_event(SOUND_MEASUREMENT, self.measure_volume())

    # hardware functions
    def measure_volume(self):

        """
        Measure the average volume
        """

        noise = self.mic.loudness()
        in_min = 1
        in_max = 5
        out_min = 0
        out_max = 100
        average = (in_min - noise) * (out_max - out_min) / (in_max - in_min) + out_min
        return round(average, 2)

    def write_message(self, message, line=0):

        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)

    def change_background(self, color):

        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass
class DfrobotBoard(Board):
    """
    Board class for drobot hardware.
    """
    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(mic_pin=2,
                                        screen_register_select_pin=8,
                                        screen_enable_pin=9,
                                        screen_data_0_pin=4,
                                        screen_data_1_pin=5,
                                        screen_data_2_pin=6,
                                        screen_data_3_pin=7,
                                        screen_analog_input_pin=0)

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512

        self.screen = SAINSMARTKS(self.pin_mappings.screen_register_select_pin,
                                  self.pin_mappings.screen_enable_pin,
                                  self.pin_mappings.screen_data_0_pin,
                                  self.pin_mappings.screen_data_1_pin,
                                  self.pin_mappings.screen_data_2_pin,
                                  self.pin_mappings.screen_data_3_pin,
                                  self.pin_mappings.screen_analog_input_pin)

        self.mic = Loudness(self.pin_mappings.mic_pin)

    def update_hardware_state(self):
        """
        Update hardware state.
        """

        self.trigger_hardware_event(SOUND_MEASUREMENT, self.measure_volume())

    # hardware functions
    def measure_volume(self):
        """
        Measure the average volume
        """

        noise = self.mic.loudness()
        in_min = 1
        in_max = 5
        out_min = 0
        out_max = 100
        average = (in_min - noise) * (out_max - out_min) / (in_max -
                                                            in_min) + out_min
        return round(average, 2)

    def write_message(self, message, line=0):
        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)

    def change_background(self, color):
        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass
Пример #6
0
class DfrobotBoard(Board):

    """
    Board class for drobot hardware.
    """

    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(
            sound_pin=2,
            vibration_pin=15,
            screen_register_select_pin=8,
            screen_enable_pin=9,
            screen_data_0_pin=4,
            screen_data_1_pin=5,
            screen_data_2_pin=6,
            screen_data_3_pin=7,
            screen_analog_input_pin=0
        )

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512

        self.screen = SAINSMARTKS(
            self.pin_mappings.screen_register_select_pin,
            self.pin_mappings.screen_enable_pin,
            self.pin_mappings.screen_data_0_pin,
            self.pin_mappings.screen_data_1_pin,
            self.pin_mappings.screen_data_2_pin,
            self.pin_mappings.screen_data_3_pin,
            self.pin_mappings.screen_analog_input_pin
        )

        self.sound = Microphone(self.pin_mappings.sound_pin)
        self.sound_ctx = thresholdContext()
        self.sound_ctx.averageReading = 0
        self.sound_ctx.runningAverage = 0
        self.sound_ctx.averagedOver = 2

        self.vibration = Button(self.pin_mappings.vibration_pin)

        self.sample_time = 2
        self.sample_number = 128

    def update_hardware_state(self):

        """
        Update hardware state.
        """

        vibration_sample = self.measure_vibration()
        self.trigger_hardware_event(VIBRATION_SAMPLE, vibration_sample)

        noise_sample = self.measure_sound()
        self.trigger_hardware_event(NOISE_SAMPLE, noise_sample)

    # hardware functions
    def measure_vibration(self):

        """
        Measure average vibration.
        """

        vibration = self.vibration.value()
        return 200 if vibration else 0

    def measure_sound(self):

        """
        Measure average volume.
        """

        samples = uint16Array(128)
        length = self.sound.getSampledWindow(self.sample_time, self.sample_number, samples)

        if not length:
            return 0

        noise = self.sound.findThreshold(self.sound_ctx, 30, samples, length)
        average = noise / 100
        return average

    def write_message(self, message, line=0):

        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)

    def change_background(self, color):

        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass
class DfrobotBoard(Board):

    """
    Board class for drobot hardware.
    """

    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(
            touch_pin=16,
            buzzer_pin=15,
            screen_register_select_pin=8,
            screen_enable_pin=9,
            screen_data_0_pin=4,
            screen_data_1_pin=5,
            screen_data_2_pin=6,
            screen_data_3_pin=7,
            screen_analog_input_pin=0
        )

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512

        self.screen = SAINSMARTKS(
            self.pin_mappings.screen_register_select_pin,
            self.pin_mappings.screen_enable_pin,
            self.pin_mappings.screen_data_0_pin,
            self.pin_mappings.screen_data_1_pin,
            self.pin_mappings.screen_data_2_pin,
            self.pin_mappings.screen_data_3_pin,
            self.pin_mappings.screen_analog_input_pin
        )

        self.touch = Button(self.pin_mappings.touch_pin)
        self.buzzer = Gpio(self.pin_mappings.buzzer_pin)

        self.buzzer.dir(DIR_OUT)

        self.touch_state = False
        self.stop_buzzer()

    def update_hardware_state(self):

        """
        Update hardware state.
        """

        current_touch_state = self.detect_touch()
        if self.touch_state != current_touch_state:

            if current_touch_state:
                self.trigger_hardware_event(TOUCH_DOWN)
            else:
                self.trigger_hardware_event(TOUCH_UP)

            self.touch_state = current_touch_state

    # hardware functions
    def detect_touch(self):

        """
        Detect touch state.
        """

        return self.touch.value()

    def start_buzzer(self):

        """
        Start buzzer.
        """

        self.buzzer.write(1)

    def stop_buzzer(self):

        """
        Stop buzzer.
        """

        self.buzzer.write(0)

    def write_message(self, message, line=0):

        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)
        print(message)

    def change_background(self, color):

        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass
class DfrobotBoard(Board):

    """
    Board class for drobot hardware.
    """

    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(
            temperature_pin=2,
            buzzer_pin=15,
            screen_register_select_pin=8,
            screen_enable_pin=9,
            screen_data_0_pin=4,
            screen_data_1_pin=5,
            screen_data_2_pin=6,
            screen_data_3_pin=7,
            screen_analog_input_pin=0
        )
        self.voltage_adjust = 1.0

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512
            self.voltage_adjust = 0.66

        self.screen = SAINSMARTKS(
            self.pin_mappings.screen_register_select_pin,
            self.pin_mappings.screen_enable_pin,
            self.pin_mappings.screen_data_0_pin,
            self.pin_mappings.screen_data_1_pin,
            self.pin_mappings.screen_data_2_pin,
            self.pin_mappings.screen_data_3_pin,
            self.pin_mappings.screen_analog_input_pin
        )

        self.temperature = LM35(self.pin_mappings.temperature_pin)
        self.temperature.setScale(self.voltage_adjust)

        self.buzzer = Gpio(self.pin_mappings.buzzer_pin)
        self.buzzer.dir(DIR_OUT)

    def update_hardware_state(self):

        """
        Update hardware state.
        """

        current_temp = self.read_temperature()
        self.trigger_hardware_event(TEMPRETURE_CHANGED, current_temp)

    # hardware functions
    def read_temperature(self):

        """
        Read temperature value in Celcius.
        """

        return self.temperature.getTemperature() * self.voltage_adjust

    def start_buzzer(self):

        """
        Start buzzer.
        """

        self.buzzer.write(1)

    def stop_buzzer(self):

        """
        Stop buzzer.
        """

        self.buzzer.write(0)

    def write_message(self, message, line=0):

        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)

    def change_background(self, color):

        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass
Пример #9
0
class DfrobotBoard(Board):
    """
    Board class for drobot hardware.
    """
    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(touch_pin=16,
                                        buzzer_pin=15,
                                        screen_register_select_pin=8,
                                        screen_enable_pin=9,
                                        screen_data_0_pin=4,
                                        screen_data_1_pin=5,
                                        screen_data_2_pin=6,
                                        screen_data_3_pin=7,
                                        screen_analog_input_pin=0)

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512

        self.screen = SAINSMARTKS(self.pin_mappings.screen_register_select_pin,
                                  self.pin_mappings.screen_enable_pin,
                                  self.pin_mappings.screen_data_0_pin,
                                  self.pin_mappings.screen_data_1_pin,
                                  self.pin_mappings.screen_data_2_pin,
                                  self.pin_mappings.screen_data_3_pin,
                                  self.pin_mappings.screen_analog_input_pin)

        self.touch = Button(self.pin_mappings.touch_pin)
        self.buzzer = Gpio(self.pin_mappings.buzzer_pin)

        self.buzzer.dir(DIR_OUT)

        self.touch_state = False
        self.stop_buzzer()

    def update_hardware_state(self):
        """
        Update hardware state.
        """

        current_touch_state = self.detect_touch()
        if self.touch_state != current_touch_state:

            if current_touch_state:
                self.trigger_hardware_event(TOUCH_DOWN)
            else:
                self.trigger_hardware_event(TOUCH_UP)

            self.touch_state = current_touch_state

    # hardware functions
    def detect_touch(self):
        """
        Detect touch state.
        """

        return self.touch.value()

    def start_buzzer(self):
        """
        Start buzzer.
        """

        self.buzzer.write(1)

    def stop_buzzer(self):
        """
        Stop buzzer.
        """

        self.buzzer.write(0)

    def write_message(self, message, line=0):
        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)
        print(message)

    def change_background(self, color):
        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass
class DfrobotBoard(Board):
    """
    Board class for drobot hardware.
    """
    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(temperature_pin=2,
                                        buzzer_pin=15,
                                        screen_register_select_pin=8,
                                        screen_enable_pin=9,
                                        screen_data_0_pin=4,
                                        screen_data_1_pin=5,
                                        screen_data_2_pin=6,
                                        screen_data_3_pin=7,
                                        screen_analog_input_pin=0)
        self.voltage_adjust = 1.0

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512
            self.voltage_adjust = 0.66

        self.screen = SAINSMARTKS(self.pin_mappings.screen_register_select_pin,
                                  self.pin_mappings.screen_enable_pin,
                                  self.pin_mappings.screen_data_0_pin,
                                  self.pin_mappings.screen_data_1_pin,
                                  self.pin_mappings.screen_data_2_pin,
                                  self.pin_mappings.screen_data_3_pin,
                                  self.pin_mappings.screen_analog_input_pin)

        self.temperature = LM35(self.pin_mappings.temperature_pin)
        self.temperature.setScale(self.voltage_adjust)

        self.buzzer = Gpio(self.pin_mappings.buzzer_pin)
        self.buzzer.dir(DIR_OUT)

    def update_hardware_state(self):
        """
        Update hardware state.
        """

        current_temp = self.read_temperature()
        self.trigger_hardware_event(TEMPRETURE_CHANGED, current_temp)

    # hardware functions
    def read_temperature(self):
        """
        Read temperature value in Celcius.
        """

        return self.temperature.getTemperature() * self.voltage_adjust

    def start_buzzer(self):
        """
        Start buzzer.
        """

        self.buzzer.write(1)

    def stop_buzzer(self):
        """
        Stop buzzer.
        """

        self.buzzer.write(0)

    def write_message(self, message, line=0):
        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)

    def change_background(self, color):
        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass
class DfrobotBoard(Board):
    """
    Board class for drobot hardware.
    """
    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(accel_x_pin=3,
                                        accel_y_pin=2,
                                        accel_z_pin=1,
                                        screen_register_select_pin=8,
                                        screen_enable_pin=9,
                                        screen_data_0_pin=4,
                                        screen_data_1_pin=5,
                                        screen_data_2_pin=6,
                                        screen_data_3_pin=7,
                                        screen_analog_input_pin=0)

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512

        self.screen = SAINSMARTKS(self.pin_mappings.screen_register_select_pin,
                                  self.pin_mappings.screen_enable_pin,
                                  self.pin_mappings.screen_data_0_pin,
                                  self.pin_mappings.screen_data_1_pin,
                                  self.pin_mappings.screen_data_2_pin,
                                  self.pin_mappings.screen_data_3_pin,
                                  self.pin_mappings.screen_analog_input_pin)

        # accelerometer setup
        self.ax = Aio(self.pin_mappings.accel_x_pin)
        self.ay = Aio(self.pin_mappings.accel_y_pin)
        self.az = Aio(self.pin_mappings.accel_z_pin)

        self.acceleration_detected = False

    def update_hardware_state(self):
        """
        Update hardware state.
        """

        current_acceleration = self.detect_acceleration()
        if current_acceleration != self.acceleration_detected:
            if current_acceleration:
                self.trigger_hardware_event(ACCELERATION_DETECTED)
            self.acceleration_detected = current_acceleration

    # hardware functions
    def detect_acceleration(self):
        """
        Detect acceleration change.
        """

        ax = self.ax.read()
        ay = self.ay.read()
        az = self.az.read()

        if ax > 412 or ay > 412 or az > 412:
            return True
        else:
            return False

    def write_message(self, message, line=0):
        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)
        print(message)

    def change_background(self, color):
        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass
class DfrobotBoard(Board):

    """
    Board class for drobot hardware.
    """

    def __init__(self):

        super(DfrobotBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(
            accel_x_pin=3,
            accel_y_pin=2,
            accel_z_pin=1,
            screen_register_select_pin=8,
            screen_enable_pin=9,
            screen_data_0_pin=4,
            screen_data_1_pin=5,
            screen_data_2_pin=6,
            screen_data_3_pin=7,
            screen_analog_input_pin=0
        )

        if HARDWARE_CONFIG.platform == KNOWN_PLATFORMS.firmata:
            addSubplatform(GENERIC_FIRMATA, "/dev/ttyACM0")
            self.pin_mappings += 512

        self.screen = SAINSMARTKS(
            self.pin_mappings.screen_register_select_pin,
            self.pin_mappings.screen_enable_pin,
            self.pin_mappings.screen_data_0_pin,
            self.pin_mappings.screen_data_1_pin,
            self.pin_mappings.screen_data_2_pin,
            self.pin_mappings.screen_data_3_pin,
            self.pin_mappings.screen_analog_input_pin
        )

        # accelerometer setup
        self.ax = Aio(self.pin_mappings.accel_x_pin)
        self.ay = Aio(self.pin_mappings.accel_y_pin)
        self.az = Aio(self.pin_mappings.accel_z_pin)

        self.acceleration_detected = False

    def update_hardware_state(self):

        """
        Update hardware state.
        """

        current_acceleration = self.detect_acceleration()
        if current_acceleration != self.acceleration_detected:
            if current_acceleration:
                self.trigger_hardware_event(ACCELERATION_DETECTED)
            self.acceleration_detected = current_acceleration

    # hardware functions
    def detect_acceleration(self):

        """
        Detect acceleration change.
        """

        ax = self.ax.read()
        ay = self.ay.read()
        az = self.az.read()

        if ax > 412 or ay > 412 or az > 412:
            return True
        else:
            return False

    def write_message(self, message, line=0):

        """
        Write message to LCD screen.
        """

        message = message.ljust(16)
        self.screen.setCursor(line, 0)
        self.screen.write(message)
        print(message)

    def change_background(self, color):

        """
        Change LCD screen background color.
        No effect on the dfrobot.
        """

        pass