Last active
October 21, 2019 15:20
-
-
Save benatwork/63b2656ae4d881bd12a1c60b76d23b71 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
// const initDevice = { | |
// initial: 'readingServices', | |
// states: { | |
// readingServices: { | |
// on: { | |
// BT_READING_DEVICE_STATE: 'readingDeviceState', | |
// BT_DEVICE_READ_ERROR: 'readTimeout' | |
// } | |
// }, | |
// readingDeviceState: { | |
// on: { | |
// BT_READING_BATTERY: 'readingBattery', | |
// BT_DEVICE_READ_ERROR: 'readTimeout' | |
// } | |
// }, | |
// readTimeout: { | |
// on: { | |
// // IDLE: 'idle', | |
// BT_SCANNING: 'scanning' | |
// } | |
// }, | |
// readingBattery: { | |
// on: { | |
// BT_READING_FIRMWARE: 'readingFirmware', | |
// BT_DEVICE_READ_ERROR: 'readTimeout' | |
// } | |
// }, | |
// readingFirmware: { | |
// on: { | |
// BT_CREATING_NOTIFICATIONS: 'subscribeToCharacteristics', | |
// BT_DEVICE_READ_ERROR: 'readTimeout' | |
// } | |
// }, | |
// subscribeToCharacteristics: { | |
// on: { | |
// BT_SUBSCRIBED_TO_CHARACTERISTICS: 'initted', | |
// BT_DEVICE_READ_ERROR: 'readTimeout' | |
// } | |
// }, | |
// initted: {} | |
// } | |
// } | |
const connectDevice = { | |
initial: 'connecting', | |
states: { | |
connecting : { | |
on: { | |
BT_CONNECTED: 'connected', | |
BT_ANDROID_CONNECTED: 'bonding', | |
BT_CONNECTING_ERROR: 'connectingError', | |
BT_CONNECTING_TIMEOUT: 'connectingTimeout', | |
}, | |
}, | |
bonding: { | |
on: { | |
SUCCESSFULLY_BONDED: 'connected', | |
ERROR_BONDING: 'connectingError' | |
} | |
}, | |
connectingTimeout: {}, | |
connectingError: {}, | |
connected: {} | |
} | |
} | |
const findDevice = { | |
initial: 'findDevice', | |
states: { | |
findDevice: { | |
on: { | |
BT_EXISTING_BT_CONNECTION: 'foundDevice', | |
BT_PREVIOUSLY_STORED_DEVICE_ID: 'foundDevice', | |
BT_NO_EXISTING_CONNECTION: 'scanning' | |
} | |
}, | |
scanning: { | |
on: { | |
BT_SCANNING_WARNING: 'scanningWarning', | |
BT_DEVICE_FOUND: 'foundDevice', | |
} | |
}, | |
scanningWarning: { | |
on: { | |
// IDLE: 'idle', | |
BT_SCANNING_TIMEOUT: 'scanningTimeout', | |
BT_DEVICE_FOUND: 'foundDevice', | |
} | |
}, | |
scanningTimeout: { | |
on: { | |
// IDLE: 'idle', | |
BT_SCANNING: 'scanning' | |
} | |
}, | |
foundDevice: {} | |
} | |
}; | |
const bluetoothMachine = Machine({ | |
id: 'bluetooth', | |
initial: 'idle', | |
states: { | |
/* | |
Must first check bluetooth availability | |
*/ | |
idle: { | |
on: { | |
BT_ON: 'bluetoothOn', | |
BT_OFF: 'bluetoothOff' | |
} | |
}, | |
/* BASE BLUETOOTH STATES */ | |
bluetoothOn: { | |
on: { | |
IDLE: 'idle', | |
FIND_DEVICE: 'findDevice' | |
}, | |
}, | |
bluetoothOff : { | |
on: { | |
IDLE: 'idle', | |
BLUETOOTH_ON: 'bluetoothOn' | |
} | |
}, | |
findDevice: { | |
on: { | |
DEVICE_FOUND: 'connectToFoundDevice', | |
NO_DEVICE_FOUND: 'idle' | |
}, | |
...findDevice, | |
}, | |
connectToFoundDevice: { | |
on: { | |
CONNECTED: 'initConnectedDevice', | |
ERROR_CONNECTING: 'idle' | |
}, | |
...connectDevice | |
}, | |
initConnectedDevice: { | |
on: { | |
IDLE: 'idle', | |
DEVICE_INITTED: 'initConnectedDevice', | |
ERROR_INITTING_DEVICE: 'disconnected', | |
}, | |
}, | |
connected: { | |
on: { | |
BT_DISCONNECTED: 'disconnected' | |
} | |
}, | |
disconnected: { | |
on: { | |
IDLE: 'idle', | |
}, | |
}, | |
/* BASE BLUETOOTH ACTIONS */ | |
} | |
}); | |
// const deviceMachine = Machine({ | |
// id: 'device', | |
// initial: 'idle', | |
// states: { | |
// /* | |
// BASE DEVICE STATES | |
// */ | |
// idle: { | |
// on: { | |
// SYS_STATE_INITIALISE: 'initiating' | |
// } | |
// }, | |
// initiated: { | |
// on: { | |
// SYS_STATE_WAITING_FOR_CARTRIDGE: 'waitingForCartridge' | |
// } | |
// }, | |
// localAuthInvalidFailure: { | |
// on: { | |
// IDLE: 'idle' | |
// } | |
// }, | |
// invalidCartridgeEmpty: { | |
// on: { | |
// IDLE: 'idle' | |
// } | |
// }, | |
// invalidRemoteTimeout: { | |
// on: { | |
// IDLE: 'idle' | |
// } | |
// }, | |
// invalidCartridgeRemoved: { | |
// IDLE: 'idle' | |
// }, | |
// invalidCartridgeRemovedInSession: { | |
// IDLE: 'idle' | |
// }, | |
// invalidReadError: { | |
// on: { | |
// IDLE: 'idle' | |
// } | |
// }, | |
// invalidGeneralError: { | |
// on: { | |
// IDLE: 'idle' | |
// } | |
// }, | |
// invalidNoDosingProfile: { | |
// IDLE: 'idle' | |
// }, | |
// deviceReady: { | |
// // TODO: | |
// }, | |
// /* | |
// BASE DEVICE ACTIONS | |
// */ | |
// initiating: { | |
// on: { | |
// SYS_STATE_ADVERTISING: 'advertising' | |
// } | |
// }, | |
// advertising: { | |
// on: { | |
// SYS_STATE_CONNECTING: 'connecting' | |
// } | |
// }, | |
// connecting: { | |
// on: { | |
// INITIATED: 'initiated' | |
// } | |
// }, | |
// waitingForCartridge: { | |
// on: { | |
// SYS_STATE_LOCAL_CARTRIDGE_AUTH: 'validatingLocalCartridge' | |
// } | |
// }, | |
// validatingLocalCartridge: { | |
// on: { | |
// // ERROR STATES | |
// EVNT_INVLD_LOCAL_AUTH_FAILURE: 'localAuthInvalidFailure', | |
// EVNT_INVLD_CARTRIDGE_EMPTY: | |
// 'invalidCartridgeEmpty', | |
// EVNT_INVLD_REMOTE_TIMEOUT: 'invalidRemoteTimeout', | |
// EVNT_INVLD_CARTRIDGE_REMOVED: 'invalidCartridgeRemoved', | |
// EVNT_INVLD_CARTRIDGE_REMOVED_IN_SESSION: | |
// 'invalidCartridgeRemovedInSession', | |
// EVNT_INVLD_READ_ERROR: 'invalidReadError', | |
// // SUCCESS STATE | |
// SYS_STATE_REMOTE_CARTRIDGE_AUTH: | |
// 'validatingRemoteCartridge' | |
// } | |
// }, | |
// validatingRemoteCartridge: { | |
// on: { | |
// // ERROR STATES | |
// RMT_INVLD_GENERAL_ERROR: 'invalidGeneralError', | |
// RMT_INVLD_NO_DOSING_PROFILE: 'invalidNoDosingProfile', | |
// // SUCCESS STATE | |
// RMT_VALIDATING_DOSING_PROFILE: | |
// 'validatingDosingProfile' | |
// } | |
// }, | |
// validatingDosingProfile: { | |
// on: { | |
// SYS_STATE_READY: 'deviceReady' | |
// } | |
// } | |
// } | |
// }) | |
// const sessionMachine = Machine({ | |
// id: 'session', | |
// initial: 'idle', | |
// states: { | |
// /* BASE DEVICE STATES */ | |
// idle: { | |
// on: { | |
// SYS_STATE_SESSION_START: 'startingSession' | |
// } | |
// }, | |
// sessionDrawEnd: { | |
// on: { | |
// SYS_STATE_SESSION_START: 'startingSession' | |
// } | |
// }, | |
// /* BASE ACTION STATES */ | |
// startingSession: { | |
// on: { | |
// SYS_STATE_SESSION_IN_PROGRESS: 'sessionInProgress' | |
// } | |
// }, | |
// sessionInProgress: { | |
// on: { | |
// SYS_STATE_PRE_HEAT_GREEN: | |
// 'sessionPreheat' | |
// } | |
// }, | |
// sessionPreheat: { | |
// on: { | |
// SYS_STATE_DRAW_END_BLUE: 'sessionDrawEnd' | |
// } | |
// } | |
// } | |
// }) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment