Skip to content

Commit c01a291

Browse files
Koalkball-hayden
andcommitted
feat: adding settings capabilities
Co-authored-by: Hayden Ball <[email protected]>
1 parent 2d32526 commit c01a291

File tree

11 files changed

+753
-754
lines changed

11 files changed

+753
-754
lines changed

example/app.config.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,42 @@ import { ExpoConfig } from '@expo/config-types';
22
import 'ts-node/register';
33

44
const config: ExpoConfig = {
5-
name: "react-native-mcu-manager-example",
6-
slug: "react-native-mcu-manager-example",
7-
assetBundlePatterns: ["**/*"],
8-
orientation: "portrait",
9-
platforms: ["ios", "android"],
10-
scheme: "rnmcumgr",
11-
version: "1.0.0",
5+
name: 'react-native-mcu-manager-example',
6+
slug: 'react-native-mcu-manager-example',
7+
assetBundlePatterns: ['**/*'],
8+
orientation: 'portrait',
9+
platforms: ['ios', 'android'],
10+
scheme: 'rnmcumgr',
11+
version: '1.0.0',
1212
splash: {
13-
image: ".assets/images/pd.png",
14-
backgroundColor: "#FFFFFF",
13+
image: '.assets/images/pd.png',
14+
backgroundColor: '#FFFFFF',
1515
},
1616
ios: {
1717
supportsTablet: true,
18-
bundleIdentifier: "uk.co.playerdata.reactnativemcumanager.example",
18+
bundleIdentifier: 'uk.co.playerdata.reactnativemcumanager.example',
1919
infoPlist: {
20-
NSBluetoothAlwaysUsageDescription: "Requires Bluetooth to perform firmware updates.",
20+
NSBluetoothAlwaysUsageDescription:
21+
'Requires Bluetooth to perform firmware updates.',
2122
},
2223
},
2324
android: {
24-
package: "uk.co.playerdata.reactnativemcumanager.example",
25-
permissions: [
26-
"ACCESS_FINE_LOCATION",
27-
"ACCESS_COARSE_LOCATION",
28-
],
25+
package: 'uk.co.playerdata.reactnativemcumanager.example',
26+
permissions: ['ACCESS_FINE_LOCATION', 'ACCESS_COARSE_LOCATION'],
2927
},
3028
plugins: [
31-
["expo-document-picker"],
32-
["expo-router"],
33-
["./gradlePlugin.ts"]
34-
]
29+
['expo-document-picker'],
30+
['expo-router'],
31+
['./gradlePlugin.ts'],
32+
[
33+
'expo-build-properties',
34+
{
35+
android: {
36+
minSdkVersion: 26,
37+
},
38+
},
39+
],
40+
],
3541
};
3642

3743
export default config;

example/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
"dependencies": {
1515
"@playerdata/react-native-mcu-manager": "workspace:*",
1616
"expo": "52.0.25",
17-
"expo-constants": "~17.0.4",
17+
"expo-build-properties": "0.13.2",
18+
"expo-constants": "17.0.4",
1819
"expo-document-picker": "13.0.2",
19-
"expo-linking": "~7.0.4",
20-
"expo-router": "~4.0.16",
20+
"expo-linking": "7.0.4",
21+
"expo-router": "4.0.16",
2122
"expo-splash-screen": "0.29.20",
2223
"expo-status-bar": "~2.0.1",
2324
"lodash": "4.17.21",
2425
"react": "18.3.1",
25-
"react-native": "0.76.3",
26+
"react-native": "0.76.6",
2627
"react-native-ble-plx": "3.4.0",
27-
"react-native-reanimated": "~3.16.1",
28+
"react-native-reanimated": "3.16.7",
2829
"react-native-safe-area-context": "4.14.1",
2930
"react-native-screens": "~4.4.0",
3031
"react-native-toast-message": "2.2.1"
@@ -33,7 +34,7 @@
3334
"@babel/core": "7.26.0",
3435
"@babel/runtime": "7.26.0",
3536
"@types/lodash": "4.17.14",
36-
"@types/react": "19.0.7",
37+
"@types/react": "18.3.18",
3738
"metro-react-native-babel-preset": "0.77.0",
3839
"ts-node": "^10.9.2",
3940
"typescript": "5.7.3"

example/src/app/_layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const RootLayout = () => {
2020
options={{ title: 'Home' }}
2121
/>
2222
<Tabs.Screen name="update" options={{ title: 'Update' }} />
23+
<Tabs.Screen name="settings" options={{ title: 'Settings' }} />
2324
</Tabs>
2425
</SelectedDeviceProvider>
2526
);

example/src/app/settings.tsx

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import {
2+
readSetting,
3+
writeSetting,
4+
} from '@playerdata/react-native-mcu-manager';
5+
import { Buffer } from 'buffer';
6+
7+
import React, { useState } from 'react';
8+
import {
9+
Button,
10+
SafeAreaView,
11+
ScrollView,
12+
StyleSheet,
13+
Text,
14+
TextInput,
15+
View,
16+
} from 'react-native';
17+
18+
import { useSelectedDevice } from '../context/selectedDevice';
19+
20+
const styles = StyleSheet.create({
21+
root: {
22+
padding: 16,
23+
},
24+
25+
block: {
26+
marginBottom: 16,
27+
},
28+
29+
list: {
30+
padding: 16,
31+
},
32+
});
33+
34+
export default function settings() {
35+
const { selectedDevice } = useSelectedDevice();
36+
37+
const [settingError, setSettingError] = useState<string | null>(null);
38+
const [settingName, setSettingName] = useState<string>('');
39+
const [settingValue, setSettingValue] = useState<string>('');
40+
41+
return (
42+
<SafeAreaView>
43+
<ScrollView contentContainerStyle={styles.root}>
44+
<Text style={styles.block}>Step 1 - Select Device to Update</Text>
45+
46+
<View style={styles.block}>
47+
{selectedDevice && (
48+
<>
49+
<Text>Selected:</Text>
50+
<Text>{selectedDevice.deviceName}</Text>
51+
</>
52+
)}
53+
</View>
54+
55+
<Text style={styles.block}>
56+
Step 2 - Read or Write settings to the device
57+
</Text>
58+
59+
<View style={styles.block}>
60+
<Text>Setting Name</Text>
61+
62+
<TextInput
63+
value={settingName || ''}
64+
onChangeText={setSettingName}
65+
placeholder="Enter setting name"
66+
/>
67+
</View>
68+
69+
<View style={styles.block}>
70+
<Text>Setting Value</Text>
71+
72+
<TextInput
73+
value={settingValue || ''}
74+
onChangeText={setSettingValue}
75+
placeholder="Enter setting value"
76+
/>
77+
</View>
78+
79+
{settingError && (
80+
<View style={styles.block}>
81+
<Text>{settingError}</Text>
82+
</View>
83+
)}
84+
85+
<View style={styles.block}>
86+
<Button
87+
onPress={async () => {
88+
try {
89+
setSettingError(null);
90+
91+
const valueB64 = await readSetting(
92+
selectedDevice?.deviceId || '',
93+
settingName
94+
);
95+
96+
const decodedValue = Buffer.from(valueB64, 'base64').toString(
97+
'binary'
98+
);
99+
setSettingValue(decodedValue);
100+
} catch (error) {
101+
if (error instanceof Error) {
102+
setSettingError(error.message);
103+
} else {
104+
setSettingError('An unknown error occurred');
105+
}
106+
}
107+
}}
108+
title="Read Setting"
109+
/>
110+
</View>
111+
112+
<View style={styles.block}>
113+
<Button
114+
onPress={async () => {
115+
try {
116+
setSettingError(null);
117+
118+
const encodedValue = Buffer.from(
119+
settingValue,
120+
'binary'
121+
).toString('base64');
122+
123+
await writeSetting(
124+
selectedDevice?.deviceId || '',
125+
settingName,
126+
encodedValue
127+
);
128+
} catch (error) {
129+
if (error instanceof Error) {
130+
setSettingError(error.message);
131+
} else {
132+
setSettingError('An unknown error occurred');
133+
}
134+
}
135+
}}
136+
title="Write Setting"
137+
/>
138+
</View>
139+
</ScrollView>
140+
</SafeAreaView>
141+
);
142+
}

0 commit comments

Comments
 (0)