diff --git a/project/main.py b/project/main.py index 2af623014c2219ce4e40cbdda0fccc8a80c1d2d3..594b6a62e78c3560aa379acc0f20bdb18be11c26 100644 --- a/project/main.py +++ b/project/main.py @@ -14,7 +14,7 @@ from reader import Reader # Objects power_button = Pin(15, Pin.IN, Pin.PULL_DOWN) -buzzer_pin =Pin(14, Pin.OUT) +buzzer_pin = Pin(14, Pin.OUT) m5_power = Pin(13) m5_power.init(Pin.OUT) m5_power.value(0) @@ -27,24 +27,28 @@ sp = None # M5Stack Module object reader = None xPower = False -rtc=RTC() -def response(message:str): - return "Reponse["+message+"]" +rtc = RTC() + + +def response(message: str): + return "Reponse[" + message + "]" + + def play_tone(frequency, duration, duty): buzzer.freq(frequency) buzzer.duty_u16(duty) sleep_ms(duration) buzzer.duty_u16(0) sleep_ms(duration) + + last_action = rtc.datetime() while True: - # if rtc.datetime(): - # print("Hello") if power_button.value(): sleep(0.5) if xPower: - xPower=False - sp.send(response("Device + Bluetooth Desconnected")) + xPower = False + # sp.send(response("Device + Bluetooth Disconnected")) sp.desonnect() ble = None sp = None @@ -54,15 +58,15 @@ while True: play_tone(250, 200, 4000) play_tone(200, 150, 4000) m5_power.value(0) - #machine.freq(20000000) + # machine.freq(20000000) else: - #machine.freq() - xPower=True + # machine.freq() + xPower = True ble = BLE() sp = BLESimplePeripheral(ble) - if sp.is_connected(): - sp.send(str(response("Device + Bluetooth Connected"))) - reader = Reader(115200,12,1) + # if sp.is_connected(): + # sp.send(str(response("Device + Bluetooth Connected"))) + reader = Reader(115200, 12, 1) reader.init_reader() play_tone(500, 100, 5000) play_tone(400, 200, 4000) @@ -71,7 +75,8 @@ while True: if xPower: r = reader.read_epc() if r: - #print(r) + print(r) play_tone(500, 110, 4000) if sp.is_connected(): - sp.send(str(r)) \ No newline at end of file + #sp.send("00") + sp.write(str(r)) diff --git a/project/reader.py b/project/reader.py index b4bc4fec8951ea4d035e95123a1766227b2e32a7..426ba598c1fc8b318645ff7ab78a0f8b5acdc626 100644 --- a/project/reader.py +++ b/project/reader.py @@ -12,19 +12,21 @@ from time import sleep_ms ' M5Stack Commands ''' M5C = { - "hardware_version" : [0xBB, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x7E], - "start_multi_plling": [0xBB,0x00,0x27,0x00,0x03,0x22,0x27,0x10,0x83,0x7E], - "start_single_polling": [0xBB,0x00,0x22,0x00,0x00,0x22,0x7E], - "stop_multid_polling" : [0xBB,0x00,0x28,0x00,0x00,0x28,0x7E] + "hardware_version": [0xBB, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x7E], + "start_multi_plling": [0xBB, 0x00, 0x27, 0x00, 0x03, 0x22, 0x27, 0x10, 0x83, 0x7E], + "start_single_polling": [0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E], + "stop_multid_polling": [0xBB, 0x00, 0x28, 0x00, 0x00, 0x28, 0x7E] } ''' ' Reader Class to run M5Stack ''' -class Reader: + +class Reader: ''' ' In Constructor only object instance of UART Protocol ''' + def __init__(self, baudrate: int, tx_pin: int, rx_pin: int): self.__uart = UART(0, baudrate=baudrate, tx=Pin(tx_pin), rx=Pin(rx_pin)) self.init_reader() @@ -32,6 +34,7 @@ class Reader: ''' ' Send command to read tags ''' + def _send_command(self, command: list): self.__uart.write(bytearray(command)) sleep_ms(50) # Allow time for the command to be processed @@ -39,6 +42,7 @@ class Reader: ''' ' Init function to check reader functionality ''' + def init_reader(self): self._send_command(M5C['hardware_version']) response = self.__uart.read() @@ -50,11 +54,13 @@ class Reader: ''' ' catch epc's once available reader functionality ''' + def read_epc(self): if self.__uart.any(): resp = self.__uart.read() - if len(resp) == 24: + # if len(resp) == 24: + if len(resp) > 10: return resp else: self._send_command(M5C['start_single_polling']) - return False \ No newline at end of file + return False