Skip to content

Commit

Permalink
Merge branch 'example/update_format_string_in_touch_related_examples'…
Browse files Browse the repository at this point in the history
… into 'master'

example: update format string in touch related examples

See merge request espressif/esp-idf!19743
  • Loading branch information
suda-morris committed Aug 25, 2022
2 parents 853a27b + 763b472 commit 935a63e
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
idf_component_register(SRCS "touch_button_example_main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES touch_element)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ static void button_handler_task(void *arg)
/* Decode message */
const touch_button_message_t *button_message = touch_button_get_message(&element_message);
if (button_message->event == TOUCH_BUTTON_EVT_ON_PRESS) {
ESP_LOGI(TAG, "Button[%d] Press", (uint32_t)element_message.arg);
ESP_LOGI(TAG, "Button[%d] Press", (int)element_message.arg);
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_RELEASE) {
ESP_LOGI(TAG, "Button[%d] Release", (uint32_t)element_message.arg);
ESP_LOGI(TAG, "Button[%d] Release", (int)element_message.arg);
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_LONGPRESS) {
ESP_LOGI(TAG, "Button[%d] LongPress", (uint32_t)element_message.arg);
ESP_LOGI(TAG, "Button[%d] LongPress", (int)element_message.arg);
}
}
}
Expand All @@ -80,11 +80,11 @@ static void button_handler(touch_button_handle_t out_handle, touch_button_messag
{
(void) out_handle; //Unused
if (out_message->event == TOUCH_BUTTON_EVT_ON_PRESS) {
ESP_LOGI(TAG, "Button[%d] Press", (uint32_t)arg);
ESP_LOGI(TAG, "Button[%d] Press", (int)arg);
} else if (out_message->event == TOUCH_BUTTON_EVT_ON_RELEASE) {
ESP_LOGI(TAG, "Button[%d] Release", (uint32_t)arg);
ESP_LOGI(TAG, "Button[%d] Release", (int)arg);
} else if (out_message->event == TOUCH_BUTTON_EVT_ON_LONGPRESS) {
ESP_LOGI(TAG, "Button[%d] LongPress", (uint32_t)arg);
ESP_LOGI(TAG, "Button[%d] LongPress", (int)arg);
}
}
#endif
Expand All @@ -107,8 +107,9 @@ void app_main(void)
/* Create Touch buttons */
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
/* Subscribe touch button events (On Press, On Release, On LongPress) */
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i], TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
(void *)channel_array[i]));
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i],
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
(void *)channel_array[i]));
#ifdef CONFIG_TOUCH_ELEM_EVENT
/* Set EVENT as the dispatch method */
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
idf_component_register(SRCS "waterproof_example_main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES touch_element)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ static void button_handler_task(void *arg)
touch_element_message_receive(&element_message, portMAX_DELAY); //Block take
const touch_button_message_t *button_message = touch_button_get_message(&element_message);
if (button_message->event == TOUCH_BUTTON_EVT_ON_PRESS) {
ESP_LOGI(TAG, "Button[%d] Press", (uint32_t)element_message.arg);
ESP_LOGI(TAG, "Button[%d] Press", (int)element_message.arg);
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_RELEASE) {
ESP_LOGI(TAG, "Button[%d] Release", (uint32_t)element_message.arg);
ESP_LOGI(TAG, "Button[%d] Release", (int)element_message.arg);
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_LONGPRESS) {
ESP_LOGI(TAG, "Button[%d] LongPress", (uint32_t)element_message.arg);
ESP_LOGI(TAG, "Button[%d] LongPress", (int)element_message.arg);
}
}
}
Expand Down Expand Up @@ -74,8 +74,9 @@ void app_main(void)
/* Create touch button */
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
/* Subscribe touch button event(Press, Release, LongPress) */
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i], TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
(void *)channel_array[i]));
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i],
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
(void *)channel_array[i]));
/* Button set dispatch method */
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
#ifdef CONFIG_TOUCH_WATERPROOF_GUARD_ENABLE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
idf_component_register(SRCS "touch_elements_example_main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES touch_element)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "touch_element/touch_button.h"
Expand Down Expand Up @@ -53,23 +54,23 @@ static void button_handler(touch_elem_message_t element_message)
{
const touch_button_message_t *button_message = touch_button_get_message(&element_message);
if (button_message->event == TOUCH_BUTTON_EVT_ON_PRESS) {
ESP_LOGI(TAG, "Button[%d] Press", (uint32_t)element_message.arg);
ESP_LOGI(TAG, "Button[%d] Press", (int)element_message.arg);
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_RELEASE) {
ESP_LOGI(TAG, "Button[%d] Release", (uint32_t)element_message.arg);
ESP_LOGI(TAG, "Button[%d] Release", (int)element_message.arg);
} else if (button_message->event == TOUCH_BUTTON_EVT_ON_LONGPRESS) {
ESP_LOGI(TAG, "Button[%d] LongPress", (uint32_t)element_message.arg);
ESP_LOGI(TAG, "Button[%d] LongPress", (int)element_message.arg);
}
}

static void slider_handler(touch_elem_message_t element_message)
{
const touch_slider_message_t *slider_message = touch_slider_get_message(&element_message);
if (slider_message->event == TOUCH_SLIDER_EVT_ON_PRESS) {
ESP_LOGI(TAG, "Slider Press, position: %d", slider_message->position);
ESP_LOGI(TAG, "Slider Press, position: %"PRIu32, slider_message->position);
} else if (slider_message->event == TOUCH_SLIDER_EVT_ON_RELEASE) {
ESP_LOGI(TAG, "Slider Release, position: %d", slider_message->position);
ESP_LOGI(TAG, "Slider Release, position: %"PRIu32, slider_message->position);
} else if (slider_message->event == TOUCH_SLIDER_EVT_ON_CALCULATION) {
ESP_LOGI(TAG, "Slider Calculate, position: %d", slider_message->position);
ESP_LOGI(TAG, "Slider Calculate, position: %"PRIu32, slider_message->position);
}
}

Expand Down Expand Up @@ -107,7 +108,8 @@ void button_example_init(void)
/* Create Touch buttons */
ESP_ERROR_CHECK(touch_button_create(&button_config, &button_handle[i]));
/* Subscribe touch button events (On Press, On Release, On LongPress) */
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i], TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
ESP_ERROR_CHECK(touch_button_subscribe_event(button_handle[i],
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS,
(void *)button_channel_array[i]));
/* Set EVENT as the dispatch method */
ESP_ERROR_CHECK(touch_button_set_dispatch_method(button_handle[i], TOUCH_ELEM_DISP_EVENT));
Expand All @@ -131,7 +133,8 @@ void slider_example_init(void)
};
ESP_ERROR_CHECK(touch_slider_create(&slider_config, &slider_handle));
/* Subscribe touch slider events (On Press, On Release, On Calculation) */
ESP_ERROR_CHECK(touch_slider_subscribe_event(slider_handle, TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL));
ESP_ERROR_CHECK(touch_slider_subscribe_event(slider_handle,
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL));
/* Set EVENT as the dispatch method */
ESP_ERROR_CHECK(touch_slider_set_dispatch_method(slider_handle, TOUCH_ELEM_DISP_EVENT));
ESP_LOGI(TAG, "Touch slider created");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
idf_component_register(SRCS "touch_matrix_example_main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES touch_element)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "touch_element/touch_matrix.h"
Expand Down Expand Up @@ -58,11 +59,14 @@ static void matrix_handler_task(void *arg)
/* Decode message */
const touch_matrix_message_t *matrix_message = touch_matrix_get_message(&element_message);
if (matrix_message->event == TOUCH_MATRIX_EVT_ON_PRESS) {
ESP_LOGI(TAG, "Matrix Press, axis: (%d, %d) index: %d", matrix_message->position.x_axis, matrix_message->position.y_axis, matrix_message->position.index);
ESP_LOGI(TAG, "Matrix Press, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis,
matrix_message->position.y_axis, matrix_message->position.index);
} else if (matrix_message->event == TOUCH_MATRIX_EVT_ON_RELEASE) {
ESP_LOGI(TAG, "Matrix Release, axis: (%d, %d) index: %d", matrix_message->position.x_axis, matrix_message->position.y_axis, matrix_message->position.index);
ESP_LOGI(TAG, "Matrix Release, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis,
matrix_message->position.y_axis, matrix_message->position.index);
} else if (matrix_message->event == TOUCH_MATRIX_EVT_ON_LONGPRESS) {
ESP_LOGI(TAG, "Matrix LongPress, axis: (%d, %d) index: %d", matrix_message->position.x_axis, matrix_message->position.y_axis, matrix_message->position.index);
ESP_LOGI(TAG, "Matrix LongPress, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, matrix_message->position.x_axis,
matrix_message->position.y_axis, matrix_message->position.index);
}
}
}
Expand All @@ -75,11 +79,14 @@ void matrix_handler(touch_matrix_handle_t out_handle, touch_matrix_message_t *ou
return;
}
if (out_message->event == TOUCH_MATRIX_EVT_ON_PRESS) {
ESP_LOGI(TAG, "Matrix Press, axis: (%d, %d) index: %d", out_message->position.x_axis, out_message->position.y_axis, out_message->position.index);
ESP_LOGI(TAG, "Matrix Press, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis,
out_message->position.y_axis, out_message->position.index);
} else if (out_message->event == TOUCH_MATRIX_EVT_ON_RELEASE) {
ESP_LOGI(TAG, "Matrix Release, axis: (%d, %d) index: %d", out_message->position.x_axis, out_message->position.y_axis, out_message->position.index);
ESP_LOGI(TAG, "Matrix Release, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis,
out_message->position.y_axis, out_message->position.index);
} else if (out_message->event == TOUCH_MATRIX_EVT_ON_LONGPRESS) {
ESP_LOGI(TAG, "Matrix LongPress, axis: (%d, %d) index: %d", out_message->position.x_axis, out_message->position.y_axis, out_message->position.index);
ESP_LOGI(TAG, "Matrix LongPress, axis: (%"PRIu8", %"PRIu8") index: %"PRIu8, out_message->position.x_axis,
out_message->position.y_axis, out_message->position.index);
}
}
#endif
Expand All @@ -105,7 +112,8 @@ void app_main(void)
};
ESP_ERROR_CHECK(touch_matrix_create(&matrix_config, &matrix_handle));
/* Subscribe touch matrix events (On Press, On Release, On LongPress) */
ESP_ERROR_CHECK(touch_matrix_subscribe_event(matrix_handle, TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, NULL));
ESP_ERROR_CHECK(touch_matrix_subscribe_event(matrix_handle,
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_LONGPRESS, NULL));
#ifdef CONFIG_TOUCH_ELEM_EVENT
/* Set EVENT as the dispatch method */
ESP_ERROR_CHECK(touch_matrix_set_dispatch_method(matrix_handle, TOUCH_ELEM_DISP_EVENT));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
idf_component_register(SRCS "touch_slider_example_main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES touch_element)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "touch_element/touch_slider.h"
Expand Down Expand Up @@ -51,11 +52,11 @@ static void slider_handler_task(void *arg)
/* Decode message */
const touch_slider_message_t *slider_message = touch_slider_get_message(&element_message);
if (slider_message->event == TOUCH_SLIDER_EVT_ON_PRESS) {
ESP_LOGI(TAG, "Slider Press, position: %d", slider_message->position);
ESP_LOGI(TAG, "Slider Press, position: %"PRIu32, slider_message->position);
} else if (slider_message->event == TOUCH_SLIDER_EVT_ON_RELEASE) {
ESP_LOGI(TAG, "Slider Release, position: %d", slider_message->position);
ESP_LOGI(TAG, "Slider Release, position: %"PRIu32, slider_message->position);
} else if (slider_message->event == TOUCH_SLIDER_EVT_ON_CALCULATION) {
ESP_LOGI(TAG, "Slider Calculate, position: %d", slider_message->position);
ESP_LOGI(TAG, "Slider Calculate, position: %"PRIu32, slider_message->position);
}
}
}
Expand All @@ -69,11 +70,11 @@ void slider_handler(touch_slider_handle_t out_handle, touch_slider_message_t *ou
return;
}
if (out_message->event == TOUCH_SLIDER_EVT_ON_PRESS) {
ESP_LOGI(TAG, "Slider Press, position: %d", out_message->position);
ESP_LOGI(TAG, "Slider Press, position: %"PRIu32, out_message->position);
} else if (out_message->event == TOUCH_SLIDER_EVT_ON_RELEASE) {
ESP_LOGI(TAG, "Slider Release, position: %d", out_message->position);
ESP_LOGI(TAG, "Slider Release, position: %"PRIu32, out_message->position);
} else if (out_message->event == TOUCH_SLIDER_EVT_ON_CALCULATION) {
ESP_LOGI(TAG, "Slider Calculate, position: %d", out_message->position);
ESP_LOGI(TAG, "Slider Calculate, position: %"PRIu32, out_message->position);
}
}
#endif
Expand All @@ -97,7 +98,8 @@ void app_main(void)
};
ESP_ERROR_CHECK(touch_slider_create(&slider_config, &slider_handle));
/* Subscribe touch slider events (On Press, On Release, On Calculation) */
ESP_ERROR_CHECK(touch_slider_subscribe_event(slider_handle, TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL));
ESP_ERROR_CHECK(touch_slider_subscribe_event(slider_handle,
TOUCH_ELEM_EVENT_ON_PRESS | TOUCH_ELEM_EVENT_ON_RELEASE | TOUCH_ELEM_EVENT_ON_CALCULATION, NULL));
#ifdef CONFIG_TOUCH_ELEM_EVENT
/* Set EVENT as the dispatch method */
ESP_ERROR_CHECK(touch_slider_set_dispatch_method(slider_handle, TOUCH_ELEM_DISP_EVENT));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
idf_component_register(SRCS "tp_interrupt_main.c"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
Expand Down Expand Up @@ -93,7 +94,7 @@ static void tp_example_read_task(void *pvParameter)
touch_pad_read_filtered(i, &value);
if (value < s_pad_init_val[i] * TOUCH_THRESH_PERCENT / 100) {
ESP_LOGI(TAG, "T%d activated!", i);
ESP_LOGI(TAG, "value: %d; init val: %d", value, s_pad_init_val[i]);
ESP_LOGI(TAG, "value: %"PRIu16"; init val: %"PRIu32, value, s_pad_init_val[i]);
vTaskDelay(200 / portTICK_PERIOD_MS);
// Reset the counter to stop changing mode.
change_mode = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
idf_component_register(SRCS "tp_read_main.c"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/touch_pad.h"
Expand Down Expand Up @@ -33,10 +34,10 @@ static void tp_example_read_task(void *pvParameter)
// If open the filter mode, please use this API to get the touch pad count.
touch_pad_read_raw_data(i, &touch_value);
touch_pad_read_filtered(i, &touch_filter_value);
printf("T%d:[%4d,%4d] ", i, touch_value, touch_filter_value);
printf("T%d:[%4"PRIu16",%4"PRIu16"] ", i, touch_value, touch_filter_value);
#else
touch_pad_read(i, &touch_value);
printf("T%d:[%4d] ", i, touch_value);
printf("T%d:[%4"PRIu16"] ", i, touch_value);
#endif
}
printf("\n");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
idf_component_register(SRCS "tp_interrupt_main.c"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
Loading

0 comments on commit 935a63e

Please sign in to comment.