Skip to content

Commit 9ccb7e0

Browse files
committed
feat(touch_digit): add ci for example
1 parent 438bf68 commit 9ccb7e0

File tree

12 files changed

+140
-21
lines changed

12 files changed

+140
-21
lines changed

.gitlab/ci/build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ build_example_ai_esp_dl_human_activity_recognition:
6969
IMAGE: espressif/idf:release-v5.3
7070
EXAMPLE_DIR: examples/ai/esp_dl/human_activity_recognition
7171

72+
build_example_ai_esp_dl_touchpad_digit_recognition:
73+
extends:
74+
- .build_examples_template
75+
- .rules:build:example_ai_esp_dl_touchpad_digit_recognition
76+
variables:
77+
IMAGE: espressif/idf:release-v5.3
78+
EXAMPLE_DIR: examples/ai/esp_dl/touchpad_digit_recognition
79+
7280
build_example_audio_wav_player:
7381
extends:
7482
- .build_examples_template

.gitlab/ci/rules.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@
407407
.patterns-example_ai_esp_dl_human_activity_recognition: &patterns-example_ai_esp_dl_human_activity_recognition
408408
- "examples/ai/esp_dl/human_activity_recognition/**/*"
409409

410+
.patterns-example_ai_esp_dl_touchpad_digit_recognition: &patterns-example_ai_esp_dl_touchpad_digit_recognition
411+
- "examples/ai/esp_dl/touchpad_digit_recognition/**/*"
412+
410413
.patterns-example_audio_wav_player: &patterns-example_audio_wav_player
411414
- "examples/audio/**/*"
412415

@@ -699,6 +702,16 @@
699702
- <<: *if-dev-push
700703
changes: *patterns-example_ai_esp_dl_human_activity_recognition
701704

705+
.rules:build:example_ai_esp_dl_touchpad_digit_recognition:
706+
rules:
707+
- <<: *if-protected
708+
- <<: *if-label-build
709+
- <<: *if-trigger-job
710+
- <<: *if-dev-push
711+
changes: *patterns-build_system
712+
- <<: *if-dev-push
713+
changes: *patterns-example_ai_esp_dl_touchpad_digit_recognition
714+
702715
.rules:build:example_audio_wav_player:
703716
rules:
704717
- <<: *if-protected

examples/.build-rules.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ examples/ai/esp_dl/human_activity_recognition:
77
enable:
88
- if: IDF_TARGET in ["esp32s3","esp32p4"] and (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR == 3)
99

10+
examples/ai/esp_dl/touchpad_digit_recognition:
11+
enable:
12+
- if: IDF_TARGET in ["esp32s3"] and (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR == 3)
13+
1014
examples/audio/wav_player:
1115
enable:
1216
- if: INCLUDE_DEFAULT == 1

examples/ai/esp_dl/touchpad_digit_recognition/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ In this example, we will demonstrate how to implement the touch driver, train an
1414

1515
### Touch Processing Flow
1616

17-
17+
When a finger moves on the Touchpad, it changes the capacitance value of the Touch channel. By detecting changes in capacitance, the finger's position can be determined. Additionally, through a software interpolation algorithm, the original 6x7 Touch data is expanded to 30x25 for model training. For more details on Touch, you can refer to [Touch Digit Recognition](https://docs.espressif.com/projects/esp-iot-solution/en/latest/ai/touch_digit_recognition.html).
1818

1919
### AI Processing Flow
2020

examples/ai/esp_dl/touchpad_digit_recognition/main/include/normalization_save.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88
#include "esp_err.h"
99
#include "touch_digit.h"
1010

11+
/**
12+
* @brief Set the normalization data object
13+
*
14+
* @param data Pointer to the touch_digit_data_t structure containing
15+
* the normalization data to be saved.
16+
* @return esp_err_t Returns ESP_OK on success, or an error code on failure.
17+
*/
1118
esp_err_t set_normalization_data(touch_digit_data_t *data);
1219

20+
/**
21+
* @brief Get the normalization data object
22+
*
23+
* @param data Pointer to the touch_digit_data_t structure where the
24+
* retrieved normalization data will be stored.
25+
* @return esp_err_t Returns ESP_OK on success, or an error code on failure.
26+
*/
1327
esp_err_t get_normalization_data(touch_digit_data_t *data);

examples/ai/esp_dl/touchpad_digit_recognition/main/include/touch_channel.h

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,30 @@
88
#include <cstdio>
99
#include <iostream>
1010

11+
/**
12+
* @brief Touch channel class for managing touch channel data
13+
*/
1114
class TouchChannel {
1215
public:
13-
uint32_t max;
14-
uint32_t min;
15-
uint32_t data;
16-
double normalized_data;
17-
18-
// TouchChannel() :
19-
// max(0), min(UINT32_MAX), normalized_data(0), data(0) {}
16+
uint32_t max; /*!< Maximum value of the channel data */
17+
uint32_t min; /*!< Minimum value of the channel data */
18+
uint32_t data; /*!< Current raw data of the channel */
19+
double normalized_data; /*!< Normalized data in range [0,1] */
2020

21+
/**
22+
* @brief Construct a new Touch Channel object
23+
*
24+
* @param max Initial maximum value, defaults to 0
25+
* @param min Initial minimum value, defaults to UINT32_MAX
26+
*/
2127
TouchChannel(uint32_t max = 0, uint32_t min = UINT32_MAX)
2228
: max(max), min(min), data(0), normalized_data(0) {}
2329

30+
/**
31+
* @brief Normalize the input data
32+
*
33+
* @param input_data Raw input data to be normalized
34+
*/
2435
void normalize(uint32_t input_data)
2536
{
2637
data = input_data;
@@ -33,6 +44,11 @@ class TouchChannel {
3344
}
3445
}
3546

47+
/**
48+
* @brief Update the maximum and minimum values of the channel
49+
*
50+
* @param input_data Raw input data to update max/min values
51+
*/
3652
void update_max_min(uint32_t input_data)
3753
{
3854
if (input_data > max) {
@@ -44,6 +60,9 @@ class TouchChannel {
4460
}
4561
}
4662

63+
/**
64+
* @brief Reset the channel data
65+
*/
4766
void reset()
4867
{
4968
max = 0;
@@ -52,6 +71,9 @@ class TouchChannel {
5271
data = 0;
5372
}
5473

74+
/**
75+
* @brief Print the maximum and minimum values
76+
*/
5577
void print()
5678
{
5779
std::cout << " max:" << max << " min:" << min << std::endl;

examples/ai/esp_dl/touchpad_digit_recognition/main/include/touch_digit.h

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,50 @@
88
#include "esp_err.h"
99
#include "touch_channel.h"
1010

11-
#define ROW_CHANNEL_NUM 7
12-
#define COL_CHANNEL_NUM 6
13-
#define PRECISION 5
11+
#define ROW_CHANNEL_NUM 7 /*!< Number of row channels */
12+
#define COL_CHANNEL_NUM 6 /*!< Number of column channels */
13+
#define PRECISION 5 /*!< Precision for data processing */
1414

15+
/**
16+
* @brief Touch digit data structure
17+
*/
1518
typedef struct {
16-
TouchChannel row_data[ROW_CHANNEL_NUM]; // 1,3,5,7,9,11,13
17-
TouchChannel col_data[COL_CHANNEL_NUM]; // 8,6,4,2,10,12
19+
TouchChannel row_data[ROW_CHANNEL_NUM]; /*!< Row channel data array */
20+
TouchChannel col_data[COL_CHANNEL_NUM]; /*!< Column channel data array */
1821
} touch_digit_data_t;
1922

23+
/**
24+
* @brief Initialize touch digit recognition
25+
*
26+
* @return esp_err_t ESP_OK on success, otherwise an error code
27+
*/
2028
esp_err_t touch_digit_init(void);
2129

30+
/**
31+
* @brief Print touch digit data
32+
*
33+
* @return esp_err_t ESP_OK on success, otherwise an error code
34+
*/
2235
esp_err_t printf_touch_digit_data(void);
2336

37+
/**
38+
* @brief Start normalization process
39+
*
40+
* @return esp_err_t ESP_OK on success, otherwise an error code
41+
*/
2442
esp_err_t touch_dight_begin_normalize(void);
2543

44+
/**
45+
* @brief End normalization process
46+
*
47+
* @return esp_err_t ESP_OK on success, otherwise an error code
48+
*/
2649
esp_err_t touch_dight_end_normalize(void);
2750

51+
/**
52+
* @brief Get normalization state
53+
*
54+
* @return true if normalization is in progress
55+
* @return false if normalization is not in progress
56+
*/
2857
bool get_touch_dight_normalize_state(void);

examples/ai/esp_dl/touchpad_digit_recognition/main/include/touch_image.h

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,28 @@
1010
#include <iostream>
1111
#include "touch_digit.h"
1212

13+
/**
14+
* @brief Touch image class for handling touch data visualization
15+
*/
1316
class TouchImage {
1417
public:
15-
uint32_t row_length;
16-
uint32_t col_length;
17-
uint8_t *data;
18+
uint32_t row_length; /*!< Length of the image row */
19+
uint32_t col_length; /*!< Length of the image column */
20+
uint8_t *data; /*!< Image data buffer */
1821

22+
/**
23+
* @brief Construct a new Touch Image object
24+
*/
1925
TouchImage() :
2026
row_length((ROW_CHANNEL_NUM - 1) * PRECISION), col_length((COL_CHANNEL_NUM - 1) * PRECISION), data(nullptr)
2127
{
2228
data = new uint8_t[row_length * col_length];
2329
this->clear();
2430
}
2531

32+
/**
33+
* @brief Destroy the Touch Image object
34+
*/
2635
~TouchImage()
2736
{
2837
if (data != nullptr) {
@@ -31,23 +40,36 @@ class TouchImage {
3140
}
3241
}
3342

43+
/**
44+
* @brief Set pixel value at specified position
45+
*
46+
* @param x X coordinate
47+
* @param y Y coordinate
48+
* @param value Pixel value
49+
*/
3450
void set_pixel(uint8_t x, uint8_t y, uint8_t value)
3551
{
3652
data[x + y * row_length] = value;
3753
}
3854

55+
/**
56+
* @brief Clear all pixels to zero
57+
*/
3958
void clear()
4059
{
4160
memset(data, 0, sizeof(uint8_t) * row_length * col_length);
4261
}
4362

63+
/**
64+
* @brief Print image to console
65+
*/
4466
void print()
4567
{
46-
for (int y = 0; y < col_length; y++) { // 遍历行
47-
for (int x = 0; x < row_length; x++) { // 遍历列
68+
for (int y = 0; y < col_length; y++) {
69+
for (int x = 0; x < row_length; x++) {
4870
printf(" %c ", data[y * row_length + x] == 0 ? ' ' : '*');
4971
}
50-
printf("\n"); // 换行
72+
printf("\n");
5173
}
5274
}
5375
};

examples/ai/esp_dl/touchpad_digit_recognition/main/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ static void button_event_cb(void *arg, void *data)
2727
extern "C" void app_main(void)
2828
{
2929
esp_err_t ret;
30+
31+
/* Initialize NVS */
3032
ret = nvs_flash_init();
3133
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
3234
ESP_ERROR_CHECK(nvs_flash_erase());
@@ -39,15 +41,20 @@ extern "C" void app_main(void)
3941
const button_gpio_config_t btn_gpio_cfg = {
4042
.gpio_num = 0,
4143
.active_level = 0,
44+
.enable_power_save = false,
4245
.disable_pull = false,
4346
};
4447

48+
/* Initialize button for normalization calibration */
4549
button_handle_t btn = NULL;
4650
ret = iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &btn);
51+
// Register callback for button press down to start normalization calibration
4752
iot_button_register_cb(btn, BUTTON_PRESS_DOWN, NULL, button_event_cb, NULL);
4853

54+
/* Initialize touch digit */
4955
touch_digit_init();
5056

57+
/* Initialize digital tube */
5158
digital_tube_driver_install(I2C_NUM_0, GPIO_NUM_37, GPIO_NUM_38);
5259
digital_tube_enable();
5360
}

examples/ai/esp_dl/touchpad_digit_recognition/main/touch_digit.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ void touch_digit_recognition_task(void *arg)
285285

286286
while (1) {
287287
if (xQueueReceive(xImageQueue, &image_data, portMAX_DELAY) == pdTRUE) {
288-
printf("Result:%d\n", touch_digit_recognition->predict(image_data.data));
289288
digital_tube_write_num(0, touch_digit_recognition->predict(image_data.data));
290289
delete [] image_data.data;
291290
}

0 commit comments

Comments
 (0)