Hello everybody, I’m trying to create an app to manage Ti SensorTag 2.
Ti Sensor Tag is a cheap module with a lot of sensor:
http://www.ti.com/ww/en/wireless_connectivity/sensortag2015/?INTC=SensorTag&HQS=sensortag
It can be used for beacon, temperature, tilt detection, light etc etc etc…
You can manage the sensor using a js library created by Evothing,
This is the HTML sample app provided by Evothing:
I’m trying to create a module to manage the sensor inside Angular and so with Ionic.
I have this code:
angular.module('sensor', [])
.run( (evothings, sensor) => {
evothings.scriptsLoaded(sensor.initialise)
})
.factory( 'evothings', ()=> {
// fake global deps
return {
tisensortag: {
createInstance: angular.noop,
ble: {
status: {},
error:{}
}
},
scriptsLoaded: ref => ref()
}
})
.factory( 'sensor', evothings => {
let sensortag
let currentDisplayStatus = ''
let currentAccelerometerValues = {}
function statusHandler(status) {
setDisplayStatus(status)
if (evothings.tisensortag.ble.status.SENSORTAG_ONLINE === status) {
// displaySprite()
}
}
function errorHandler(error) {
if (evothings.easyble.error.DISCONNECTED === error)
{
setDisplayStatus('Disconnected')
// sprite.hide()
}
else
{
setDisplayStatus('Error: ' + error)
}
}
function accelerometerHandler(data) {
var values = sensortag.getAccelerometerValues(data)
currentAccelerometerValues = {
rawX: values.x,
rawY: values.y,
degreeX: values.x/ 10*90,
degreeY: values.y/ 10*90
}
}
function setDisplayStatus(status){
currentDisplayStatus = status
}
return {
get displayStatus() {
return currentDisplayStatus
},
get accelerometerValues() {
return currentAccelerometerValues
},
initialise() {
// Create SensorTag CC2650 instance.
sensortag = evothings.tisensortag
.createInstance(evothings.tisensortag.CC2650_BLUETOOTH_SMART)
// Set up callbacks and sensors.
sensortag
.statusCallback(statusHandler)
.errorCallback(errorHandler)
.accelerometerCallback(accelerometerHandler, 200)
},
connect() {
sensortag.connectToNearestDevice()
},
disconnect() {
sensortag.disconnectDevice()
setDisplayStatus()'Disconnected')
}
}
})
I cannot understand how to save in the scope the callbacks, for example the connection status and the accelerometer value.
Can you help me?