Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 3409989

Browse files
added light sensor, improved mic to 16bit 16khz
1 parent 2ff1ae3 commit 3409989

File tree

5 files changed

+99
-11
lines changed

5 files changed

+99
-11
lines changed

src/ingestion-sdk-platform/wio-terminal/ei_device_wio_terminal.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@
4242
typedef enum
4343
{
4444
ACCELEROMETER = 0,
45+
MICROPHONE,
46+
LIGHT,
4547
GAS,
4648
BME280,
4749
DPS310,
4850
TFMINI,
4951
BMI088,
5052
ULTRASONIC,
51-
SCD30,
52-
MICROPHONE
53+
SCD30
5354

54-
}used_sensors_t;
55+
} used_sensors_t;
5556

5657
#define EDGE_STRINGIZE_(x) #x
5758
#define EDGE_STRINGIZE(x) EDGE_STRINGIZE_(x)
@@ -180,6 +181,17 @@ bool EiDeviceWioTerminal::get_sensor_list(const ei_device_sensor_t **sensor_list
180181
sensors[ACCELEROMETER].frequencies[0] = 62.5f;
181182
sensors[ACCELEROMETER].frequencies[1] = 100.0f;
182183

184+
sensors[MICROPHONE].name = "Built-in microphone";
185+
sensors[MICROPHONE].start_sampling_cb = &ei_microphone_setup_data_sampling;
186+
sensors[MICROPHONE].max_sample_length_s = 5;
187+
sensors[MICROPHONE].frequencies[0] = 16000.0f;
188+
189+
sensors[LIGHT].name = "Built-in light sensor";
190+
sensors[LIGHT].start_sampling_cb = &ei_light_setup_data_sampling;
191+
sensors[LIGHT].max_sample_length_s = available_bytes / (100 * SIZEOF_N_AXIS_SAMPLED);
192+
sensors[LIGHT].frequencies[0] = 62.5f;
193+
sensors[LIGHT].frequencies[1] = 100.0f;
194+
183195
sensors[GAS].name = "External multichannel gas(Grove-multichannel gas v2)";
184196
sensors[GAS].start_sampling_cb = &ei_mutlgas_setup_data_sampling;
185197
sensors[GAS].max_sample_length_s = available_bytes / (100 * SIZEOF_N_GAS_SAMPLED);
@@ -216,11 +228,6 @@ bool EiDeviceWioTerminal::get_sensor_list(const ei_device_sensor_t **sensor_list
216228
sensors[ULTRASONIC].frequencies[0] = 62.5f;
217229
sensors[ULTRASONIC].frequencies[1] = 100.0f;
218230

219-
sensors[MICROPHONE].name = "Built-in microphone";
220-
sensors[MICROPHONE].start_sampling_cb = &ei_microphone_setup_data_sampling;
221-
sensors[MICROPHONE].max_sample_length_s = 5;
222-
sensors[MICROPHONE].frequencies[0] = 16000.0f;
223-
224231
sensors[SCD30].name = "External CO2+Temp sensor(Grove-SCD30)";
225232
sensors[SCD30].start_sampling_cb = &ei_scd30_setup_data_sampling;
226233
sensors[SCD30].max_sample_length_s = available_bytes / (100 * SIZEOF_N_SCD30_SAMPLED);

src/ingestion-sdk-platform/wio-terminal/ei_device_wio_terminal.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@
2626
/* Include ----------------------------------------------------------------- */
2727
#include "ei_device_info.h"
2828
#include "ei_inertialsensor.h"
29+
#include "ei_microphone.h"
30+
#include "ei_light.h"
2931
#include "ei_mutlgassensor.h"
3032
#include "ei_bme280.h"
3133
#include "ei_dps310.h"
3234
#include "ei_tfmini.h"
3335
#include "ei_bmi088.h"
3436
#include "ei_ultrasonic.h"
35-
#include "ei_microphone.h"
3637
#include "ei_scd30.h"
3738
#include "sfud_fs_commands.h"
3839

3940
/** Number of sensors used */
40-
#define EI_DEVICE_N_SENSORS 9
41+
#define EI_DEVICE_N_SENSORS 10
4142

4243
/** C Callback types */
4344
typedef int (*c_callback)(uint8_t out_buffer[32], size_t *out_size);

src/sensors/ei_light.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
/* Include ----------------------------------------------------------------- */
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#include "ei_light.h"
7+
8+
#include "ei_config_types.h"
9+
10+
#include "ei_device_wio_terminal.h"
11+
#include "sensor_aq.h"
12+
13+
#include <Arduino.h>
14+
15+
extern void ei_printf(const char *format, ...);
16+
extern ei_config_t *ei_config_get_config();
17+
extern EI_CONFIG_ERROR ei_config_set_sample_interval(float interval);
18+
19+
// extern sampler_callback cb_sampler;
20+
21+
static float light_data[N_ULTRASONIC_SAMPLED] = {0};
22+
23+
bool ei_light_init(void)
24+
{
25+
pinMode(WIO_LIGHT, INPUT);
26+
}
27+
28+
bool ei_light_read_data(sampler_callback callback)
29+
{
30+
light_data[0] = analogRead(WIO_LIGHT); // Distance in cm
31+
// delay(20); // Short delay to avoid huge data sets
32+
33+
if (callback((const void *)&light_data[0], SIZEOF_N_LIGHT_SAMPLED))
34+
return 1;
35+
return 0;
36+
37+
}
38+
39+
bool ei_light_setup_data_sampling(void)
40+
{
41+
42+
if (ei_config_get_config()->sample_interval_ms < 10.0f)
43+
{
44+
ei_config_set_sample_interval(10.0f);
45+
}
46+
47+
sensor_aq_payload_info payload = {
48+
// Unique device ID (optional), set this to e.g. MAC address or device EUI **if** your device has one
49+
EiDevice.get_id_pointer(),
50+
// Device type (required), use the same device type for similar devices
51+
EiDevice.get_type_pointer(),
52+
// How often new data is sampled in ms. (100Hz = every 10 ms.)
53+
ei_config_get_config()->sample_interval_ms,
54+
{{"Illumination", "na"},
55+
},
56+
};
57+
58+
ei_light_init();
59+
60+
ei_sampler_start_sampling(&ei_light_read_data,&payload, SIZEOF_N_LIGHT_SAMPLED);
61+
}

src/sensors/ei_light.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
#ifndef _EI_LIGHT_H
3+
#define _EI_LIGHT_H
4+
5+
/* Include ----------------------------------------------------------------- */
6+
#include "ei_sampler.h"
7+
8+
/** Number of axis used and sample data format */
9+
typedef float sample_format_t;
10+
#define N_LIGHT_SAMPLED 1
11+
#define SIZEOF_N_LIGHT_SAMPLED (sizeof(sample_format_t) * N_LIGHT_SAMPLED)
12+
13+
14+
/* Function prototypes ----------------------------------------------------- */
15+
bool ei_light_init(void);
16+
bool ei_light_sample_start(sampler_callback callback, float sample_interval_ms);
17+
bool ei_light_setup_data_sampling(void);
18+
bool ei_light_read_data(sampler_callback callback );
19+
20+
#endif

src/sensors/ei_microphone.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static uint32_t headerOffset = 0;
4040

4141
static unsigned char ei_mic_ctx_buffer[1024];
4242
static uint8_t temp_buffer[4096];
43-
//static int16_t temp_buf[4096*3];
4443
static sensor_aq_signing_ctx_t ei_mic_signing_ctx;
4544
static sensor_aq_mbedtls_hs256_ctx_t ei_mic_hs_ctx;
4645

0 commit comments

Comments
 (0)