Skip to content

Commit

Permalink
📋 Prep for saving new BLE Bluetooth objects
Browse files Browse the repository at this point in the history
- Move the major and minor boxes to the same row to take up less space
- Split the fake callbacks into enter, exit and range
- generalize `fakeMonitorCallback` to work for both enter and exit
- do not call rangeCallback directly from monitor callback since there
  are now separate buttons
- for the range callback, use the device major and minor values if they
  exist
- for the range callback, reset monitor and range results to avoid
  duplicates

This is the first step for testing the data models defined in:
e-mission/e-mission-docs#1062 (comment)
  • Loading branch information
shankari committed Apr 1, 2024
1 parent 7c70840 commit 26c388d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
28 changes: 18 additions & 10 deletions www/js/bluetooth/BluetoothCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const BluetoothCard = ({ device, isClassic, isScanningBLE }: Props) => {
bgColor = device.in_range ? `rgba(200,250,200,1)` : `rgba(250,200,200,1)`;
}

async function fakeMonitorCallback() {
async function fakeMonitorCallback(state: String) {
// If we don't do this, the results start accumulating in the device object
// first call, we put a result into the device
// second call, the device already has a result, so we put another one in...
Expand All @@ -33,16 +33,16 @@ const BluetoothCard = ({ device, isClassic, isScanningBLE }: Props) => {
window['cordova'].plugins.locationManager.getDelegate().didDetermineStateForRegion({
region: deviceWithoutResult,
eventType: 'didDetermineStateForRegion',
state: 'CLRegionStateInside',
state: state,
});
let timer: ReturnType<typeof setTimeout> = setTimeout(fakeRangeCallback, 500);
}

async function fakeRangeCallback() {
// If we don't do this, the results start accumulating in the device object
// first call, we put a result into the device
// second call, the device already has a result, so we put another one in...
const deviceWithMajorMinor = { ...device, major: 1234, minor: 4567 };
const deviceWithMajorMinor = { ...device };
deviceWithMajorMinor.major = device.major | 1234;
deviceWithMajorMinor.minor = device.minor | 4567;
deviceWithMajorMinor.monitorResult = undefined;
deviceWithMajorMinor.rangeResult = undefined;
window['cordova'].plugins.locationManager.getDelegate().didRangeBeaconsInRegion({
region: deviceWithMajorMinor,
eventType: 'didRangeBeaconsInRegion',
Expand All @@ -65,9 +65,17 @@ const BluetoothCard = ({ device, isClassic, isScanningBLE }: Props) => {
<Text style={{ backgroundColor: colors.secondaryContainer }} variant="bodyMedium">
{device.rangeResult}
</Text>
<Button mode="elevated" onPress={fakeMonitorCallback}>
Fake callback
</Button>
<Card.Actions>
<Button mode="elevated" onPress={() => fakeMonitorCallback('CLRegionStateInside')}>
Enter
</Button>
<Button mode="elevated" onPress={fakeRangeCallback}>
Range
</Button>
<Button mode="elevated" onPress={() => fakeMonitorCallback('CLRegionStateOutside')}>
Exit
</Button>
</Card.Actions>
</Card.Content>
</Card>
);
Expand Down
22 changes: 12 additions & 10 deletions www/js/bluetooth/BluetoothScanPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,18 @@ const BluetoothScanPage = ({ ...props }: any) => {
value={newUUID || ''}
onChangeText={(t) => setNewUUID(t.toUpperCase())}
/>
<TextInput
label="Major (optional)"
value={newMajor || ''}
onChangeText={(t) => setNewMajor(t)}
/>
<TextInput
label="Minor (optional)"
value={newMinor || ''}
onChangeText={(t) => setNewMinor(t)}
/>
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<TextInput
label="Major (optional)"
value={newMajor || ''}
onChangeText={(t) => setNewMajor(t)}
/>
<TextInput
label="Minor (optional)"
value={newMinor || ''}
onChangeText={(t) => setNewMinor(t)}
/>
</View>
<Button disabled={!newUUID} onPress={() => addNewUUID(newUUID, newMajor, newMinor)}>
Add New Beacon To Scan
</Button>
Expand Down

0 comments on commit 26c388d

Please sign in to comment.