|
| 1 | +import { Injectable } from '@angular/core'; |
| 2 | +import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core'; |
| 3 | +import { Observable } from 'rxjs'; |
| 4 | + |
| 5 | +export interface UpdateOptions { |
| 6 | + /** |
| 7 | + * A string that contains the identifier for the Bluetooth LE device to update. It will either be a MAC address (on Android) or a UUID (on iOS). |
| 8 | + */ |
| 9 | + deviceId: string; |
| 10 | + |
| 11 | + /** |
| 12 | + * A string that is the path to the file to use in the update. It can be either in either `cdvfile://` or `file://` format. |
| 13 | + */ |
| 14 | + fileUrl: string; |
| 15 | + |
| 16 | + /** |
| 17 | + * The PacketReceiptNotificationsValue (Default to 10) |
| 18 | + */ |
| 19 | + packetReceiptNotificationsValue?: number; |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * @name Dfu Update |
| 24 | + * @description |
| 25 | + * This plugin is a Wrapper to use Nordic Semiconductor's Device Firmware Update (DFU) service to update a Bluetooth LE device. |
| 26 | + * |
| 27 | + * @usage |
| 28 | + * ```typescript |
| 29 | + * import { DfuUpdate } from '@ionic-native/dfu-update/ngx'; |
| 30 | + * |
| 31 | + * |
| 32 | + * constructor(private dfuUpdate: DfuUpdate) { } |
| 33 | + * |
| 34 | + * ... |
| 35 | + * |
| 36 | + * |
| 37 | + * this.dfuUpdate.updateFirmware('fileURL', 'deviceIdentifier') |
| 38 | + * .then((res: any) => console.log(res)) |
| 39 | + * .catch((error: any) => console.error(error)); |
| 40 | + * |
| 41 | + * ``` |
| 42 | + */ |
| 43 | +@Plugin({ |
| 44 | + pluginName: 'DfuUpdate', |
| 45 | + plugin: 'cordova-plugin-dfu-update', |
| 46 | + pluginRef: 'window.DfuUpdate', |
| 47 | + repo: 'https://github.com/EinfachHans/cordova-plugin-dfu-update', |
| 48 | + install: 'ionic cordova plugin add cordova-plugin-dfu-update --variable ANDROID_NORDIC_VERSION="1.11.0"', |
| 49 | + installVariables: ['ANDROID_NORDIC_VERSION'], |
| 50 | + platforms: ['Android', 'iOS'], |
| 51 | +}) |
| 52 | +@Injectable() |
| 53 | +export class DfuUpdate extends IonicNativePlugin { |
| 54 | + /** |
| 55 | + * Start the Firmware-Update-Process |
| 56 | + * @param options - Options for the process |
| 57 | + * @return {Observable<any>} Returns a Observable that emits when something happens |
| 58 | + */ |
| 59 | + @Cordova({ |
| 60 | + observable: true, |
| 61 | + callbackOrder: 'reverse', |
| 62 | + }) |
| 63 | + updateFirmware(options: UpdateOptions): Observable<any> { |
| 64 | + return; |
| 65 | + } |
| 66 | +} |
0 commit comments