🎨 clean up

pull/216/head
yehangyang 2022-03-03 14:35:04 +08:00
parent cab8fc55c2
commit 5ea65b93d5
18 changed files with 129 additions and 152 deletions

View File

@ -1,13 +0,0 @@
menu "ESP32-S3-EYE Firmware"
choice ESP_SR_LANGUAGE
bool "esp-sr language"
default CN_MODEL
help
Select ESP-SR Language.
config CN_MODEL
bool "Chinese"
config EN_MODEL
bool "English"
endchoice
endmenu

View File

@ -1,6 +1,6 @@
#include "driver/gpio.h" #include "driver/gpio.h"
#include "app_buttom.hpp" #include "app_button.hpp"
#include "app_camera.hpp" #include "app_camera.hpp"
#include "app_lcd.hpp" #include "app_lcd.hpp"
#include "app_led.hpp" #include "app_led.hpp"
@ -14,13 +14,13 @@ extern "C" void app_main()
QueueHandle_t xQueueFrame_1 = xQueueCreate(2, sizeof(camera_fb_t *)); QueueHandle_t xQueueFrame_1 = xQueueCreate(2, sizeof(camera_fb_t *));
QueueHandle_t xQueueFrame_2 = xQueueCreate(2, sizeof(camera_fb_t *)); QueueHandle_t xQueueFrame_2 = xQueueCreate(2, sizeof(camera_fb_t *));
AppButtom *key = new AppButtom(); AppButton *key = new AppButton();
AppSpeech *speech = new AppSpeech(); AppSpeech *speech = new AppSpeech();
AppCamera *camera = new AppCamera(PIXFORMAT_RGB565, FRAMESIZE_240X240, 2, xQueueFrame_0); AppCamera *camera = new AppCamera(PIXFORMAT_RGB565, FRAMESIZE_240X240, 2, xQueueFrame_0);
AppFace *face = new AppFace(key, speech, xQueueFrame_0, xQueueFrame_1); AppFace *face = new AppFace(key, speech, xQueueFrame_0, xQueueFrame_1);
AppMotion *motion = new AppMotion(key, speech, xQueueFrame_1, xQueueFrame_2); AppMotion *motion = new AppMotion(key, speech, xQueueFrame_1, xQueueFrame_2);
AppLCD *lcd = new AppLCD(key, speech, xQueueFrame_2); AppLCD *lcd = new AppLCD(key, speech, xQueueFrame_2);
LED *led = new LED(GPIO_NUM_3, key, speech); AppLED *led = new AppLED(GPIO_NUM_3, key, speech);
key->attach(face); key->attach(face);
key->attach(motion); key->attach(motion);

View File

@ -1,35 +0,0 @@
#pragma once
#include <vector>
#include "__base__.hpp"
typedef enum
{
_IDLE = 0,
_MENU,
_PLAY,
_UP,
_DOWN
} _key_name_t;
typedef struct
{
_key_name_t key; /**< button index on the channel */
int min; /**< min voltage in mv corresponding to the button */
int max; /**< max voltage in mv corresponding to the button */
} key_config_t;
class AppButtom : public Subject
{
public:
std::vector<key_config_t> key_configs;
_key_name_t pressed;
uint8_t menu;
AppButtom();
~AppButtom();
void run();
};

View File

@ -0,0 +1,35 @@
#pragma once
#include <vector>
#include "__base__.hpp"
typedef enum
{
BUTTON_IDLE = 0,
BUTTON_MENU,
BUTTON_PLAY,
BUTTON_UP,
BUTTON_DOWN
} button_name_t;
typedef struct
{
button_name_t key; /**< button index on the channel */
int min; /**< min voltage in mv corresponding to the button */
int max; /**< max voltage in mv corresponding to the button */
} key_config_t;
class AppButton : public Subject
{
public:
std::vector<key_config_t> key_configs;
button_name_t pressed;
uint8_t menu;
AppButton();
~AppButton();
void run();
};

View File

@ -2,11 +2,6 @@
#include <list> #include <list>
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_camera.h" #include "esp_camera.h"
#include "__base__.hpp" #include "__base__.hpp"

View File

@ -1,17 +1,21 @@
#pragma once #pragma once
#include "sdkconfig.h"
#include "human_face_detect_msr01.hpp" #include "human_face_detect_msr01.hpp"
#include "human_face_detect_mnp01.hpp" #include "human_face_detect_mnp01.hpp"
#include "face_recognition_tool.hpp" #include "face_recognition_tool.hpp"
// #if CONFIG_MFN_V1_Q8 #if CONFIG_MFN_V1
// #include "face_recognition_112_v1_s8.hpp" #if CONFIG_S8
// #elif CONFIG_MFN_V1_Q16 #include "face_recognition_112_v1_s8.hpp"
#elif CONFIG_S16
#include "face_recognition_112_v1_s16.hpp" #include "face_recognition_112_v1_s16.hpp"
// #endif #endif
#endif
#include "__base__.hpp" #include "__base__.hpp"
#include "app_camera.hpp" #include "app_camera.hpp"
#include "app_buttom.hpp" #include "app_button.hpp"
#include "app_speech.hpp" #include "app_speech.hpp"
typedef enum typedef enum
@ -25,18 +29,20 @@ typedef enum
class AppFace : public Observer, public Frame class AppFace : public Observer, public Frame
{ {
private: private:
AppButtom *key; AppButton *key;
AppSpeech *speech; AppSpeech *speech;
public: public:
HumanFaceDetectMSR01 detector; HumanFaceDetectMSR01 detector;
HumanFaceDetectMNP01 detector2; HumanFaceDetectMNP01 detector2;
// #if CONFIG_MFN_V1_Q8 #if CONFIG_MFN_V1
// FaceRecognition112V1S8 *recognizer; #if CONFIG_S8
// #elif CONFIG_MFN_V1_Q16 FaceRecognition112V1S8 *recognizer;
#elif CONFIG_S16
FaceRecognition112V1S16 *recognizer; FaceRecognition112V1S16 *recognizer;
// #endif #endif
#endif
face_info_t recognize_result; face_info_t recognize_result;
recognizer_state_t state; recognizer_state_t state;
@ -46,7 +52,7 @@ public:
uint8_t frame_count; uint8_t frame_count;
AppFace(AppButtom *key, AppFace(AppButton *key,
AppSpeech *speech, AppSpeech *speech,
QueueHandle_t queue_i = nullptr, QueueHandle_t queue_i = nullptr,
QueueHandle_t queue_o = nullptr, QueueHandle_t queue_o = nullptr,

View File

@ -1,12 +1,10 @@
#pragma once #pragma once
#include <stdint.h>
#include "esp_log.h"
#include "screen_driver.h" #include "screen_driver.h"
#include "__base__.hpp" #include "__base__.hpp"
#include "app_camera.hpp" #include "app_camera.hpp"
#include "app_buttom.hpp" #include "app_button.hpp"
#include "app_speech.hpp" #include "app_speech.hpp"
#define BOARD_LCD_MOSI 47 #define BOARD_LCD_MOSI 47
@ -28,7 +26,7 @@
class AppLCD : public Observer, public Frame class AppLCD : public Observer, public Frame
{ {
private: private:
AppButtom *key; AppButton *key;
AppSpeech *speech; AppSpeech *speech;
public: public:
@ -36,7 +34,7 @@ public:
bool switch_on; bool switch_on;
bool paper_drawn; bool paper_drawn;
AppLCD(AppButtom *key, AppLCD(AppButton *key,
AppSpeech *speech, AppSpeech *speech,
QueueHandle_t xQueueFrameI = nullptr, QueueHandle_t xQueueFrameI = nullptr,
QueueHandle_t xQueueFrameO = nullptr, QueueHandle_t xQueueFrameO = nullptr,

View File

@ -5,19 +5,18 @@
#include "freertos/task.h" #include "freertos/task.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "app_buttom.hpp" #include "app_button.hpp"
#include "app_speech.hpp" #include "app_speech.hpp"
class LED : public Observer class AppLED : public Observer
{ {
private: private:
const gpio_num_t pin; const gpio_num_t pin;
AppButtom *key; AppButton *key;
AppSpeech *sr; AppSpeech *sr;
public: public:
LED(const gpio_num_t pin, AppButtom *key, AppSpeech *sr); AppLED(const gpio_num_t pin, AppButton *key, AppSpeech *sr);
~LED();
void update(); void update();
}; };

View File

@ -2,19 +2,19 @@
#include "__base__.hpp" #include "__base__.hpp"
#include "app_camera.hpp" #include "app_camera.hpp"
#include "app_buttom.hpp" #include "app_button.hpp"
#include "app_speech.hpp" #include "app_speech.hpp"
class AppMotion : public Observer, public Frame class AppMotion : public Observer, public Frame
{ {
private: private:
AppButtom *key; AppButton *key;
AppSpeech *speech; AppSpeech *speech;
public: public:
bool switch_on; bool switch_on;
AppMotion(AppButtom *key, AppMotion(AppButton *key,
AppSpeech *speech, AppSpeech *speech,
QueueHandle_t queue_i = nullptr, QueueHandle_t queue_i = nullptr,
QueueHandle_t queue_o = nullptr, QueueHandle_t queue_o = nullptr,

View File

@ -1,10 +1,5 @@
#pragma once #pragma once
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_afe_sr_iface.h" #include "esp_afe_sr_iface.h"
#include "__base__.hpp" #include "__base__.hpp"

View File

@ -1,4 +1,4 @@
#include "app_buttom.hpp" #include "app_button.hpp"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -26,16 +26,16 @@
#define PRESS_INTERVAL 500000 #define PRESS_INTERVAL 500000
static const char *TAG = "App/Buttom"; static const char *TAG = "App/Button";
AppButtom::AppButtom() : key_configs({{_MENU, 2800, 3000}, {_PLAY, 2250, 2450}, {_UP, 300, 500}, {_DOWN, 850, 1050}}), AppButton::AppButton() : key_configs({{BUTTON_MENU, 2800, 3000}, {BUTTON_PLAY, 2250, 2450}, {BUTTON_UP, 300, 500}, {BUTTON_DOWN, 850, 1050}}),
pressed(_IDLE) pressed(BUTTON_IDLE)
{ {
ESP_ERROR_CHECK(adc1_config_width((adc_bits_width_t)ADC_WIDTH_BIT_DEFAULT)); ESP_ERROR_CHECK(adc1_config_width((adc_bits_width_t)ADC_WIDTH_BIT_DEFAULT));
ESP_ERROR_CHECK(adc1_config_channel_atten(ADC1_EXAMPLE_CHAN0, ADC_EXAMPLE_ATTEN)); ESP_ERROR_CHECK(adc1_config_channel_atten(ADC1_EXAMPLE_CHAN0, ADC_EXAMPLE_ATTEN));
} }
static void task(AppButtom *self) static void task(AppButton *self)
{ {
int64_t backup_time = esp_timer_get_time(); int64_t backup_time = esp_timer_get_time();
int64_t last_time = esp_timer_get_time(); int64_t last_time = esp_timer_get_time();
@ -52,10 +52,10 @@ static void task(AppButtom *self)
{ {
if (((backup_time - last_time) > PRESS_INTERVAL)) if (((backup_time - last_time) > PRESS_INTERVAL))
{ {
ESP_LOGD(TAG, "Key[%d] is pressed", self->pressed);
self->pressed = key_config.key; self->pressed = key_config.key;
ESP_LOGI(TAG, "Button[%d] is clicked", self->pressed);
if (self->pressed == _MENU) if (self->pressed == BUTTON_MENU)
{ {
self->menu++; self->menu++;
self->menu %= (MENU_MOTION_DETECTION + 1); self->menu %= (MENU_MOTION_DETECTION + 1);
@ -64,7 +64,7 @@ static void task(AppButtom *self)
last_time = backup_time; last_time = backup_time;
self->notify(); self->notify();
self->pressed = _IDLE; self->pressed = BUTTON_IDLE;
break; break;
} }
} }
@ -73,7 +73,7 @@ static void task(AppButtom *self)
} }
} }
void AppButtom::run() void AppButton::run()
{ {
xTaskCreatePinnedToCore((TaskFunction_t)task, TAG, 3 * 1024, this, 5, NULL, 0); xTaskCreatePinnedToCore((TaskFunction_t)task, TAG, 3 * 1024, this, 5, NULL, 0);
} }

View File

@ -1,7 +1,5 @@
#include "app_camera.hpp" #include "app_camera.hpp"
#include "assert.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_system.h" #include "esp_system.h"

View File

@ -52,7 +52,7 @@ static int rgb_printf(camera_fb_t *fb, uint32_t color, const char *format, ...)
return len; return len;
} }
AppFace::AppFace(AppButtom *key, AppFace::AppFace(AppButton *key,
AppSpeech *speech, AppSpeech *speech,
QueueHandle_t queue_i, QueueHandle_t queue_i,
QueueHandle_t queue_o, QueueHandle_t queue_o,
@ -63,44 +63,43 @@ AppFace::AppFace(AppButtom *key,
detector2(0.4F, 0.3F, 10), detector2(0.4F, 0.3F, 10),
state(IDLE), state(IDLE),
switch_on(false) switch_on(false)
// recognizer(
// #if CONFIG_MFN_V1_Q8
// new FaceRecognition112V1S8()
// #elif CONFIG_MFN_V1_Q16
// new FaceRecognition112V1S16()
// #endif
// )
{ {
// this->recognizer = new FaceRecognition112V1S8(); #if CONFIG_MFN_V1
#if CONFIG_S8
this->recognizer = new FaceRecognition112V1S8();
#elif CONFIG_S16
this->recognizer = new FaceRecognition112V1S16(); this->recognizer = new FaceRecognition112V1S16();
#endif
#endif
this->recognizer->set_partition(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "fr"); this->recognizer->set_partition(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "fr");
int partition_result = this->recognizer->set_ids_from_flash(); this->recognizer->set_ids_from_flash();
} }
AppFace::~AppFace() AppFace::~AppFace()
{ {
delete this->recognizer;
} }
void AppFace::update() void AppFace::update()
{ {
// Parse key // Parse key
if (this->key->pressed > _IDLE) if (this->key->pressed > BUTTON_IDLE)
{ {
if (this->key->pressed == _MENU) if (this->key->pressed == BUTTON_MENU)
{ {
this->switch_on = (this->key->menu == MENU_FACE_RECOGNITION) ? true : false; this->switch_on = (this->key->menu == MENU_FACE_RECOGNITION) ? true : false;
ESP_LOGD(TAG, "%s", this->switch_on ? "ON" : "OFF"); ESP_LOGD(TAG, "%s", this->switch_on ? "ON" : "OFF");
} }
else if (this->key->pressed == _PLAY) else if (this->key->pressed == BUTTON_PLAY)
{ {
this->state = RECOGNIZE; this->state = RECOGNIZE;
} }
else if (this->key->pressed == _UP) else if (this->key->pressed == BUTTON_UP)
{ {
this->state = ENROLL; this->state = ENROLL;
} }
else if (this->key->pressed == _DOWN) else if (this->key->pressed == BUTTON_DOWN)
{ {
this->state = DELETE; this->state = DELETE;
} }
@ -159,7 +158,7 @@ static void task(AppFace *self)
{ {
case ENROLL: case ENROLL:
self->recognizer->enroll_id((uint16_t *)frame->buf, {(int)frame->height, (int)frame->width, 3}, detect_results.front().keypoint, "", true); self->recognizer->enroll_id((uint16_t *)frame->buf, {(int)frame->height, (int)frame->width, 3}, detect_results.front().keypoint, "", true);
ESP_LOGW(TAG, "Enroll ID %d", self->recognizer->get_enrolled_ids().back().id); ESP_LOGI(TAG, "Enroll ID %d", self->recognizer->get_enrolled_ids().back().id);
break; break;
case RECOGNIZE: case RECOGNIZE:
@ -169,13 +168,13 @@ static void task(AppFace *self)
if (self->recognize_result.id > 0) if (self->recognize_result.id > 0)
ESP_LOGI(TAG, "Match ID: %d", self->recognize_result.id); ESP_LOGI(TAG, "Match ID: %d", self->recognize_result.id);
else else
ESP_LOGE(TAG, "Match ID: %d", self->recognize_result.id); ESP_LOGI(TAG, "Match ID: %d", self->recognize_result.id);
break; break;
case DELETE: case DELETE:
vTaskDelay(10); vTaskDelay(10);
self->recognizer->delete_id(true); self->recognizer->delete_id(true);
ESP_LOGE(TAG, "%d IDs left", self->recognizer->get_enrolled_id_num()); ESP_LOGI(TAG, "%d IDs left", self->recognizer->get_enrolled_id_num());
break; break;
default: default:

View File

@ -2,6 +2,7 @@
#include <string.h> #include <string.h>
#include "esp_log.h"
#include "esp_camera.h" #include "esp_camera.h"
#include "esp_lcd_panel_io.h" #include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_vendor.h" #include "esp_lcd_panel_vendor.h"
@ -13,7 +14,7 @@
static const char TAG[] = "App/LCD"; static const char TAG[] = "App/LCD";
AppLCD::AppLCD(AppButtom *key, AppLCD::AppLCD(AppButton *key,
AppSpeech *speech, AppSpeech *speech,
QueueHandle_t queue_i, QueueHandle_t queue_i,
QueueHandle_t queue_o, QueueHandle_t queue_o,
@ -120,9 +121,9 @@ void AppLCD::draw_color(int color)
void AppLCD::update() void AppLCD::update()
{ {
if (this->key->pressed > _IDLE) if (this->key->pressed > BUTTON_IDLE)
{ {
if (this->key->pressed == _MENU) if (this->key->pressed == BUTTON_MENU)
{ {
this->switch_on = (this->key->menu == MENU_STOP_WORKING) ? false : true; this->switch_on = (this->key->menu == MENU_STOP_WORKING) ? false : true;
ESP_LOGD(TAG, "%s", this->switch_on ? "ON" : "OFF"); ESP_LOGD(TAG, "%s", this->switch_on ? "ON" : "OFF");

View File

@ -19,7 +19,7 @@ typedef enum
LED_BLINK_4S = 10, LED_BLINK_4S = 10,
} led_mode_t; } led_mode_t;
LED::LED(const gpio_num_t pin, AppButtom *key, AppSpeech *sr) : pin(pin), key(key), sr(sr) AppLED::AppLED(const gpio_num_t pin, AppButton *key, AppSpeech *sr) : pin(pin), key(key), sr(sr)
{ {
// initialize GPIO // initialize GPIO
gpio_config_t gpio_conf; gpio_config_t gpio_conf;
@ -33,14 +33,14 @@ LED::LED(const gpio_num_t pin, AppButtom *key, AppSpeech *sr) : pin(pin), key(ke
gpio_set_level(this->pin, 0); gpio_set_level(this->pin, 0);
} }
void LED::update() void AppLED::update()
{ {
led_mode_t mode = LED_ALWAYS_OFF; led_mode_t mode = LED_ALWAYS_OFF;
// parse key // parse key
if (this->key->pressed) if (this->key->pressed)
{ {
mode = LED_BLINK_2S; mode = LED_BLINK_1S;
} }
// parse speech recognition // parse speech recognition
else if (this->sr->detected) else if (this->sr->detected)

View File

@ -1,7 +1,5 @@
#include "app_motion.hpp" #include "app_motion.hpp"
#include "assert.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_camera.h" #include "esp_camera.h"
@ -9,7 +7,7 @@
static const char TAG[] = "App/Motion"; static const char TAG[] = "App/Motion";
AppMotion::AppMotion(AppButtom *key, AppMotion::AppMotion(AppButton *key,
AppSpeech *speech, AppSpeech *speech,
QueueHandle_t queue_i, QueueHandle_t queue_i,
QueueHandle_t queue_o, QueueHandle_t queue_o,
@ -20,9 +18,9 @@ AppMotion::AppMotion(AppButtom *key,
void AppMotion::update() void AppMotion::update()
{ {
if (this->key->pressed > _IDLE) if (this->key->pressed > BUTTON_IDLE)
{ {
if (this->key->pressed == _MENU) if (this->key->pressed == BUTTON_MENU)
{ {
this->switch_on = (this->key->menu == MENU_MOTION_DETECTION) ? true : false; this->switch_on = (this->key->menu == MENU_MOTION_DETECTION) ? true : false;
ESP_LOGD(TAG, "%s", this->switch_on ? "ON" : "OFF"); ESP_LOGD(TAG, "%s", this->switch_on ? "ON" : "OFF");

View File

@ -162,7 +162,7 @@ static void detect_hander(AppSpeech *self)
else else
{ {
self->notify(); self->notify();
ESP_LOGD(TAG, "Command: %d", self->command); ESP_LOGI(TAG, "Command: %d", self->command);
#ifndef CONFIG_SR_MN_CN_MULTINET3_CONTINUOUS_RECOGNITION #ifndef CONFIG_SR_MN_CN_MULTINET3_CONTINUOUS_RECOGNITION
self->afe_handle->enable_wakenet(afe_data); self->afe_handle->enable_wakenet(afe_data);

View File

@ -25,7 +25,8 @@ CONFIG_ESP32S3_DATA_CACHE_LINE_64B=y
# Image Relation # Image Relation
CONFIG_CAMERA_MODULE_ESP_S3_EYE=y CONFIG_CAMERA_MODULE_ESP_S3_EYE=y
CONFIG_LCD_DRIVER_SCREEN_CONTROLLER_ST7789=y CONFIG_LCD_DRIVER_SCREEN_CONTROLLER_ST7789=y
CONFIG_MFN_V1_Q8=y CONFIG_MFN_V1=y
CONFIG_S8=y
# Speech Relation # Speech Relation