Last active
November 17, 2020 09:57
-
-
Save apostopher/8217793985b532f9b67d065b80379f9e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const bleMachine = Machine( | |
{ | |
id: 'BLEMachine', | |
context: { | |
measurements: {}, | |
}, | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { INIT: 'initializing' }, | |
}, | |
initializing: { | |
invoke: { | |
id: 'initializeBLE', | |
src: 'initializeBLE', | |
onDone: [ | |
{ | |
target: 'ready', | |
actions: ['saveManager'], | |
}, | |
], | |
onError: [ | |
{ | |
target: 'initError', | |
}, | |
], | |
}, | |
}, | |
ready: { | |
on: { SCAN: 'scanning' }, | |
}, | |
scanning: { | |
invoke: { | |
id: 'scanForDevices', | |
src: 'scanForDevices', | |
onDone: [ | |
{ | |
target: 'scanned', | |
actions: ['saveDevice'], | |
}, | |
], | |
onError: [ | |
{ | |
target: 'scanError', | |
}, | |
], | |
}, | |
}, | |
scanned: { | |
on: { | |
CONNECT: 'connecting', | |
}, | |
}, | |
connecting: { | |
invoke: { | |
id: 'connectToNTester', | |
src: 'connectToNTester', | |
onDone: [ | |
{ | |
target: 'connected', | |
actions: ['saveDevice'], | |
}, | |
], | |
onError: [ | |
{ | |
target: 'connectionError', | |
}, | |
], | |
}, | |
}, | |
connected: { | |
initial: 'measuring', | |
states: { | |
measuring: { | |
invoke: { | |
id: 'observeMeasurements', | |
src: 'observeMeasurements', | |
onDone: [ | |
{ | |
target: 'measured', | |
actions: ['saveMeasurement'], | |
}, | |
], | |
}, | |
on: { STOP_MEASUREMENT: 'measured' }, | |
}, | |
measured: { | |
on: { | |
START_MEASUREMENT: 'measuring', | |
RESTART: [ | |
{ | |
target: '.ready', | |
cond: 'managerFound', | |
}, | |
{ | |
target: '.idle', | |
}, | |
], | |
}, | |
}, | |
} | |
}, | |
initError: { | |
exit: ['resetInitError'], | |
}, | |
scanError: {}, | |
connectionError: {}, | |
}, | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment