Dozingfiretruck 1 tahun lalu
induk
melakukan
b95c1326fa
2 mengubah file dengan 36 tambahan dan 33 penghapusan
  1. 29 18
      components/tp/luat_lib_tp.c
  2. 7 15
      components/tp/luat_tp.c

+ 29 - 18
components/tp/luat_lib_tp.c

@@ -1,6 +1,7 @@
 #include "luat_base.h"
 #include "luat_tp.h"
 #include "luat_msgbus.h"
+#include "luat_gpio.h"
 
 #define LUAT_LOG_TAG "tp"
 #include "luat_log.h"
@@ -29,27 +30,37 @@ static int l_tp_handler(lua_State* L, void* ptr) {
         if (lua_isfunction(L, -1)) {
             lua_pushlightuserdata(L, luat_tp_config);
             lua_newtable(L);
-            lua_pushstring(L, "event");
-            lua_pushinteger(L, luat_tp_data->event);
-            lua_settable(L, -3);
-            lua_pushstring(L, "track_id");
-            lua_pushinteger(L, luat_tp_data->track_id);
-            lua_settable(L, -3);
-            lua_pushstring(L, "x");
-            lua_pushinteger(L, luat_tp_data->x_coordinate);
-            lua_settable(L, -3);
-            lua_pushstring(L, "y");
-            lua_pushinteger(L, luat_tp_data->y_coordinate);
-            lua_settable(L, -3);
-            lua_pushstring(L, "width");
-            lua_pushinteger(L, luat_tp_data->width);
-            lua_settable(L, -3);
-            lua_pushstring(L, "timestamp");
-            lua_pushinteger(L, luat_tp_data->timestamp);
-            lua_settable(L, -3);
+            for (uint8_t i=0; i<LUAT_TP_TOUCH_MAX; i++){
+                if ((TP_EVENT_TYPE_DOWN == luat_tp_data[i].event) || (TP_EVENT_TYPE_UP == luat_tp_data[i].event) || (TP_EVENT_TYPE_MOVE == luat_tp_data[i].event)){
+                    lua_newtable(L);
+                    lua_pushstring(L, "event");
+                    lua_pushinteger(L, luat_tp_data[i].event);
+                    lua_settable(L, -3);
+                    lua_pushstring(L, "track_id");
+                    lua_pushinteger(L, luat_tp_data[i].track_id);
+                    lua_settable(L, -3);
+                    lua_pushstring(L, "x");
+                    lua_pushinteger(L, luat_tp_data[i].x_coordinate);
+                    lua_settable(L, -3);
+                    lua_pushstring(L, "y");
+                    lua_pushinteger(L, luat_tp_data[i].y_coordinate);
+                    lua_settable(L, -3);
+                    lua_pushstring(L, "width");
+                    lua_pushinteger(L, luat_tp_data[i].width);
+                    lua_settable(L, -3);
+                    lua_pushstring(L, "timestamp");
+                    lua_pushinteger(L, luat_tp_data[i].timestamp);
+                    lua_settable(L, -3);
+
+                    lua_pushinteger(L, i + 1);
+                    lua_insert(L, -2);
+                    lua_settable(L, -3);
+                }
+            }
             lua_call(L, 2, 0);
         }
     }
+    luat_gpio_irq_enable(luat_tp_config->pin_int, 1);
     return 0;
 }
 

+ 7 - 15
components/tp/luat_tp.c

@@ -17,28 +17,20 @@ void luat_tp_task_entry(void* param){
         luat_tp_data_t* tp_data = luat_tp_config->tp_data;
         uint8_t touch_num = luat_tp_config->opts->read(luat_tp_config,tp_data);
         if (touch_num){
-            for (uint8_t i=0; i<LUAT_TP_TOUCH_MAX; i++){
-                if ((TP_EVENT_TYPE_DOWN == tp_data[i].event) || (TP_EVENT_TYPE_UP == tp_data[i].event) || (TP_EVENT_TYPE_MOVE == tp_data[i].event)){
-                //     LLOGD("event=%d, track_id=%d, x=%d, y=%d, s=%d, timestamp=%u.\r\n", 
-                //                 tp_data[i].event,
-                //                 tp_data[i].track_id,
-                //                 tp_data[i].x_coordinate,
-                //                 tp_data[i].y_coordinate,
-                //                 tp_data[i].width,
-                //                 tp_data[i].timestamp);
-                    if (luat_tp_config->callback){
-                        luat_tp_config->callback(luat_tp_config,&tp_data[i]);
-                    }
-                }
+            if (luat_tp_config->callback == NULL){
+                luat_gpio_irq_enable(luat_tp_config->pin_int, 1);
+            }else{
+                luat_tp_config->callback(luat_tp_config,tp_data);
             }
+        }else{
+            luat_gpio_irq_enable(luat_tp_config->pin_int, 1);
         }
-        luat_gpio_irq_enable(luat_tp_config->pin_int, 1);
     }
 }
 
 int luat_tp_init(luat_tp_config_t* luat_tp_config){
     if (tp_task_handle == 0){
-        luat_rtos_task_create(&tp_task_handle, 4096, 50, "tp", luat_tp_task_entry, NULL, 10);
+        luat_rtos_task_create(&tp_task_handle, 4096, 10, "tp", luat_tp_task_entry, NULL, 10);
     }
     tp_config_gt911.init(luat_tp_config);