diff --git a/README.md b/README.md index 2d1bc9f..86085b0 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,32 @@ Haptic configuration tool ## Connecting your Nano -TODO \ No newline at end of file +Plug the nano to the USB port. :-) + +ZERO/ONE will automatically detect the Nano_D++ device. + +### Device connection states + +The connection between the device and the haptic controller software can be in the following states. Entering each state is associated with equivalent events emitted in the ZERO/ONE software: + +**Attached** + +The device is attached when it is connected to USB. + +**Detached** + +The device is detached when disconnected from USB. + +**Connected** + +The device is in connected state when the USB serial port is successfully opened. + +**Disconnected** + +The device enters disconnected state when the USB serial port is closed. + +Note that a **connected** device is also always **attached**, and if the USB plug is pulled on a **connected** device, it becomes both **disconnected** and **detached** simultaneously. If the connection is closed without disconnecting USB, the device becomes **disconnected** but remains **attached**. + + + + diff --git a/src/App.vue b/src/App.vue index b2627d0..8515351 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,6 +4,7 @@ import DevicePreview from '@/components/device/DevicePreview.vue' import ConfigPane from '@/components/config/ConfigPane.vue' import Navbar from '@/components/navbar/Navbar.vue' import { useStore } from '@/store' +import { useMessageHandlers } from '@/device' const { electron } = window const store = useStore() @@ -21,7 +22,18 @@ electron?.onMenu((key) => { } }) -store.fetchProfiles() +store.fetchProfiles() // TODO remove me! + +// handle device events +const handlers = useMessageHandlers(store) +window.nanodevices.on_event('device-attached', (evt, deviceid, data) => store.device_attached(deviceid)) +window.nanodevices.on_event('device-detached', (evt, deviceid, data) => store.device_detached(deviceid)) +window.nanodevices.on_event('device-error', (evt, deviceid, data) => { /* TODO handle connection errors */ }) +window.nanodevices.on_event('connected', (evt, deviceid, data) => store.device_connected(deviceid)) +window.nanodevices.on_event('disconnected', (evt, deviceid, data) => store.device_disconnected(deviceid)) +window.nanodevices.on_event('update', (evt, deviceid, data) => { handlers.handle_message(data) }) +// get list of the currently attached devices +window.nanodevices.list_devices().then((devs)=>store.init_devices(devs))