@nativescript-community/nordic-dfu
Version:
A NativeScript plugin for performing Nordic Bluetooth device firmware updates.
62 lines • 2.27 kB
JavaScript
import { Observable } from '@nativescript/core';
export var DfuState;
(function (DfuState) {
DfuState[DfuState["CONNECTING"] = 0] = "CONNECTING";
DfuState[DfuState["DFU_PROCESS_STARTING"] = 1] = "DFU_PROCESS_STARTING";
DfuState[DfuState["ENABLING_DFU_MODE"] = 2] = "ENABLING_DFU_MODE";
DfuState[DfuState["FIRMWARE_VALIDATING"] = 3] = "FIRMWARE_VALIDATING";
DfuState[DfuState["DEVICE_DISCONNECTING"] = 4] = "DEVICE_DISCONNECTING";
DfuState[DfuState["DFU_COMPLETED"] = 5] = "DFU_COMPLETED";
DfuState[DfuState["DFU_ABORTED"] = 6] = "DFU_ABORTED";
DfuState[DfuState["DFU_FAILED"] = 7] = "DFU_FAILED";
})(DfuState || (DfuState = {}));
// Keep strong references of the initiators while running
const executingInitiators = new Map();
export function _addExecutingInitiator(peripheralUUID, context) {
executingInitiators.set(peripheralUUID, context);
}
export function _removeExecutingInitiator(peripheralUUID) {
if (executingInitiators.has(peripheralUUID)) {
const context = executingInitiators.get(peripheralUUID);
if (context?.cleanUpCallback) {
context.cleanUpCallback();
}
executingInitiators.delete(peripheralUUID);
}
}
// For internal usage
export class DFUControllerInternal {
constructor(native) {
this.mNative = native;
}
}
export class DFUInitiatorCommon extends Observable {
constructor(peripheralUUID) {
super();
this.mPeripheralUUID = peripheralUUID;
}
get peripheralUUID() {
return this.mPeripheralUUID;
}
getCurrentServiceController() {
let serviceController;
if (executingInitiators.has(this.mPeripheralUUID)) {
serviceController = executingInitiators.get(this.mPeripheralUUID)?.serviceController;
}
else {
serviceController = null;
}
return serviceController;
}
_notifyDfuStateChanged(state, reason) {
this.notify({
eventName: DFUInitiatorCommon.dfuStateChangedEvent,
object: this,
state: state,
reason,
});
}
}
DFUInitiatorCommon.dfuStateChangedEvent = 'DFUStateChanged';
DFUInitiatorCommon.dfuProgressEvent = 'DFUProgress';
//# sourceMappingURL=common.js.map