Skip to content

Commit

Permalink
🔧 Add the ability to add new beacons to the list
Browse files Browse the repository at this point in the history
We currently have two hardcoded beacons in the list. But everybody is going to
have their own beacon for testing. Let's make it possible to add new UUIDs

Changes:
- New field to enter the UUID
- Add button
- When add button is clicked, add new entry with the specified UUID and dummy
  values

Testing done:
Entered two separate UUIDs and clicked "Add"
Two new entries were created in the list
  • Loading branch information
shankari committed Mar 28, 2024
1 parent 48f4847 commit 05b2664
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion www/js/bluetooth/BluetoothScanPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StyleSheet, Modal, ScrollView, SafeAreaView, View, Text } from 'react-n
import { gatherBluetoothClassicData } from './bluetoothScanner';
import { logWarn, displayError, displayErrorMsg, logDebug } from '../plugin/logger';
import BluetoothCard from './BluetoothCard';
import { Appbar, useTheme, Button } from 'react-native-paper';
import { Appbar, useTheme, TextInput, Button } from 'react-native-paper';
import {
BLEBeaconDevice,
BLEPluginCallback,
Expand Down Expand Up @@ -40,6 +40,7 @@ const BluetoothScanPage = ({ ...props }: any) => {
const [isScanningClassic, setIsScanningClassic] = useState(false);
const [isScanningBLE, setIsScanningBLE] = useState(false);
const [isClassic, setIsClassic] = useState(false);
const [newUUID, setNewUUID] = useState<string | null>(null);
const { colors } = useTheme();

// Flattens the `sampleBeacons` into an array of BLEBeaconDevices
Expand Down Expand Up @@ -169,6 +170,19 @@ const BluetoothScanPage = ({ ...props }: any) => {
setIsClassic(!isClassic);
};

// Add a beacon with the new UUID to the list of BLE devices to scan
function addNewUUID(newUUID: string) {
console.log("Before adding UUID "+newUUID+" entries = "+sampleBLEDevices);
const devicesWithAddition = {...sampleBLEDevices};
devicesWithAddition[newUUID] = {
identifier: 'Test-Beacon',
minor: 4949,
major: 3838,
in_range: false,
}
setSampleBLEDevices(devicesWithAddition);
}

const BluetoothCardList = ({ devices }) => {
if (isClassic) {
// When in classic mode, render devices as normal
Expand Down Expand Up @@ -263,6 +277,14 @@ const BluetoothScanPage = ({ ...props }: any) => {
<ScrollView style={{ flex: 1 }} contentContainerStyle={{ flex: 1 }}>
<BlueScanContent />
</ScrollView>
<TextInput
label="New UUID"
value={newUUID || ''}
onChangeText={(t) => setNewUUID(t)}
/>
<Button onPress={() => addNewUUID(newUUID)}>
Add
</Button>
</SafeAreaView>
</Modal>
</>
Expand Down

0 comments on commit 05b2664

Please sign in to comment.