Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings #470

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:

ios-example:
name: iOS example app
runs-on: macos-14
runs-on: macos-15-arm64
needs: build
steps:
- name: Checkout
Expand Down
46 changes: 26 additions & 20 deletions example/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,42 @@ import { ExpoConfig } from '@expo/config-types';
import 'ts-node/register';

const config: ExpoConfig = {
name: "react-native-mcu-manager-example",
slug: "react-native-mcu-manager-example",
assetBundlePatterns: ["**/*"],
orientation: "portrait",
platforms: ["ios", "android"],
scheme: "rnmcumgr",
version: "1.0.0",
name: 'react-native-mcu-manager-example',
slug: 'react-native-mcu-manager-example',
assetBundlePatterns: ['**/*'],
orientation: 'portrait',
platforms: ['ios', 'android'],
scheme: 'rnmcumgr',
version: '1.0.0',
splash: {
image: ".assets/images/pd.png",
backgroundColor: "#FFFFFF",
image: '.assets/images/pd.png',
backgroundColor: '#FFFFFF',
},
ios: {
supportsTablet: true,
bundleIdentifier: "uk.co.playerdata.reactnativemcumanager.example",
bundleIdentifier: 'uk.co.playerdata.reactnativemcumanager.example',
infoPlist: {
NSBluetoothAlwaysUsageDescription: "Requires Bluetooth to perform firmware updates.",
NSBluetoothAlwaysUsageDescription:
'Requires Bluetooth to perform firmware updates.',
},
},
android: {
package: "uk.co.playerdata.reactnativemcumanager.example",
permissions: [
"ACCESS_FINE_LOCATION",
"ACCESS_COARSE_LOCATION",
],
package: 'uk.co.playerdata.reactnativemcumanager.example',
permissions: ['ACCESS_FINE_LOCATION', 'ACCESS_COARSE_LOCATION'],
},
plugins: [
["expo-document-picker"],
["expo-router"],
["./gradlePlugin.ts"]
]
['expo-document-picker'],
['expo-router'],
['./gradlePlugin.ts'],
[
'expo-build-properties',
{
android: {
minSdkVersion: 26,
},
},
],
],
};

export default config;
11 changes: 6 additions & 5 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
"dependencies": {
"@playerdata/react-native-mcu-manager": "workspace:*",
"expo": "52.0.25",
"expo-constants": "~17.0.4",
"expo-build-properties": "0.13.2",
"expo-constants": "17.0.4",
"expo-document-picker": "13.0.2",
"expo-linking": "~7.0.4",
"expo-router": "~4.0.16",
"expo-linking": "7.0.4",
"expo-router": "4.0.16",
"expo-splash-screen": "0.29.20",
"expo-status-bar": "~2.0.1",
"lodash": "4.17.21",
"react": "18.3.1",
"react-native": "0.76.3",
"react-native": "0.76.6",
"react-native-ble-plx": "3.4.0",
"react-native-reanimated": "~3.16.1",
"react-native-reanimated": "3.16.7",
"react-native-safe-area-context": "4.14.1",
"react-native-screens": "~4.4.0",
"react-native-toast-message": "2.2.1"
Expand Down
1 change: 1 addition & 0 deletions example/src/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const RootLayout = () => {
options={{ title: 'Home' }}
/>
<Tabs.Screen name="update" options={{ title: 'Update' }} />
<Tabs.Screen name="settings" options={{ title: 'Settings' }} />
</Tabs>
</SelectedDeviceProvider>
);
Expand Down
142 changes: 142 additions & 0 deletions example/src/app/settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import {
readSetting,
writeSetting,
} from '@playerdata/react-native-mcu-manager';
import { Buffer } from 'buffer';

import React, { useState } from 'react';
import {
Button,
SafeAreaView,
ScrollView,
StyleSheet,
Text,
TextInput,
View,
} from 'react-native';

import { useSelectedDevice } from '../context/selectedDevice';

const styles = StyleSheet.create({
root: {
padding: 16,
},

block: {
marginBottom: 16,
},

list: {
padding: 16,
},
});

export default function settings() {
const { selectedDevice } = useSelectedDevice();

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

return (
<SafeAreaView>
<ScrollView contentContainerStyle={styles.root}>
<Text style={styles.block}>Step 1 - Select Device to Update</Text>

<View style={styles.block}>
{selectedDevice && (
<>
<Text>Selected:</Text>
<Text>{selectedDevice.deviceName}</Text>
</>
)}
</View>

<Text style={styles.block}>
Step 2 - Read or Write settings to the device
</Text>

<View style={styles.block}>
<Text>Setting Name</Text>

<TextInput
value={settingName || ''}
onChangeText={setSettingName}
placeholder="Enter setting name"
/>
</View>

<View style={styles.block}>
<Text>Setting Value</Text>

<TextInput
value={settingValue || ''}
onChangeText={setSettingValue}
placeholder="Enter setting value"
/>
</View>

{settingError && (
<View style={styles.block}>
<Text>{settingError}</Text>
</View>
)}

<View style={styles.block}>
<Button
onPress={async () => {
try {
setSettingError(null);

const valueB64 = await readSetting(
selectedDevice?.deviceId || '',
settingName
);

const decodedValue = Buffer.from(valueB64, 'base64').toString(
'binary'
);
setSettingValue(decodedValue);
} catch (error) {
if (error instanceof Error) {
setSettingError(error.message);
} else {
setSettingError('An unknown error occurred');
}
}
}}
title="Read Setting"
/>
</View>

<View style={styles.block}>
<Button
onPress={async () => {
try {
setSettingError(null);

const encodedValue = Buffer.from(
settingValue,
'binary'
).toString('base64');

await writeSetting(
selectedDevice?.deviceId || '',
settingName,
encodedValue
);
} catch (error) {
if (error instanceof Error) {
setSettingError(error.message);
} else {
setSettingError('An unknown error occurred');
}
}
}}
title="Write Setting"
/>
</View>
</ScrollView>
</SafeAreaView>
);
}
Loading
Loading