kopia lustrzana https://github.com/AlexFWulff/awulff-pico-playground
changing to float32 model inputs
rodzic
a5b2f83603
commit
6d2c2bdbed
|
@ -0,0 +1 @@
|
|||
alex@Alexs-MBP.home.64612
|
|
@ -13,6 +13,7 @@ pico_sdk_init()
|
|||
|
||||
add_executable(pico-voice
|
||||
source/main.cpp
|
||||
source/lights.cpp
|
||||
)
|
||||
|
||||
include(${MODEL_FOLDER}/edge-impulse-sdk/cmake/utils.cmake)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
alex@Alexs-MacBook-Pro.local.64766
|
|
@ -0,0 +1 @@
|
|||
alex@Alexs-MacBook-Pro.local.64766
|
|
@ -0,0 +1,110 @@
|
|||
#define PIN 7
|
||||
|
||||
#include <pico/multicore.h>
|
||||
#include <stdio.h>
|
||||
#include "Adafruit_NeoPixel.hpp"
|
||||
|
||||
bool update_state(uint32_t *state, bool strip_on) {
|
||||
// check for new state information
|
||||
if (multicore_fifo_rvalid()) {
|
||||
uint32_t val = multicore_fifo_pop_blocking();
|
||||
|
||||
// turn lights off
|
||||
if (val == 2) {
|
||||
printf("Turning lights off\n");
|
||||
multicore_fifo_push_blocking(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// increment state by 1
|
||||
else {
|
||||
if (!strip_on) {
|
||||
printf("Turning lights on\n");
|
||||
multicore_fifo_push_blocking(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SET NUM STATES HERE
|
||||
*state = (*state+1) % 3;
|
||||
printf("Incrementing state to %u\n", *state);
|
||||
multicore_fifo_push_blocking(0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// if no data available just leave as it was
|
||||
return strip_on;
|
||||
}
|
||||
|
||||
void core1_entry() {
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN,
|
||||
NEO_GRB + NEO_KHZ800);
|
||||
strip.begin();
|
||||
//strip.setBrightness(64);
|
||||
strip.show();
|
||||
|
||||
// tell the other core we're ready for data
|
||||
multicore_fifo_push_blocking(0);
|
||||
|
||||
uint32_t state = 0;
|
||||
bool lights_on = false;
|
||||
|
||||
while (1) {
|
||||
lights_on = update_state(&state, lights_on);
|
||||
|
||||
if (!lights_on) {
|
||||
strip.clear();
|
||||
strip.show();
|
||||
sleep_ms(200);
|
||||
}
|
||||
|
||||
// rainbow state
|
||||
else if (state == 0) {
|
||||
uint16_t i, j;
|
||||
|
||||
for(j=0; j<256; j++) {
|
||||
for(i=0; i< strip.numPixels(); i++) {
|
||||
uint8_t WheelPos = ((i * 256 / strip.numPixels()) + j) & 255;
|
||||
uint32_t c = 0;
|
||||
|
||||
WheelPos = 255 - WheelPos;
|
||||
|
||||
if(WheelPos < 85) {
|
||||
c = strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||
}
|
||||
|
||||
else if(WheelPos < 170) {
|
||||
WheelPos -= 85;
|
||||
c = strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||
}
|
||||
|
||||
else {
|
||||
WheelPos -= 170;
|
||||
c = strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||
}
|
||||
|
||||
strip.setPixelColor(i, c);
|
||||
}
|
||||
|
||||
// check if state has changed
|
||||
uint32_t last_state = state;
|
||||
lights_on = update_state(&state, lights_on);
|
||||
if (last_state != state || !lights_on) break;
|
||||
|
||||
strip.show();
|
||||
sleep_ms(10);
|
||||
}
|
||||
}
|
||||
|
||||
// boring
|
||||
else if (state == 1) {
|
||||
for(int i=0; i< strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, strip.Color(10,10,5));
|
||||
}
|
||||
|
||||
strip.show();
|
||||
sleep_ms(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
void core1_entry();
|
|
@ -1,5 +1,5 @@
|
|||
#include "ei_run_classifier.h"
|
||||
#include "Adafruit_NeoPixel.hpp"
|
||||
#include "lights.h"
|
||||
|
||||
#include <hardware/gpio.h>
|
||||
#include <hardware/uart.h>
|
||||
|
@ -12,102 +12,30 @@
|
|||
|
||||
// ############ ADC and Model Stuff ############
|
||||
|
||||
#define NSAMP 5000
|
||||
#define NSAMP 4000
|
||||
// set this to determine sample rate
|
||||
// 0 = 500,000 Hz
|
||||
// 960 = 50,000 Hz
|
||||
// 9600 = 5,000 Hz
|
||||
#define CLOCK_DIV 9600
|
||||
#define CLOCK_DIV 12000
|
||||
#define CAPTURE_CHANNEL 0
|
||||
#define LED_PIN 25
|
||||
|
||||
float features[NSAMP];
|
||||
uint16_t capture_buf[NSAMP];
|
||||
|
||||
// ############ Lights Stuff ############
|
||||
#define PIN 7
|
||||
|
||||
// ############ Functions ############
|
||||
int raw_feature_get_data(size_t offset, size_t length, float *out_ptr) {
|
||||
memcpy(out_ptr, features + offset, length * sizeof(float));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void core1_entry() {
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN,
|
||||
NEO_GRB + NEO_KHZ800);
|
||||
strip.begin();
|
||||
strip.setBrightness(64);
|
||||
strip.show();
|
||||
|
||||
// tell the other core we're ready for data
|
||||
multicore_fifo_push_blocking(0);
|
||||
|
||||
uint32_t state = 0;
|
||||
bool sent_req = false;
|
||||
uint32_t loop_idx = 0;
|
||||
while (1) {
|
||||
// check for new state information
|
||||
if (multicore_fifo_rvalid()) {
|
||||
uint32_t val = multicore_fifo_pop_blocking();
|
||||
|
||||
// 0 means state unchanged
|
||||
if (val != 0) {
|
||||
state = val;
|
||||
}
|
||||
|
||||
sent_req = false;
|
||||
}
|
||||
|
||||
else if (!sent_req) {
|
||||
// tell the other core we're ready for data
|
||||
multicore_fifo_push_blocking(0);
|
||||
// make sure we don't fill up the other queue
|
||||
sent_req = true;
|
||||
}
|
||||
|
||||
// turn on
|
||||
if (state == 1) {
|
||||
uint16_t i, j;
|
||||
|
||||
for(j=0; j<256; j++) { // 5 cycles of all colors on wheel
|
||||
for(i=0; i< strip.numPixels(); i++) {
|
||||
uint8_t WheelPos = ((i * 256 / strip.numPixels()) + j) & 255;
|
||||
uint32_t c = 0;
|
||||
|
||||
WheelPos = 255 - WheelPos;
|
||||
if(WheelPos < 85) {
|
||||
c = strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||
}
|
||||
if(WheelPos < 170) {
|
||||
WheelPos -= 85;
|
||||
c = strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||
}
|
||||
WheelPos -= 170;
|
||||
c = strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||
|
||||
strip.setPixelColor(i, c);
|
||||
}
|
||||
|
||||
strip.show();
|
||||
sleep_ms(10);
|
||||
}
|
||||
}
|
||||
|
||||
// turn off
|
||||
else if (state == 2) {
|
||||
strip.clear();
|
||||
strip.show();
|
||||
sleep_ms(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
stdio_usb_init();
|
||||
stdio_init_all();
|
||||
|
||||
|
||||
// function lives in lights.cpp
|
||||
multicore_launch_core1(core1_entry);
|
||||
|
||||
gpio_init(LED_PIN);
|
||||
|
@ -179,22 +107,26 @@ int main()
|
|||
|
||||
if (EI_CLASSIFIER_HAS_ANOMALY == 1) printf("Anomaly!\n");
|
||||
|
||||
const float thresh = 0.9;
|
||||
const float thresh = 0.7;
|
||||
|
||||
uint32_t state = 0;
|
||||
uint32_t state = 0;
|
||||
for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
|
||||
if (ix == 0 && result.classification[ix].value > thresh) {
|
||||
printf("GO\n");
|
||||
state = 1;
|
||||
//printf("EXTINGUISH\n");
|
||||
//state = 1;
|
||||
}
|
||||
|
||||
if (ix == 2 && result.classification[ix].value > thresh) {
|
||||
printf("STOP\n");
|
||||
state = 2;
|
||||
if (ix == 1 && result.classification[ix].value > thresh) {
|
||||
//printf("ILLUMINATE\n");
|
||||
//state = 2;
|
||||
}
|
||||
|
||||
printf("%0.2f, ",result.classification[ix].value);
|
||||
}
|
||||
|
||||
if (multicore_fifo_rvalid()) {
|
||||
printf("\n");
|
||||
|
||||
if (multicore_fifo_rvalid() && state != 0) {
|
||||
multicore_fifo_pop_blocking();
|
||||
multicore_fifo_push_blocking(state);
|
||||
}
|
||||
|
@ -204,6 +136,10 @@ int main()
|
|||
|
||||
// copy everything to feature buffer to run model
|
||||
// this is probably slow, idk
|
||||
|
||||
// copy everything to feature buffer to run model
|
||||
// this is probably slow, idk
|
||||
/*
|
||||
uint64_t sum = 0;
|
||||
for (uint32_t i=0; i<NSAMP; i++) {
|
||||
sum += capture_buf[i];
|
||||
|
@ -213,5 +149,17 @@ int main()
|
|||
for (uint32_t i=0; i<NSAMP; i++) {
|
||||
features[i] = (float)capture_buf[i]-dc_offset;
|
||||
}
|
||||
*/
|
||||
uint16_t min = 32768;
|
||||
uint16_t max = 0;
|
||||
|
||||
for (uint32_t i=0; i<NSAMP; i++) {
|
||||
if (capture_buf[i] > max) max = capture_buf[i];
|
||||
if (capture_buf[i] < min) min = capture_buf[i];
|
||||
}
|
||||
|
||||
for (uint32_t i=0; i<NSAMP; i++) {
|
||||
features[i] = ((float)capture_buf[i]-(float)min)/((float)max-(float)min)*2-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue