forked from momolarson/BLEServiceDiscovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBLEWriteCharacteristic.js
79 lines (69 loc) · 2.53 KB
/
BLEWriteCharacteristic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, {useState} from 'react';
import { connect } from 'react-redux';
import {NavigationContainer } from '@react-navigation/native';
import {createStackNavigator } from '@react-navigation/stack';
import {SafeAreaView, View, FlatList, StyleSheet, Text , TextInput,Button} from 'react-native';
import {writeCharacteristic} from './actions';
import DataActivityIndicator from './DataActivityIndicator';
function Item({ characteristic }) {
return (
<View style={styles.item}>
<Text style={styles.title}>{characteristic.uuid}</Text>
<Text style={styles.subtext}>Notifiable: {characteristic.isNotifiable.toString()}</Text>
<Text style={styles.subtext}>Notifying: {characteristic.isNotifying.toString()}</Text>
<Text style={styles.subtext}>Readable: {characteristic.isReadable.toString()}</Text>
<Text style={styles.subtext}>Indicatable: {characteristic.isIndicatable.toString()}</Text>
<Text style={styles.subtext}>Writeable with Response: {characteristic.isWritableWithResponse.toString()}</Text>
<Text style={styles.subtext}>Writeable without Response: {characteristic.isWritableWithoutResponse.toString()}</Text>
</View>
);
}
function handleClick (ReduxStore,text){
ReduxStore.writeCharacteristic(text + '\n');
}
function BLEWritecharacteristic(ReduxStore) {
const [text,setText] = useState({'text':'write something to device'});
return(
<>
<Text>{ReduxStore.selectedCharacteristic.uuid}</Text>
<Item characteristic={ReduxStore.selectedCharacteristic} />
<TextInput
onChangeText={(text) => setText({text})}
style={{ height: 40, color: 'black', borderColor: 'gray', borderWidth: 1 }}
value={text.text}
/>
<Button
title="Write"
onPress={() => handleClick(ReduxStore,text.text)}
/>
</>
);
}
//}
function mapStateToProps(state){
return{
selectedCharacteristic: state.BLEs.selectedCharacteristic,
};
}
const mapDispatchToProps = dispatch => ({
writeCharacteristic: text => dispatch(writeCharacteristic(text))
})
export default connect(mapStateToProps,mapDispatchToProps,null,{ forwardRef: true })(BLEWritecharacteristic);
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 2,
},
item: {
backgroundColor: '#f9c2ff',
padding: 20,
marginVertical: 8,
marginHorizontal: 16,
},
title: {
fontSize: 14,
},
subtext: {
fontSize: 10,
}
});