-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runtime status #139
base: dev
Are you sure you want to change the base?
Runtime status #139
Changes from all commits
a5a9c3a
3a8b45c
8d8ae7e
95c7388
96c7e0d
48bee94
cd4e7bc
1629432
8fa57a2
a879c07
e409059
6936d23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import * as consts from '../consts'; | ||
import { UpdatePeripheralsAction, PeripheralRenameAction, Peripheral, PeripheralList } from '../types'; | ||
import { UpdatePeripheralsAction, PeripheralRenameAction, Peripheral, PeripheralList, UpdateRuntimeVersionAction, UpdateBatteryAction } from '../types'; | ||
|
||
type Actions = UpdatePeripheralsAction | PeripheralRenameAction; | ||
type Actions = UpdatePeripheralsAction | PeripheralRenameAction | UpdateRuntimeVersionAction | UpdateBatteryAction; | ||
|
||
interface PeripheralState { | ||
peripheralList: PeripheralList; | ||
|
@@ -19,9 +19,7 @@ const initialPeripheralState: PeripheralState = { | |
|
||
// Taken from runtime_util.c in Runtime repo | ||
const IS_UNSAFE = 0; | ||
const V_BATT = 5; | ||
|
||
// TODO: Handle runtimeVersion since no longer sent | ||
export const peripherals = (state: PeripheralState = initialPeripheralState, action: Actions) => { | ||
const nextState = Object.assign({}, state); | ||
const nextPeripherals = nextState.peripheralList; | ||
|
@@ -32,12 +30,10 @@ export const peripherals = (state: PeripheralState = initialPeripheralState, act | |
(action.peripherals ?? []).forEach((peripheral: Peripheral) => { | ||
if (peripheral.name === consts.PeripheralTypes.BatteryBuzzer) { | ||
const batteryParams = peripheral.params; | ||
//since batterysafety is not included in runtimestatus, have to extract the value from params | ||
if (batteryParams[IS_UNSAFE] && batteryParams[IS_UNSAFE].bval) { | ||
nextState.batterySafety = batteryParams[IS_UNSAFE].bval!; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However batterysafety is not included in the runtime status thus extracted manually. |
||
} | ||
if (batteryParams[V_BATT] && batteryParams[V_BATT].fval) { | ||
nextState.batteryLevel = batteryParams[V_BATT].fval!; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got removed because the batteryLevel is already changed from calling changeBatteryLevel in runtime.ts |
||
} | ||
} else { | ||
const key = `${peripheral.type}_${peripheral.uid}`; | ||
keys.push(key); | ||
|
@@ -47,6 +43,8 @@ export const peripherals = (state: PeripheralState = initialPeripheralState, act | |
} | ||
nextPeripherals[key] = { ...peripheral, uid: key }; | ||
} | ||
//batteryLevel gets updated from runtimestatus proto | ||
nextState.batteryLevel = state.batteryLevel; | ||
}); | ||
|
||
Object.keys(nextPeripherals).forEach((uid: string) => { | ||
|
@@ -62,6 +60,16 @@ export const peripherals = (state: PeripheralState = initialPeripheralState, act | |
// nextPeripherals[action.id].name = action.name; | ||
return nextState; | ||
} | ||
case consts.PeripheralActionsTypes.UPDATE_RUNTIME_VERSION: | ||
return { | ||
...state, | ||
runtimeVersion: action.version | ||
} | ||
case consts.PeripheralActionsTypes.UPDATE_BATTERY: | ||
return { | ||
...state, | ||
batteryLevel: action.battery | ||
} | ||
default: { | ||
return state; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Runtime Status sends us the current run mode it is in. Calls the updateCodeStatus action to change the mode