From 04c11b00ec15e9fa3493b10d43609efb3dd7b2b2 Mon Sep 17 00:00:00 2001 From: logzhan <719901725@qq.com> Date: Sat, 24 Sep 2022 18:45:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5UDP=E9=80=9A=E4=BF=A1?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/GeekHAL/HAL/HAL_Button.cpp | 3 ++ .../components/GeekHAL/HAL/HAL_IMU.cpp | 6 +-- 2.Firmware/GeekTrack/main/app_main.c | 47 ++++++++++++++++--- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Button.cpp b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Button.cpp index db93865..349fbb4 100644 --- a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Button.cpp +++ b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_Button.cpp @@ -18,6 +18,9 @@ static void Button_EventHandler(ButtonEvent* btn, int event) if(event == ButtonEvent::EVENT_ButtonClick){ if(btn == &btPOWER){ Button_Info.btnPower = 1; + gpio_pad_select_gpio(21); + gpio_set_direction((gpio_num_t)21, GPIO_MODE_OUTPUT); + gpio_set_level((gpio_num_t)21, 0); printf("Button PWR short click.\n"); } } diff --git a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_IMU.cpp b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_IMU.cpp index c0fe6fc..b43f4ca 100644 --- a/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_IMU.cpp +++ b/2.Firmware/GeekTrack/components/GeekHAL/HAL/HAL_IMU.cpp @@ -43,9 +43,9 @@ void IMU_Update() /* Sensor Debug. */ float yaw = 0.0f, pitch = 0.0f, roll = 0.0f; - MPU9250_GetEulerAngles(&yaw, &roll, &pitch); - - printf("%.2f, %.2f, %.2f\n", yaw, roll, pitch); + + //MPU9250_GetEulerAngles(&yaw, &roll, &pitch); + //printf("%.2f, %.2f, %.2f\n", yaw, roll, pitch); //printf("%.2f, %.2f, %.2f\n", imu.acc[0], imu.acc[1], imu.acc[2]); //printf("%.2f, %.2f, %.2f\n", imu.gyr[0], imu.gyr[1], imu.gyr[2]); diff --git a/2.Firmware/GeekTrack/main/app_main.c b/2.Firmware/GeekTrack/main/app_main.c index 7762888..fa2c93d 100644 --- a/2.Firmware/GeekTrack/main/app_main.c +++ b/2.Firmware/GeekTrack/main/app_main.c @@ -29,13 +29,45 @@ #include "esp_freertos_hooks.h" #include "freertos/semphr.h" -#include "lvgl.h" -#include "lvgl_helpers.h" #include "System/GeekOS.h" #include "WIFINetwork.h" +#include "mpu9250.h" + +#define UDP_PORT 9000 +#define TAG "main" + +static void UdpSendData(void *pvParameters) +{ + struct sockaddr_in saddr = { 0 }; + + int sock = -1; + int err = 0; + /* Init the sock. */ + sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + if (sock < 0) { + ESP_LOGE(TAG, "Failed to create socket. Error %d", errno); + } + + saddr.sin_family = PF_INET; + saddr.sin_port = htons(UDP_PORT); + saddr.sin_addr.s_addr = htonl(IPADDR_BROADCAST); + + char line[128] = " "; + /* Task Send Sensor Data. */ + while (1) { + float yaw, roll, pitch; + MPU9250_GetEulerAngles(&yaw, &roll, &pitch); + sprintf(line, "%f %f %f\n", yaw, roll, pitch); + err = sendto(sock, line, 256, 0, (struct sockaddr *)&saddr, + sizeof(struct sockaddr_in)); + if (err < 0) { + ESP_LOGE(TAG, "IPV4 sendto failed. errno: %d", errno); + } + vTaskDelay(30 / portTICK_PERIOD_MS); + } + close(sock); +} -#define LV_TICK_PERIOD_MS 1 -static void lv_tick_task(void *arg); /**----------------------------------------------------------------------- * Function : app_main * Description : GEEKIMU 程序主入口 @@ -49,10 +81,11 @@ void app_main(void) // vTaskDelay(1500 / portTICK_PERIOD_MS); /* Config serial zero for shell. */ - // userShellInit(0); - // xTaskCreate(shellTask, "shell", 4096, GetEsp32Shell(), 12, NULL); + userShellInit(0); + xTaskCreate(shellTask, "shell", 4096, GetEsp32Shell(), 12, NULL); - // LIB_WIFIConnect(); + LIB_WIFIConnect(); + xTaskCreate(UdpSendData, "UdpSend", 4096, NULL, 5, NULL); uint32_t tick = 0; /* Forever loop. */