diff --git a/boards/HDK/MixGo_MINI-V1.7.pdf b/boards/HDK/MixGo_MINI-V1.7.pdf new file mode 100644 index 00000000..c1375140 Binary files /dev/null and b/boards/HDK/MixGo_MINI-V1.7.pdf differ diff --git a/boards/default_src/micropython/origin/build/lib/adxl345.py b/boards/default_src/micropython/origin/build/lib/adxl345.py index 3ea21da9..5ce18442 100644 --- a/boards/default_src/micropython/origin/build/lib/adxl345.py +++ b/boards/default_src/micropython/origin/build/lib/adxl345.py @@ -1,56 +1,52 @@ -#ADXL345 -import time -import ustruct -from micropython import const - -DATA_FORMAT = const(0x31) -BW_RATE = const(0x2c) -POWER_CTL = const(0x2d) -INT_ENABLE = const(0x2E) -OFSX = const(0x1e) -OFSY = const(0x1f) -OFSZ = const(0x20) - -class ADXL345: - def __init__(self, i2c, address=0X53): - self._device = i2c - self._address = address - for addr in self._device.scan(): - if self._device.readfrom_mem(addr, 0, 1)[0] == 0xe5: - self._address = addr - break - else: - raise AttributeError("Cannot find a ADXL345") - - self._wreg(DATA_FORMAT,0x2B) #16g量程 - self._wreg(BW_RATE,0x0A) #数据输出速度为100Hz - self._wreg(INT_ENABLE,0x00) #不使用中断 - - self._wreg(OFSX,0x00) - self._wreg(OFSY,0x00) - self._wreg(OFSZ,0x00) - self._wreg(POWER_CTL,0x08) #链接使能,测量模式 - time.sleep(0.5) - - def readXYZ(self): - x, = ustruct.unpack(' 5: break + _keys[i] = general[i] + else: + _keys[0] = general + # Pack the mouse state as described by the input report + self._ble.gatts_notify(self.conn_handle, self.h_rep, bytes([special & 0xFF, 0]) + _keys) + if release: + time.sleep_ms(10) + self._ble.gatts_notify(self.conn_handle, self.h_rep, b'\x00\x00\x00\x00\x00\x00\x00\x00') + + def notify_battery(self, level): + if self.is_connected(): + self.battery_level = max(min(level, 100), 0) + # Notifies the client by writing to the battery level handle. + self._ble.gatts_notify(self.conn_handle, self.h_bat, struct.pack("> 7 else 0x00, _KEYCODE[char] & 0x7F) + time.sleep_ms(20 + delay) + + @property + def mac(self): + '''Get mac address''' + return hexlify(self._ble.config('mac')[1]).decode() diff --git a/boards/default_src/micropython/origin/build/lib/ble_hid_mouse.py b/boards/default_src/micropython/origin/build/lib/ble_hid_mouse.py new file mode 100644 index 00000000..68e345ae --- /dev/null +++ b/boards/default_src/micropython/origin/build/lib/ble_hid_mouse.py @@ -0,0 +1,152 @@ +""" +Bluetooth-HID-Mouse + +Micropython library for the Bluetooth-HID-Mouse +======================================================= +#https://github.com/Heerkog/MicroPythonBLEHID + +@dahanzimin From the Mixly Team +""" +import bluetooth +import struct, time +from micropython import const +from ubinascii import hexlify +from ble_advertising import advertising_payload +from bluetooth import UUID, FLAG_READ, FLAG_WRITE ,FLAG_NOTIFY, FLAG_WRITE_NO_RESPONSE + +_IRQ_CENTRAL_CONNECT = const(1) +_IRQ_CENTRAL_DISCONNECT = const(2) +_IRQ_MTU_EXCHANGED = const(21) +_IRQ_CONNECTION_UPDATE = const(27) +_IRQ_PASSKEY_ACTION = const(31) +_PASSKEY_ACTION_INPUT = const(2) +_PASSKEY_ACTION_DISP = const(3) +_PASSKEY_ACTION_NUMCMP = const(4) + +_HID_INPUT_REPORT = const(b'\x05\x01\t\x02\xa1\x01\x85\x01\t\x01\xa1\x00\x05\t\x19\x01)\x03\x15\x00%\x01\x95\x03u\x01\x81\x02\x95\x01u\x05\x81\x03\x05\x01\t0\t1\t8\x15\x81%\x7fu\x08\x95\x03\x81\x06\xc0\xc0') + +_DIS = (UUID(0x180A), ( (UUID(0x2A24), FLAG_READ), + (UUID(0x2A25), FLAG_READ), + (UUID(0x2A26), FLAG_READ), + (UUID(0x2A27), FLAG_READ), + (UUID(0x2A28), FLAG_READ), + (UUID(0x2A29), FLAG_READ), + (UUID(0x2A50), FLAG_READ), ), ) + +_BAS = (UUID(0x180F), ( (UUID(0x2A19), FLAG_READ | FLAG_NOTIFY, ( + (UUID(0x2902), 0x01 | 0x02), + (UUID(0x2904), 0x01),)), ), ) + +_HIDS = (UUID(0x1812), ((UUID(0x2A4A), FLAG_READ), + (UUID(0x2A4B), FLAG_READ), + (UUID(0x2A4C), FLAG_READ | FLAG_WRITE | FLAG_WRITE_NO_RESPONSE), + (UUID(0x2A4D), FLAG_READ | FLAG_NOTIFY, ( + (UUID(0x2902), 0x01 | 0x02), + (UUID(0x2908), 0x01 | 0x02), )), + (UUID(0x2A4E), FLAG_READ | FLAG_WRITE | FLAG_WRITE_NO_RESPONSE), ), ) + +class Mouse: + def __init__(self, name=None, passkey=1234, battery_level=100): + if (name is '') or (name is None): + name = "Mixgo_" + self.mac[-6:].upper() + print("Mouse name:", name) + + self._ble = bluetooth.BLE() + self._ble.active(True) + self._ble.irq(self._irq) + self._ble.config(gap_name=name) + self._ble.config(mtu=23) + self.device_state = False + self.conn_handle = None + self.passkey = passkey + self.battery_level = battery_level + + handles = self._ble.gatts_register_services((_DIS, _BAS, _HIDS)) + self._service_characteristics(handles) + self._payload = advertising_payload(name=name, services=[UUID(0x1812)], appearance=const(962)) + self.advertise() + + def _irq(self, event, data): + # Interrupt request callback function + if event == _IRQ_CENTRAL_CONNECT: + self.conn_handle, _, _ = data + print("Mouse connected: ", self.conn_handle) + self.device_state = True + elif event == _IRQ_CENTRAL_DISCONNECT: + self.conn_handle = None + conn_handle, addr_type, addr = data + print("Mouse disconnected: ", conn_handle) + self.advertise() + self.device_state = False + elif event == _IRQ_MTU_EXCHANGED: + conn_handle, mtu = data + self._ble.config(mtu=mtu) + print("MTU exchanged: ", mtu) + elif event == _IRQ_CONNECTION_UPDATE: + self.conn_handle, _, _, _, _ = data + print("Connection update") + elif event == _IRQ_PASSKEY_ACTION: + conn_handle, action, passkey = data + print("Passkey action", conn_handle, action, passkey) + if action == _PASSKEY_ACTION_NUMCMP: + self._ble.gap_passkey(conn_handle, action, False) + elif action == _PASSKEY_ACTION_DISP: + print("Displaying passkey") + self._ble.gap_passkey(conn_handle, action, self.passkey) + elif action == _PASSKEY_ACTION_INPUT: + print(" Prompting for passkey") + self._ble.gap_passkey(conn_handle, action, None) + else: + print("unknown action") + #else: + #print("Unhandled IRQ event: ", event, data) + + def _service_characteristics(self, handles): + (h_mod, h_ser, h_fwr, h_hwr, h_swr, h_man, h_pnp) = handles[0] + (self.h_bat, h_ccc, h_bfmt,) = handles[1] + (h_info, h_hid, h_ctrl, self.h_rep, _, h_d1, h_proto) = handles[2] + + # Write DIS characteristics. + self._ble.gatts_write(h_mod, b'1') + self._ble.gatts_write(h_ser, b'1') + self._ble.gatts_write(h_fwr, b'1') + self._ble.gatts_write(h_hwr, b'1') + self._ble.gatts_write(h_swr, b'1') + self._ble.gatts_write(h_man, b'Homebrew') + self._ble.gatts_write(h_pnp, struct.pack("