Exemplo n.º 1
0
    def __init__(self):

        super(GroveBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(interrupter_pin=2, uart_bus=0)

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

        self.gps_baud = HARDWARE_CONFIG.gps_baud
        self.gps = NMEAGPS(self.pin_mappings.uart_bus, self.gps_baud, -1)

        self.interrupter = RFR359F(self.pin_mappings.interrupter_pin)

        self.obj_detected_state = False
        self.nmea_stream_reader = NMEAStreamReader()
Exemplo n.º 2
0
    def __init__(self):

        super(GroveBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(
            interrupter_pin=2,
            uart_bus=0
        )

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

        self.gps_baud = HARDWARE_CONFIG.gps_baud
        self.gps = NMEAGPS(self.pin_mappings.uart_bus, self.gps_baud, -1)

        self.interrupter = RFR359F(self.pin_mappings.interrupter_pin)

        self.obj_detected_state = False
        self.nmea_stream_reader = NMEAStreamReader()
Exemplo n.º 3
0
class GroveBoard(Board):
    """
    Board class for Grove hardware.
    """
    def __init__(self):

        super(GroveBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(interrupter_pin=2, uart_bus=0)

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

        self.gps_baud = HARDWARE_CONFIG.gps_baud
        self.gps = NMEAGPS(self.pin_mappings.uart_bus, self.gps_baud, -1)

        self.interrupter = RFR359F(self.pin_mappings.interrupter_pin)

        self.obj_detected_state = False
        self.nmea_stream_reader = NMEAStreamReader()

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

        # handle gps data

        gps_data = self.query_gps()
        if gps_data:
            for gps_msg in gps_data:
                self.trigger_hardware_event(GPS_DATA_RECEIVED, gps_msg)

        # handle IR interrupter data

        obj_detected = self.detect_object()
        if self.obj_detected_state != obj_detected:

            if obj_detected:
                self.trigger_hardware_event(OBJECT_DETECTED)

            self.obj_detected_state = obj_detected

    # hardware functions
    def query_gps(self):
        """
        Query GPS receiver.
        """

        print("Running GPS query.")
        if self.gps.dataAvailable(5000):

            try:
                payload = self.gps.readStr(256).decode("utf8", "ignore")
                data = self.nmea_stream_reader.next(payload)
            except (ParseError, ChecksumError):
                print("GPS result: (Error) No Data.")
                return None

            print("GPS result: {0} messages.".format(len(data)))
            return data
        else:
            print("GPS result: No Data.")
            return None

    def detect_object(self):
        """
        Detect object.
        """

        return self.interrupter.objectDetected()
Exemplo n.º 4
0
class GroveBoard(Board):

    """
    Board class for Grove hardware.
    """

    def __init__(self):

        super(GroveBoard, self).__init__()

        # pin mappings
        self.pin_mappings = PinMappings(
            interrupter_pin=2,
            uart_bus=0
        )

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

        self.gps_baud = HARDWARE_CONFIG.gps_baud
        self.gps = NMEAGPS(self.pin_mappings.uart_bus, self.gps_baud, -1)

        self.interrupter = RFR359F(self.pin_mappings.interrupter_pin)

        self.obj_detected_state = False
        self.nmea_stream_reader = NMEAStreamReader()

    def update_hardware_state(self):

        """
        Update hardware state.
        """

        # handle gps data

        gps_data = self.query_gps()
        if gps_data:
            for gps_msg in gps_data:
                self.trigger_hardware_event(GPS_DATA_RECEIVED, gps_msg)

        # handle IR interrupter data

        obj_detected = self.detect_object()
        if self.obj_detected_state != obj_detected:

            if obj_detected:
                self.trigger_hardware_event(OBJECT_DETECTED)

            self.obj_detected_state = obj_detected

    # hardware functions
    def query_gps(self):

        """
        Query GPS receiver.
        """

        print("Running GPS query.")
        if self.gps.dataAvailable(5000):

            try:
                payload = self.gps.readStr(256).decode("utf8", "ignore")
                data = self.nmea_stream_reader.next(payload)
            except (ParseError, ChecksumError):
                print("GPS result: (Error) No Data.")
                return None

            print("GPS result: {0} messages.".format(len(data)))
            return data
        else:
            print("GPS result: No Data.")
            return None

    def detect_object(self):

        """
        Detect object.
        """

        return self.interrupter.objectDetected()