Skip to content

Instantly share code, notes, and snippets.

@apostopher
Last active November 17, 2020 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apostopher/8217793985b532f9b67d065b80379f9e to your computer and use it in GitHub Desktop.
Save apostopher/8217793985b532f9b67d065b80379f9e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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