-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from edge-ml/board/nanoV2
Board/nano v2
- Loading branch information
Showing
19 changed files
with
676 additions
and
38 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=EdgeML-Arduino | ||
version=1.3.3 | ||
version=1.3.4 | ||
author=edge-ml | ||
maintainer=edge-ml <[email protected]> | ||
sentence=Library to use the Nicla Sense ME and BLE Nano 33 with edge-ml. | ||
|
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
102 changes: 102 additions & 0 deletions
102
src/boards/generic_boards/ble33nanov2/APDS_Sensor_NanoV2.cpp
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,102 @@ | ||
#include "config/flags.h" | ||
#if defined NORMAL_BOARD | ||
|
||
#include "APDS_Sensor_NanoV2.h" | ||
|
||
void APDS_Sensor_NanoV2::start() { | ||
if (APDS.begin()) { | ||
available = true; | ||
} | ||
} | ||
|
||
void APDS_Sensor_NanoV2::end() { | ||
APDS.end(); | ||
available = false; | ||
} | ||
|
||
void APDS_Sensor_NanoV2::get_data(int sensorID, byte *data) { | ||
switch (sensorID) { | ||
case APDS_COLOUR_NANOV2: { | ||
int r, g, b; | ||
get_color(r, g, b); | ||
uint16_t * arr = (uint16_t*)data; | ||
arr[0] = (uint16_t)r; | ||
arr[1] = (uint16_t)g; | ||
arr[2] = (uint16_t)b; | ||
break; | ||
} | ||
case APDS_BRIGHT_NANOV2: { | ||
uint16_t * arr = (uint16_t*)data; | ||
arr[0] = get_light(); | ||
break; | ||
} | ||
case APDS_PROX_NANOV2: { | ||
uint16_t * arr = (uint16_t*)data; | ||
arr[0] = get_proximity(); | ||
break; | ||
} | ||
case APDS_GEST_NANOV2: { | ||
int8_t * arr = (int8_t*)data; | ||
arr[0] = get_gesture(); | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void APDS_Sensor_NanoV2::get_color(int& r, int& g, int& b) { | ||
if (!available) { | ||
return; | ||
} | ||
while (! APDS.colorAvailable()) { | ||
delay(2); | ||
} | ||
// In library is only uint16; later converted | ||
APDS.readColor(r, g, b); | ||
|
||
} | ||
|
||
uint16_t APDS_Sensor_NanoV2::get_light() { | ||
if (!available) { | ||
return 0; | ||
} | ||
while (! APDS.colorAvailable()) { | ||
delay(2); | ||
} | ||
|
||
int r, g, b, c; | ||
APDS.readColor(r, g, b, c); | ||
// In library is only uint16 | ||
return (uint16_t)c; | ||
} | ||
|
||
uint8_t APDS_Sensor_NanoV2::get_proximity() { | ||
if (!available) { | ||
return -1; | ||
} | ||
while (! APDS.proximityAvailable()) { | ||
delay(2); | ||
} | ||
// In library is only uint8 | ||
return (uint8_t)APDS.readProximity(); | ||
} | ||
|
||
// Warning if gesture is turned on then it will wait for a gesture!!! | ||
int8_t APDS_Sensor_NanoV2::get_gesture() { | ||
if (!available) { | ||
return -1; | ||
} | ||
while (! APDS.gestureAvailable()) { | ||
delay(2); | ||
} | ||
|
||
// In library is only int8 | ||
return (int8_t)APDS.readGesture(); | ||
} | ||
|
||
int APDS_Sensor_NanoV2::get_sensor_count() { | ||
return sensor_count; | ||
} | ||
|
||
#endif |
32 changes: 32 additions & 0 deletions
32
src/boards/generic_boards/ble33nanov2/APDS_Sensor_NanoV2.h
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,32 @@ | ||
#ifndef APDS_Sensor_H_NANOV2 | ||
#define APDS_Sensor_H_NANOV2 | ||
|
||
#include "config/flags.h" | ||
#if defined NORMAL_BOARD | ||
|
||
#include <Arduino_APDS9960.h> | ||
#include <boards/generic_boards/SensorInterface.h> | ||
#include "SensorID_NanoV2.h" | ||
|
||
class APDS_Sensor_NanoV2: public SensorInterface { | ||
public: | ||
void start() override; | ||
void end() override; | ||
|
||
void get_data(int sensorID, byte *data) override; | ||
|
||
int get_sensor_count() override; | ||
|
||
void get_color(int& r, int& g, int& b); | ||
uint16_t get_light(); | ||
uint8_t get_proximity(); | ||
int8_t get_gesture(); | ||
|
||
const int sensor_count = 4; | ||
|
||
private: | ||
bool available = false; | ||
}; | ||
|
||
#endif | ||
#endif //APDS_Sensor_H_NANOV2 |
34 changes: 34 additions & 0 deletions
34
src/boards/generic_boards/ble33nanov2/BARO_Sensor_NanoV2.cpp
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,34 @@ | ||
#include "config/flags.h" | ||
#if defined NORMAL_BOARD | ||
|
||
#include "BARO_Sensor_NanoV2.h" | ||
|
||
void BARO_Sensor_NanoV2::start() { | ||
if (BARO.begin()) { | ||
available = true; | ||
} | ||
} | ||
|
||
void BARO_Sensor_NanoV2::end() { | ||
BARO.end(); | ||
available = false; | ||
} | ||
|
||
void BARO_Sensor_NanoV2::get_data(int sensorID, byte *data) { | ||
float * floatArray = (float*)data; | ||
floatArray[0] = get_pressure(); | ||
} | ||
|
||
float BARO_Sensor_NanoV2::get_pressure() { | ||
if (!available) { | ||
return 0.0; | ||
} | ||
|
||
return BARO.readPressure(); | ||
} | ||
|
||
int BARO_Sensor_NanoV2::get_sensor_count() { | ||
return sensor_count; | ||
} | ||
|
||
#endif |
28 changes: 28 additions & 0 deletions
28
src/boards/generic_boards/ble33nanov2/BARO_Sensor_NanoV2.h
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,28 @@ | ||
#ifndef BARO_SENSOR_H_NANOV2 | ||
#define BARO_SENSOR_H_NANOV2 | ||
|
||
#include "config/flags.h" | ||
#if defined NORMAL_BOARD | ||
|
||
#include <Arduino_LPS22HB.h> | ||
#include <boards/generic_boards/SensorInterface.h> | ||
#include "SensorID_NanoV2.h" | ||
|
||
class BARO_Sensor_NanoV2: public SensorInterface { | ||
public: | ||
void start() override; | ||
void end() override; | ||
|
||
void get_data(int sensorID, byte *data) override; | ||
|
||
int get_sensor_count() override; | ||
|
||
float get_pressure(); | ||
|
||
const int sensor_count = 1; | ||
private: | ||
bool available = false; | ||
}; | ||
|
||
#endif | ||
#endif //BARO_SENSOR_H_NANOv |
55 changes: 55 additions & 0 deletions
55
src/boards/generic_boards/ble33nanov2/HTS_Sensor_NanoV2.cpp
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,55 @@ | ||
#include "config/flags.h" | ||
#if defined NORMAL_BOARD | ||
|
||
#include "HTS_Sensor_NanoV2.h" | ||
|
||
void HTS_Sensor_NanoV2::start() { | ||
if (HS300x.begin()) { | ||
available = true; | ||
} | ||
} | ||
|
||
void HTS_Sensor_NanoV2::end() { | ||
HS300x.end(); | ||
available = false; | ||
} | ||
|
||
void HTS_Sensor_NanoV2::get_data(int sensorID, byte *data) { | ||
float value; | ||
switch (sensorID) { | ||
case HTS_TEMP_NANOV2: | ||
value = get_temperature(); | ||
break; | ||
case HTS_HUM_NANOV2: | ||
value = get_humidity(); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
float * floatArray = (float*)data; | ||
floatArray[0] = value; | ||
} | ||
|
||
float HTS_Sensor_NanoV2::get_temperature() { | ||
if (!available) { | ||
return 0.0; | ||
} | ||
|
||
// -5 correction from original code | ||
return HS300x.readTemperature()-5; | ||
} | ||
|
||
float HTS_Sensor_NanoV2::get_humidity(){ | ||
if (!available) { | ||
return 0.0; | ||
} | ||
|
||
return HS300x.readHumidity(); | ||
} | ||
|
||
int HTS_Sensor_NanoV2::get_sensor_count() { | ||
return sensor_count; | ||
} | ||
|
||
#endif |
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,33 @@ | ||
#ifndef HTS_SENSOR_H_NANOV2 | ||
#define HTS_SENSOR_H_NANOV2 | ||
|
||
#include "config/flags.h" | ||
#if defined NORMAL_BOARD | ||
|
||
#define CELSIUS CELSIUS_WRAP | ||
#define FAHRENHEIT FAHRENHEIT_WRAP | ||
#include <Arduino_HS300x.h> | ||
#undef CELSIUS | ||
#undef FAHRENHEIT | ||
#include <boards/generic_boards/SensorInterface.h> | ||
#include "SensorID_NanoV2.h" | ||
|
||
class HTS_Sensor_NanoV2: public SensorInterface { | ||
public: | ||
void start() override; | ||
void end() override; | ||
|
||
void get_data(int sensorID, byte *data) override; | ||
|
||
int get_sensor_count() override; | ||
|
||
float get_temperature(); | ||
float get_humidity(); | ||
|
||
const int sensor_count = 2; | ||
private: | ||
bool available = false; | ||
}; | ||
|
||
#endif | ||
#endif //HTS_SENSOR_H_NANOV2 |
48 changes: 48 additions & 0 deletions
48
src/boards/generic_boards/ble33nanov2/IMU_Sensor_NanoV2.cpp
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,48 @@ | ||
#include "config/flags.h" | ||
#if defined NORMAL_BOARD | ||
|
||
#include "IMU_Sensor_NanoV2.h" | ||
|
||
void IMU_Sensor_NanoV2::start() { | ||
if (available) { | ||
return; | ||
} | ||
if (IMU.begin()) { | ||
available = true; | ||
} | ||
} | ||
|
||
void IMU_Sensor_NanoV2::end() { | ||
if (!available) { | ||
return; | ||
} | ||
available = false; | ||
} | ||
|
||
void IMU_Sensor_NanoV2::get_data(int sensorID, byte *data) { | ||
float x, y, z; | ||
switch (sensorID) { | ||
case IMU_ACCELERATION_NANOV2: | ||
IMU.readAcceleration(x,y,z); | ||
break; | ||
case IMU_GYROSCOPE_NANOV2: | ||
IMU.readGyroscope(x,y,z); | ||
break; | ||
case IMU_MAGNET_NANOV2: | ||
IMU.readMagneticField(x,y,z); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
float * floatArray = (float*)data; | ||
floatArray[0] = x; | ||
floatArray[1] = y; | ||
floatArray[2] = z; | ||
} | ||
|
||
int IMU_Sensor_NanoV2::get_sensor_count() { | ||
return sensor_count; | ||
} | ||
|
||
#endif |
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,27 @@ | ||
#ifndef EDGEML_ARDUINO_IMU_SENSOR_NANO_HV2 | ||
#define EDGEML_ARDUINO_IMU_SENSOR_NANO_HV2 | ||
|
||
#include "config/flags.h" | ||
#if defined NORMAL_BOARD | ||
|
||
#include "Arduino_BMI270_BMM150.h" | ||
#include <boards/generic_boards/SensorInterface.h> | ||
#include "SensorID_NanoV2.h" | ||
|
||
class IMU_Sensor_NanoV2: public SensorInterface { | ||
public: | ||
void start() override; | ||
void end() override; | ||
|
||
void get_data(int sensorID, byte data[]) override; | ||
|
||
int get_sensor_count() override; | ||
|
||
const int sensor_count = 3; | ||
|
||
private: | ||
bool available = false; | ||
}; | ||
|
||
#endif | ||
#endif //EDGEML_ARDUINO_IMU_SENSOR_NANO_HV2 |
Oops, something went wrong.