forked from pawar4/ECE477
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
32,866 additions
and
1,779 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
[android] | ||
target = Google Inc.:Google APIs:23 | ||
|
||
[maven_repositories] | ||
central = https://repo1.maven.org/maven2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: '@react-native-community', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
[ignore] | ||
; We fork some components by platform | ||
.*/*[.]android.js | ||
|
||
; Ignore "BUCK" generated dirs | ||
<PROJECT_ROOT>/\.buckd/ | ||
|
||
; Ignore polyfills | ||
node_modules/react-native/Libraries/polyfills/.* | ||
|
||
; These should not be required directly | ||
; require from fbjs/lib instead: require('fbjs/lib/warning') | ||
node_modules/warning/.* | ||
|
||
; Flow doesn't support platforms | ||
.*/Libraries/Utilities/LoadingView.js | ||
|
||
[untyped] | ||
.*/node_modules/@react-native-community/cli/.*/.* | ||
|
||
[include] | ||
|
||
[libs] | ||
node_modules/react-native/interface.js | ||
node_modules/react-native/flow/ | ||
|
||
[options] | ||
emoji=true | ||
|
||
esproposal.optional_chaining=enable | ||
esproposal.nullish_coalescing=enable | ||
|
||
module.file_ext=.js | ||
module.file_ext=.json | ||
module.file_ext=.ios.js | ||
|
||
munge_underscores=true | ||
|
||
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1' | ||
module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub' | ||
|
||
suppress_type=$FlowIssue | ||
suppress_type=$FlowFixMe | ||
suppress_type=$FlowFixMeProps | ||
suppress_type=$FlowFixMeState | ||
|
||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\) | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+ | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError | ||
|
||
[lints] | ||
sketchy-null-number=warn | ||
sketchy-null-mixed=warn | ||
sketchy-number=warn | ||
untyped-type-import=warn | ||
nonstrict-import=warn | ||
deprecated-type=warn | ||
unsafe-getters-setters=warn | ||
unnecessary-invariant=warn | ||
signature-verification-failure=warn | ||
deprecated-utility=error | ||
|
||
[strict] | ||
deprecated-type | ||
nonstrict-import | ||
sketchy-null | ||
unclear-type | ||
unsafe-getters-setters | ||
untyped-import | ||
untyped-type-import | ||
|
||
[version] | ||
^0.122.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pbxproj -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# OSX | ||
# | ||
.DS_Store | ||
|
||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
|
||
# Android/IntelliJ | ||
# | ||
build/ | ||
.idea | ||
.gradle | ||
local.properties | ||
*.iml | ||
|
||
# node.js | ||
# | ||
node_modules/ | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
# BUCK | ||
buck-out/ | ||
\.buckd/ | ||
*.keystore | ||
!debug.keystore | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/ | ||
|
||
*/fastlane/report.xml | ||
*/fastlane/Preview.html | ||
*/fastlane/screenshots | ||
|
||
# Bundle artifact | ||
*.jsbundle | ||
|
||
# CocoaPods | ||
/ios/Pods/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
bracketSpacing: false, | ||
jsxBracketSameLine: true, | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
import * as React from 'react'; | ||
import { useState } from 'react'; | ||
import { NativeEventEmitter, NativeModules, Platform, PermissionsAndroid } from 'react-native'; | ||
import { Text, View, Button } from 'react-native'; | ||
import { NavigationContainer } from '@react-navigation/native'; | ||
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; | ||
import MapView from "react-native-maps"; | ||
// import BleManager from 'react-native-ble-manager'; | ||
import BluetoothSerial from 'react-native-bluetooth-serial' | ||
|
||
|
||
function HomeScreen() { | ||
const [isconnected, setIsConnected] = useState(false); //state variable to hold boolean value of whether any device is connected | ||
const [weight,setWeight] = useState("5 kg"); | ||
const peripherals = new Map(); | ||
const [list, setList] = useState([]); //state variable to hold all discovered peripherals(not connected) | ||
const [device, setDevice] = useState(null); // state variable to hold current connected peripheral | ||
const [readdata, setreaddata] = useState(""); //state variable to hold current read message | ||
|
||
|
||
//Component to discover all unpaired devices within range | ||
const discoverUnpaired = () => { | ||
BluetoothSerial.discoverUnpairedDevices() | ||
.then((unpairedDevices) => { | ||
setList(unpairedDevices); | ||
}) | ||
.catch(err => {console.error(err); | ||
}); | ||
for(var i = 0; i < list.length; ++i) | ||
{ | ||
console.log(list[i]); | ||
} | ||
} | ||
|
||
discoverPaired_Connect = () => { | ||
discoverPaired(); | ||
BluetoothConnect(); | ||
} | ||
|
||
//Component to discover paired device (HC05) with phone | ||
const discoverPaired = () => { | ||
BluetoothSerial.list().then((pairedDevices) => { | ||
setDevice(pairedDevices[0]); | ||
//console.log(device); | ||
}).catch(err => {console.error(err); | ||
}); | ||
} | ||
|
||
//Component to connect to the HC05 | ||
const BluetoothConnect = () => { | ||
BluetoothSerial.connect(device.id).then((res) => { | ||
console.log("Connected to device:",device.name); | ||
setIsConnected(true); | ||
}).catch(err => {console.error(err);}); | ||
// setDevice(device); | ||
//BluetoothSerial.pairDevice(device); | ||
} | ||
|
||
//Component to disconnect from bluetooth device | ||
const BluetoothDisconnect = () => { | ||
BluetoothSerial.disconnect() | ||
.catch(err => {console.error(err);}); | ||
setIsConnected(false); | ||
console.log("Disconnected from backpack") | ||
} | ||
|
||
const checkconnection = () => { | ||
BluetoothSerial.isConnected().then((res) => | ||
{ | ||
console.log(res) | ||
}).catch(err => {console.error(err);}); | ||
} | ||
|
||
const GetWeight = () => { | ||
setWeight("500 kg"); | ||
} | ||
|
||
const WriteMessage = (message) => { | ||
if (!isconnected) { | ||
console.log('You must connect to device first'); | ||
} | ||
|
||
BluetoothSerial.write(message) | ||
.then((res) => { | ||
console.log('Successfuly wrote to device'); | ||
//this.setState({ connected: true }) | ||
}) | ||
.catch(err => {console.error(err);}); | ||
} | ||
|
||
React.useEffect(() => { | ||
// this is a constructor (runs once) | ||
if (Platform.OS === 'android' && Platform.Version >= 23) { | ||
PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION).then((result) => { | ||
if (result) { | ||
console.log("Permission is OK"); | ||
} else { | ||
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION).then((result) => { | ||
if (result) { | ||
console.log("User accept"); | ||
} else { | ||
console.log("User refuse"); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
discoverPaired(); //automatically as app opens up, the app tries to connect to the backpack. | ||
|
||
BluetoothSerial.withDelimiter('\r\n').then((res) => { | ||
console.log("Delimiter has been set up "); | ||
BluetoothSerial.on('read', data => { | ||
setreaddata(data); | ||
//console.log(`DATA FROM BLUETOOTH: ${data.data}`); | ||
// console.log(data.data); | ||
}); | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<View style={{ flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center'}}> | ||
|
||
<View style={{margin: 10}}> | ||
<Button title="Discover Paired devices" onPress={() => discoverPaired() } /> | ||
</View> | ||
|
||
<View style={{margin: 10}}> | ||
<Button title="Connect to backpack" onPress={() => BluetoothConnect() } /> | ||
</View> | ||
|
||
<View style={{margin: 10}}> | ||
<Button title="Disconnect from backpack" onPress={() => BluetoothDisconnect() } /> | ||
</View> | ||
|
||
<View style={{margin: 10}}> | ||
<Button title="Check if connected" onPress={() => checkconnection() } /> | ||
</View> | ||
|
||
<View style={{margin: 10}}> | ||
<Button title="Send request to backpack" onPress={() => WriteMessage(String("Hello\r\n")) } /> | ||
</View> | ||
|
||
<View style={{margin: 10}}> | ||
<Button title="Get Backpack Weight" onPress={() => GetWeight() } /> | ||
</View> | ||
|
||
<Text> {readdata.data} </Text> | ||
<Text> {weight} </Text> | ||
</View> | ||
); | ||
|
||
|
||
} | ||
|
||
function GPSScreen() { | ||
const [region, setRegion] = useState({ | ||
latitude: 51.5079145, | ||
longitude: -0.0899163, | ||
latitudeDelta: 0.01, | ||
longitudeDelta: 0.01 | ||
}); | ||
|
||
return ( | ||
<MapView | ||
style={{ flex: 1 }} | ||
region={region} | ||
onRegionChangeComplete={region => setRegion(region)} | ||
showsUserLocation={true} | ||
followsUserLocation={true} | ||
/> | ||
); | ||
} | ||
|
||
function SettingScreen() { | ||
return ( | ||
<View style={{flex: 1}}> | ||
</View> | ||
); | ||
} | ||
|
||
const Tab = createBottomTabNavigator(); | ||
|
||
function MyTabs() { | ||
return ( | ||
<Tab.Navigator> | ||
<Tab.Screen name='Home' component={HomeScreen} /> | ||
<Tab.Screen name='GPS' component={GPSScreen} /> | ||
<Tab.Screen name="Settings" component={SettingScreen} /> | ||
</Tab.Navigator> | ||
); | ||
} | ||
|
||
export default function App() { | ||
return ( | ||
<NavigationContainer> | ||
<MyTabs /> | ||
</NavigationContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* @format | ||
*/ | ||
|
||
import 'react-native'; | ||
import React from 'react'; | ||
import App from '../App'; | ||
|
||
// Note: test renderer must be required after react-native. | ||
import renderer from 'react-test-renderer'; | ||
|
||
it('renders correctly', () => { | ||
renderer.create(<App />); | ||
}); |
Oops, something went wrong.