mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
rename BLEData to BleUart
These actions all relate specifically to the nRF UART GATT service
This commit is contained in:
committed by
David Lechner
parent
802f2bc05d
commit
f3425e2f0f
@@ -0,0 +1,73 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020 The Pybricks Authors
|
||||
// actions/ble-uart.ts: Actions for Bluetooth Low Energy nRF UART service
|
||||
|
||||
import { Action } from 'redux';
|
||||
import { assert } from '../utils';
|
||||
import { createCountFunc } from '../utils/iter';
|
||||
|
||||
/**
|
||||
* BLE nRF UART service actions types.
|
||||
*/
|
||||
export enum BleUartActionType {
|
||||
/**
|
||||
* Write data.
|
||||
*/
|
||||
Write = 'ble.data.action.write',
|
||||
/**
|
||||
* Writing completed successfully.
|
||||
*/
|
||||
DidWrite = 'ble.data.didWrite',
|
||||
/**
|
||||
* Writing failed.
|
||||
*/
|
||||
DidFailToWrite = 'ble.data.action.didFailToWrite',
|
||||
/**
|
||||
* Notify that data was received.
|
||||
*/
|
||||
Notify = 'ble.data.action.receive',
|
||||
}
|
||||
|
||||
const nextId = createCountFunc();
|
||||
|
||||
export type BleUartWriteAction = Action<BleUartActionType.Write> & {
|
||||
id: number;
|
||||
value: Uint8Array;
|
||||
};
|
||||
|
||||
export function write(value: Uint8Array): BleUartWriteAction {
|
||||
assert(value.length <= 20, 'value can be at most 20 bytes');
|
||||
return { type: BleUartActionType.Write, id: nextId(), value };
|
||||
}
|
||||
|
||||
export type BleUartDidWriteAction = Action<BleUartActionType.DidWrite> & {
|
||||
id: number;
|
||||
};
|
||||
|
||||
export function didWrite(id: number): BleUartDidWriteAction {
|
||||
return { type: BleUartActionType.DidWrite, id };
|
||||
}
|
||||
|
||||
export type BleUartDidFailToWriteAction = Action<BleUartActionType.DidFailToWrite> & {
|
||||
id: number;
|
||||
err: Error;
|
||||
};
|
||||
|
||||
export function didFailToWrite(id: number, err: Error): BleUartDidFailToWriteAction {
|
||||
return { type: BleUartActionType.DidFailToWrite, id, err };
|
||||
}
|
||||
|
||||
export type BleUartNotifyAction = Action<BleUartActionType.Notify> & {
|
||||
value: DataView;
|
||||
};
|
||||
|
||||
export function notify(value: DataView): BleUartNotifyAction {
|
||||
return { type: BleUartActionType.Notify, value };
|
||||
}
|
||||
|
||||
/** Common type for low-level BLE data actions. */
|
||||
export type BleUartAction =
|
||||
| BleUartWriteAction
|
||||
| BleUartDidWriteAction
|
||||
| BleUartDidFailToWriteAction
|
||||
| BleUartNotifyAction;
|
||||
@@ -2,8 +2,6 @@
|
||||
// Copyright (c) 2020 The Pybricks Authors
|
||||
|
||||
import { Action } from 'redux';
|
||||
import { assert } from '../utils';
|
||||
import { createCountFunc } from '../utils/iter';
|
||||
|
||||
/**
|
||||
* Bluetooth low energy connection action types.
|
||||
@@ -60,69 +58,6 @@ export function didDisconnect(): BLEConnectAction {
|
||||
return { type: BLEConnectActionType.DidDisconnect };
|
||||
}
|
||||
|
||||
export enum BLEDataActionType {
|
||||
/**
|
||||
* Write data.
|
||||
*/
|
||||
Write = 'ble.data.action.write',
|
||||
/**
|
||||
* Writing completed successfully.
|
||||
*/
|
||||
DidWrite = 'ble.data.didWrite',
|
||||
/**
|
||||
* Writing failed.
|
||||
*/
|
||||
DidFailToWrite = 'ble.data.action.didFailToWrite',
|
||||
/**
|
||||
* Notify that data was received.
|
||||
*/
|
||||
Notify = 'ble.data.action.receive',
|
||||
}
|
||||
|
||||
const nextId = createCountFunc();
|
||||
|
||||
export type BLEDataWriteAction = Action<BLEDataActionType.Write> & {
|
||||
id: number;
|
||||
value: Uint8Array;
|
||||
};
|
||||
|
||||
export function write(value: Uint8Array): BLEDataWriteAction {
|
||||
assert(value.length <= 20, 'value can be at most 20 bytes');
|
||||
return { type: BLEDataActionType.Write, id: nextId(), value };
|
||||
}
|
||||
|
||||
export type BLEDataDidWriteAction = Action<BLEDataActionType.DidWrite> & {
|
||||
id: number;
|
||||
};
|
||||
|
||||
export function didWrite(id: number): BLEDataDidWriteAction {
|
||||
return { type: BLEDataActionType.DidWrite, id };
|
||||
}
|
||||
|
||||
export type BLEDataDidFailToWriteAction = Action<BLEDataActionType.DidFailToWrite> & {
|
||||
id: number;
|
||||
err: Error;
|
||||
};
|
||||
|
||||
export function didFailToWrite(id: number, err: Error): BLEDataDidFailToWriteAction {
|
||||
return { type: BLEDataActionType.DidFailToWrite, id, err };
|
||||
}
|
||||
|
||||
export type BLEDataNotifyAction = Action<BLEDataActionType.Notify> & {
|
||||
value: DataView;
|
||||
};
|
||||
|
||||
export function notify(value: DataView): BLEDataNotifyAction {
|
||||
return { type: BLEDataActionType.Notify, value };
|
||||
}
|
||||
|
||||
/** Common type for low-level BLE data actions. */
|
||||
export type BLEDataAction =
|
||||
| BLEDataWriteAction
|
||||
| BLEDataDidWriteAction
|
||||
| BLEDataDidFailToWriteAction
|
||||
| BLEDataNotifyAction;
|
||||
|
||||
/**
|
||||
* High-level BLE actions.
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// Copyright (c) 2020 The Pybricks Authors
|
||||
|
||||
import { Dispatch as ReduxDispatch } from 'redux';
|
||||
import { BLEAction, BLEConnectAction, BLEDataAction } from './ble';
|
||||
import { BLEAction, BLEConnectAction } from './ble';
|
||||
import { BleUartAction } from './ble-uart';
|
||||
import { EditorAction } from './editor';
|
||||
import { FlashFirmwareAction } from './flash-firmware';
|
||||
import { HubAction, HubMessageAction } from './hub';
|
||||
@@ -23,7 +24,7 @@ import { TerminalDataAction } from './terminal';
|
||||
export type Action =
|
||||
| BLEAction
|
||||
| BLEConnectAction
|
||||
| BLEDataAction
|
||||
| BleUartAction
|
||||
| BootloaderConnectionAction
|
||||
| BootloaderDidRequestAction
|
||||
| BootloaderRequestAction
|
||||
|
||||
Reference in New Issue
Block a user