Skip to content

Commit cec92ae

Browse files
committed
fix(device): write to fff3
1 parent 3098df2 commit cec92ae

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

src/device.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class DjiDevice {
7575
private pairPinCode?: string = 'love';
7676
private noble?: typeof noble;
7777
private cameraPeripheral?: Peripheral;
78-
private fff5Characteristic?: Characteristic;
78+
private fff3Characteristic?: Characteristic;
7979
private state: DjiDeviceState = DjiDeviceState.idle;
8080
private startStreamingTimer?: NodeJS.Timeout;
8181
private stopStreamingTimer?: NodeJS.Timeout;
@@ -140,7 +140,7 @@ export class DjiDevice {
140140
this.noble = undefined;
141141
}
142142
this.cameraPeripheral = undefined;
143-
this.fff5Characteristic = undefined;
143+
this.fff3Characteristic = undefined;
144144
this.batteryPercentage = undefined;
145145
this.setState(DjiDeviceState.idle);
146146
}
@@ -287,13 +287,16 @@ export class DjiDevice {
287287
console.info(
288288
`dji-device: Subscribing to characteristic ${characteristic.uuid}`,
289289
);
290-
if (characteristic.uuid === fff5Id) {
291-
this.fff5Characteristic = characteristic;
290+
if (characteristic.uuid === fff3Id) {
291+
this.fff3Characteristic = characteristic;
292292
}
293293
characteristic
294294
.subscribeAsync()
295295
.then(async () => {
296-
console.log('subscribed', characteristic.uuid);
296+
console.info(
297+
'dji-device: Subscribed to characteristic',
298+
characteristic.uuid,
299+
);
297300
characteristic.on('data', (data) => {
298301
if (error) {
299302
console.error('dji-device: Characteristic read error', error);
@@ -586,10 +589,20 @@ export class DjiDevice {
586589
this.writeValue(message.encode());
587590
}
588591

589-
private writeValue(value: Buffer): void {
590-
if (!this.fff5Characteristic) {
592+
private async writeValue(value: Buffer): Promise<void> {
593+
if (!this.fff3Characteristic) {
594+
console.error('dji-device: No characteristic to write to');
591595
return;
592596
}
593-
this.fff5Characteristic.write(value, false);
597+
await this.fff3Characteristic
598+
.writeAsync(value, false)
599+
.then(() => {
600+
console.debug('dji-device: Write successful');
601+
})
602+
.catch((error) => {
603+
if (error) {
604+
console.error('dji-device: Write error', error);
605+
}
606+
});
594607
}
595608
}

0 commit comments

Comments
 (0)