From f7dfd1bb518676129cd9621f8def7937e32a856d Mon Sep 17 00:00:00 2001 From: Daniel Cardoso Date: Tue, 19 Apr 2022 02:06:30 +0100 Subject: [PATCH 1/2] Add reset devices. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit it's persisting hotspot values ​​even after power off If possible return `resetDevices` in provider. --- src/HotspotBle/useHotspotBle.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/HotspotBle/useHotspotBle.tsx b/src/HotspotBle/useHotspotBle.tsx index 54465ff..f628919 100644 --- a/src/HotspotBle/useHotspotBle.tsx +++ b/src/HotspotBle/useHotspotBle.tsx @@ -74,9 +74,13 @@ const useHotspotBle = () => { instanceRef.current = null } }, []) + + const resetDevices = useCallback(() => setDevices([]), []) const startScan = useCallback( async (callback: (error: BleError | null) => void) => { + resetDevices() + getBleManager().startDeviceScan( [Service.MAIN_UUID], { allowDuplicates: false }, @@ -93,7 +97,7 @@ const useHotspotBle = () => { }, [] ) - + const stopScan = useCallback(() => getBleManager().stopDeviceScan(), []) const connect = useCallback(async (hotspotDevice: Device) => { From 66bd41f89d1b23f04ab75358486930e6f3d797aa Mon Sep 17 00:00:00 2001 From: dannpl Date: Tue, 19 Apr 2022 02:17:23 +0100 Subject: [PATCH 2/2] feat: update context --- src/HotspotBle/HotspotBleProvider.tsx | 1 + src/HotspotBle/bleTypes.ts | 5 +++++ src/HotspotBle/useHotspotBle.tsx | 11 ++++++----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/HotspotBle/HotspotBleProvider.tsx b/src/HotspotBle/HotspotBleProvider.tsx index 2e1f91d..67603d7 100644 --- a/src/HotspotBle/HotspotBleProvider.tsx +++ b/src/HotspotBle/HotspotBleProvider.tsx @@ -8,6 +8,7 @@ const initialState = { enable: async () => false, startScan: async () => {}, stopScan: async () => {}, + resetDevices: () => {}, connect: async () => {}, disconnect: async () => false, findCharacteristic: async () => undefined, diff --git a/src/HotspotBle/bleTypes.ts b/src/HotspotBle/bleTypes.ts index 419441a..ae1e7dd 100644 --- a/src/HotspotBle/bleTypes.ts +++ b/src/HotspotBle/bleTypes.ts @@ -65,6 +65,11 @@ export interface HotspotBleManager { */ stopScan: () => void + /** + * Reset devices that have been scanned. + */ + resetDevices: () => void + /** * Connect to a Hotspot. Pass the device from {@link HotspotBleManager.scannedDevices | scannedDevices} after scanning. * @param hotspotDevice diff --git a/src/HotspotBle/useHotspotBle.tsx b/src/HotspotBle/useHotspotBle.tsx index f628919..c59318a 100644 --- a/src/HotspotBle/useHotspotBle.tsx +++ b/src/HotspotBle/useHotspotBle.tsx @@ -74,13 +74,13 @@ const useHotspotBle = () => { instanceRef.current = null } }, []) - - const resetDevices = useCallback(() => setDevices([]), []) + + const resetDevices = useCallback(() => setDevices({}), []) const startScan = useCallback( async (callback: (error: BleError | null) => void) => { resetDevices() - + getBleManager().startDeviceScan( [Service.MAIN_UUID], { allowDuplicates: false }, @@ -95,9 +95,9 @@ const useHotspotBle = () => { } ) }, - [] + [resetDevices] ) - + const stopScan = useCallback(() => getBleManager().stopDeviceScan(), []) const connect = useCallback(async (hotspotDevice: Device) => { @@ -402,6 +402,7 @@ const useHotspotBle = () => { return { startScan, stopScan, + resetDevices, connect, disconnect, isConnected,