diff --git a/www/js/bluetooth/BluetoothScanPage.tsx b/www/js/bluetooth/BluetoothScanPage.tsx index ae6a36a8a..e885392fb 100644 --- a/www/js/bluetooth/BluetoothScanPage.tsx +++ b/www/js/bluetooth/BluetoothScanPage.tsx @@ -1,7 +1,8 @@ -import React, { useContext } from 'react'; +import React, { useContext, useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { AppContext } from '../App'; import { StyleSheet, Text, Modal, ScrollView, SafeAreaView, Pressable } from 'react-native'; +import { gatherData } from './blueoothScanner'; /** * The implementation of this scanner page follows the design of @@ -13,6 +14,23 @@ import { StyleSheet, Text, Modal, ScrollView, SafeAreaView, Pressable } from 're const BluetoothScanPage = ({ ...props }: any) => { const { t } = useTranslation(); const context = useContext(AppContext); // May not be necessary + const [logs, setLogs] = useState([]); + + useEffect(() => { + + }, []); + + // Function to run Bluetooth test and update logs + const runBluetoothTest = async () => { + try { + setLogs(["Loading..."]); + const newLogs = await gatherData(); + setLogs(newLogs); + } catch (error) { + console.error(error); + // Handle error + } + }; const BlueScanContent = (
@@ -28,6 +46,16 @@ const BluetoothScanPage = ({ ...props }: any) => { } {'Add Scanner Components here!'} + + +

Console Output:

+ {logs.map((log, index) => ( +

{log}

+ ))}
); @@ -56,6 +84,9 @@ const s = StyleSheet.create({ alignItems: 'center', padding: 0, }, + btn: { + display: 'flex' + } }); export default BluetoothScanPage; diff --git a/www/js/bluetooth/blueoothScanner.ts b/www/js/bluetooth/blueoothScanner.ts new file mode 100644 index 000000000..594860442 --- /dev/null +++ b/www/js/bluetooth/blueoothScanner.ts @@ -0,0 +1,23 @@ +function gatherData(): Promise { + return new Promise((resolve, reject) => { + let logs: string[] = []; + + window['bluetoothSerial'].discoverUnpaired( + (devices) => { + logs.push("Successfully scanned, results..."); + devices.forEach(function (device) { + logs.push("ID: " + device.id + " Name: " + device.name); + }); + resolve(logs); + }, + (failure) => { + logs.push("Failed!"); + logs.push("ERROR: " + failure); + console.debug("ERROR: " + failure); + reject(new Error(failure)); + } + ); + }); +} + + export { gatherData }; \ No newline at end of file