# ble.py - ASM001/ASM002 BLE Driver # # Note: You should copy this module to your OpenMV Cam's SD card or internal # file system. # # This is a driver for the ASM001/ASM002 BLE modules. It takes care of parsing # commands for you. Please see the http://truconnect.ack.me/2.0/general_overview # reference guide for how to use the ASM001/ASM002 BLE modules. from time import sleep from pyb import Pin, UART class BLE: BLE_NONE=0 BLE_SHIELD=1 def command(self, cmd): if self.type==self.BLE_SHIELD: self.uart.write(cmd) self.uart.write("\r\n") r=self.uart.read(9) if r[0]!=82: raise OSError("Response corrupted!") if r[1]==49: raise OSError("Command failed!") if r[1]==50: raise OSError("Parse error!") if r[1]==51: raise OSError("Unknown command!") if r[1]==52: raise OSError("Too few args!") if r[1]==53: raise OSError("Too many args!") if r[1]==54: raise OSError("Unknown variable or option!") if r[1]==55: raise OSError("Invalid argument!") if r[1]==56: raise OSError("Timeout!") if r[1]==57: raise OSError("Security mismatch!") if r[1]!=48: raise OSError("Response corrupted!") for i in range(2,6): if r[i]<48 or 57