Skip to content

Commit

Permalink
now the APDS also sends the current ambient light value
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Hirschberger committed Mar 30, 2020
1 parent c59e26b commit cc7d251
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,27 @@ The Arduino directory contains examples i had written for my Arduino UNO R3 and
payload: true
}
],
'Gesture: DOWN': [
'Gesture: DOWN': [
{
notification: 'VOLUME_DOWN',
payload: {
step: 2
step: 2
}
},
{
notification: 'USER_PRESENCE',
payload: true
}
],
'AmbientLight: ': [
{
notification: 'AMBIENT_LIGHT',
payloadReplacement: '###VALUE###',
replacementPrefix: 'AmbientLight: ',
payload: {
value: '###VALUE###'
}
}
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
upDownScale: 8
}
}
],
'AmbientLight: ': [
{
notification: 'AMBIENT_LIGHT',
payloadReplacement: '###VALUE###',
replacementPrefix: 'AmbientLight: ',
payload: {
value: '###VALUE###'
}
}
]
}
},
Expand Down
18 changes: 16 additions & 2 deletions examples/APDS-9960_Multi-VL53L1X/APDS-9960_Multi-VL53L1X.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ unsigned long sensorsLastHit[SENSOR_CNT];
// gesture sensor interrup pin
#define APDS9960_INT 2 // Needs to be an interrupt pin
#define APDS9960_DEBOUNCE 500 //Time between two accepted interrupts
#define APDS9960_AMBIENTLIGHT_INTERVAL 10000 //Time between two accepted interrupts
unsigned long APDS9960LastHit = 0;
unsigned long APDS9960LastAmbientLight = 0;
uint16_t APDS9960AmbientLight = 0;

// GLOBAL VARIABLES

Expand Down Expand Up @@ -116,7 +119,8 @@ void setup() {
if (gestureSensor.init()) {

Serial.println(F("INFO: APDS-9960 initialization complete"));


gestureSensor.enableLightSensor(false);
attachInterrupt(digitalPinToInterrupt(APDS9960_INT), interruptRoutine, FALLING);

if (gestureSensor.enableGestureSensor(true)) {
Expand Down Expand Up @@ -178,9 +182,19 @@ void loop() {

delay(200);
}
}
}

if (gesture_ready){
unsigned long curTime = millis();
if((curTime - APDS9960LastAmbientLight) > APDS9960_AMBIENTLIGHT_INTERVAL){
if(!gestureSensor.readAmbientLight(APDS9960AmbientLight)){
Serial.print("Problem with AmbientLight");
} else {
Serial.print("AmbientLight: ");
Serial.println(APDS9960AmbientLight);
APDS9960LastAmbientLight = curTime;
}
}
// check if there was an interrupt in the meantime
handleInterrupt();
}
Expand Down
6 changes: 5 additions & 1 deletion examples/APDS-9960_Multi-VL53L1X/APDS-9960_Multi-VL53L1X.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ I use a debounce for the APDS-9960 as well to avoid getting no outputs for other

#define APDS9960_DEBOUNCE 500 //Time between two accepted interrupts

The APDS-9960 has an ambient light sensor we use to send the current light intensity in intervals. The interval is configured with the following value:

#define APDS9960_AMBIENTLIGHT_INTERVAL 10000 //Time between two accepted interrupts


## CONCLUSION ##
If everything went well we do now get gestures and hits transmitted on the serial interface and can react to them on the Raspberry Pi.
If a hit happend for a VL53L1X sensor hits during the DEBOUNCE period will be ignored.
If a hit happend for a VL53L1X sensor hits during the DEBOUNCE period will be ignored. Also in periodic intervals the current ambient light value will be transmitted.
24 changes: 23 additions & 1 deletion node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,30 @@ module.exports = NodeHelper.create({
var payload = {}
} else {
var payload = self.config.devices[curDev].messages[curExptMessage][curNotification].payload
if(typeof self.config.devices[curDev].messages[curExptMessage][curNotification].payloadReplacement !== 'undefined'){
var payloadReplacementString = self.config.devices[curDev].messages[curExptMessage][curNotification].payloadReplacement
if(typeof self.config.devices[curDev].messages[curExptMessage][curNotification].replacementPrefix !== 'undefined'){
replacementPrefix = self.config.devices[curDev].messages[curExptMessage][curNotification].replacementPrefix
} else {
replacementPrefix = ""
}

var curReplacementValue = curData.substring(replacementPrefix.length-1,curData.length-1)

var newPayload = {}
for(var curPayloadKey in payload){
var curPayloadValue = payload[curPayloadKey]
if(typeof curPayloadValue === 'string'){
newPayload[curPayloadKey] = curPayloadValue.replace(payloadReplacementString,curReplacementValue)
} else {
newPayload[curPayloadKey] = curPayloadValue
}
}

payload = newPayload
}
}
self.sendSocketNotification(self.config.devices[curDev].messages[curExptMessage][curNotification].notification,payload)
self.sendSocketNotification(self.config.devices[curDev].messages[curExptMessage][curNotification].notification,newPayload)
}
}
}
Expand Down

0 comments on commit cc7d251

Please sign in to comment.