Skip to content

Commit

Permalink
Merge pull request #35 from edge-ml/board/nanoV2
Browse files Browse the repository at this point in the history
Board/nano v2
  • Loading branch information
tk-king authored Nov 29, 2023
2 parents 5f8c8f6 + 57db181 commit 5d7d725
Show file tree
Hide file tree
Showing 19 changed files with 676 additions and 38 deletions.
2 changes: 1 addition & 1 deletion library.properties
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.
Expand Down
2 changes: 2 additions & 0 deletions src/EdgeML.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef Edge_ML_BASE_H_
#define Edge_ML_BASE_H_

#include <config/flags.h>

// arduino-libraries/Arduino_BHY2@^1.0.6

#include <config/flags.h>
Expand Down
102 changes: 102 additions & 0 deletions src/boards/generic_boards/ble33nanov2/APDS_Sensor_NanoV2.cpp
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 src/boards/generic_boards/ble33nanov2/APDS_Sensor_NanoV2.h
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 src/boards/generic_boards/ble33nanov2/BARO_Sensor_NanoV2.cpp
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 src/boards/generic_boards/ble33nanov2/BARO_Sensor_NanoV2.h
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 src/boards/generic_boards/ble33nanov2/HTS_Sensor_NanoV2.cpp
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
33 changes: 33 additions & 0 deletions src/boards/generic_boards/ble33nanov2/HTS_Sensor_NanoV2.h
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 src/boards/generic_boards/ble33nanov2/IMU_Sensor_NanoV2.cpp
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
27 changes: 27 additions & 0 deletions src/boards/generic_boards/ble33nanov2/IMU_Sensor_NanoV2.h
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
Loading

0 comments on commit 5d7d725

Please sign in to comment.