Skip to content

Commit fc09554

Browse files
committed
fixup! feat: adding settings capabilities
1 parent de759f6 commit fc09554

File tree

6 files changed

+406
-106
lines changed

6 files changed

+406
-106
lines changed

example/app/_layout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { Tabs } from 'expo-router';
22
import 'react-native-reanimated';
33

4-
export default function Home() {
4+
export default function Root() {
55
return (
66
<Tabs>
7+
<Tabs.Screen
8+
name="index"
9+
options={{ title: 'Home' }}
10+
/>
711
<Tabs.Screen
812
name="update"
913
options={{ title: 'Update' }}

example/app/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import { Text, View } from 'react-native';
3+
4+
export default function Home() {
5+
return (
6+
<View>
7+
<Text>Use the tabs below to choose which function to test</Text>
8+
</View>
9+
);
10+
}

example/app/settings.tsx

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default function settings() {
4040
null
4141
);
4242

43+
const [settingError, setSettingError] = useState<string | null>(null);
4344
const [settingName, setSettingName] = useState<string>('');
4445
const [settingValue, setSettingValue] = useState<string>('');
4546

@@ -106,31 +107,52 @@ export default function settings() {
106107
<TextInput
107108
value={settingValue || ''}
108109
onChangeText={setSettingValue}
109-
placeholder="Enter setting name"
110+
placeholder="Enter setting value"
110111
/>
111112
</View>
112113

114+
{settingError && (
115+
<View style={styles.block}>
116+
<Text>{settingError}</Text>
117+
</View>
118+
)}
119+
113120
<View style={styles.block}>
114121
<Button
115122
onPress={async () => {
116-
const valueB64 = await readSetting(selectedDeviceId, settingName);
117-
const decodedValue = Buffer.from(valueB64, 'base64').toString(
118-
'binary'
119-
);
120-
setSettingValue(decodedValue);
123+
try {
124+
const valueB64 = await readSetting(selectedDeviceId, settingName);
125+
const decodedValue = Buffer.from(valueB64, 'base64').toString(
126+
'binary'
127+
);
128+
setSettingValue(decodedValue);
129+
} catch (error) {
130+
if (error instanceof Error) {
131+
setSettingError(error.message);
132+
} else {
133+
setSettingError('An unknown error occurred');
134+
}
135+
}
121136
}}
122137
title="Read Setting"
123138
/>
124139
</View>
125140

126141
<View style={styles.block}>
127-
<Text>{settingValue}</Text>
128142
<Button
129143
onPress={async () => {
130-
const encodedValue = Buffer.from(settingValue, 'binary').toString(
131-
'base64'
132-
);
133-
await writeSetting(selectedDeviceId, settingName, encodedValue);
144+
try {
145+
const encodedValue = Buffer.from(settingValue, 'binary').toString(
146+
'base64'
147+
);
148+
await writeSetting(selectedDeviceId, settingName, encodedValue);
149+
} catch (error) {
150+
if (error instanceof Error) {
151+
setSettingError(error.message);
152+
} else {
153+
setSettingError('An unknown error occurred');
154+
}
155+
}
134156
}}
135157
title="Write Setting"
136158
/>

example/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
"dependencies": {
1515
"@playerdata/react-native-mcu-manager": "workspace:*",
1616
"expo": "^52.0.25",
17-
"expo-build-properties": "0.12.5",
17+
"expo-build-properties": "0.13.2",
1818
"expo-constants": "~17.0.4",
1919
"expo-document-picker": "13.0.2",
20-
"expo-linking": "~7.0.4",
21-
"expo-router": "~4.0.16",
20+
"expo-linking": "7.0.4",
21+
"expo-router": "4.0.16",
2222
"expo-splash-screen": "0.29.20",
2323
"expo-status-bar": "~2.0.1",
2424
"lodash": "4.17.21",
2525
"react": "18.3.1",
26-
"react-native": "0.76.3",
26+
"react-native": "0.76.6",
2727
"react-native-ble-plx": "3.4.0",
2828
"react-native-reanimated": "^3.16.7",
2929
"react-native-safe-area-context": "4.12.0",

0 commit comments

Comments
 (0)