move bbnow code

This commit is contained in:
2026-07-20 15:48:07 -05:00
parent 98b5b96171
commit 67a85f2c11
3 changed files with 12 additions and 101 deletions
+10 -2
View File
@@ -20,11 +20,19 @@ dependencies:
idf: idf:
source: source:
type: idf type: idf
version: 6.0.1 version: 6.0.0
lvgl/lvgl:
component_hash: d7c1ac037ae6e85d94897f807d6e7ba0946a83e720074fc95a4f6241da9f9f53
dependencies: []
source:
registry_url: https://components.espressif.com/
type: service
version: 8.4.0
direct_dependencies: direct_dependencies:
- atanisoft/esp_lcd_ili9488 - atanisoft/esp_lcd_ili9488
- espressif/led_strip - espressif/led_strip
- idf - idf
manifest_hash: 104ee01597639c0b6c90ebbe71e61d9642bbc422f80747aa239202863e58174a - lvgl/lvgl
manifest_hash: 5310bc9c053335562a91430b060b867c038be3618c4dd8d268b10627680fe2d0
target: esp32s3 target: esp32s3
version: 3.0.0 version: 3.0.0
+1 -98
View File
@@ -1,4 +1,3 @@
#include "bbnow.hpp"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
@@ -17,6 +16,7 @@
#include "blk_box_drivers/ssegs.hpp" #include "blk_box_drivers/ssegs.hpp"
#include "blk_box_drivers/helpers.hpp" #include "blk_box_drivers/helpers.hpp"
#include "blk_box_drivers/tft.hpp" #include "blk_box_drivers/tft.hpp"
#include "blk_box_drivers/bbnow.hpp"
#include <lvgl.h> #include <lvgl.h>
@@ -30,97 +30,8 @@
#include "esp_crc.h" #include "esp_crc.h"
#include "nvs_flash.h" #include "nvs_flash.h"
#define ESPNOW_CHANNEL 6
#define ESPNOW_DATA_MAX_LEN 24
const static char TAG[] = "main"; const static char TAG[] = "main";
const static uint8_t ESPNOW_PMK[16] = {0x4F, 0xA2, 0x8E, 0x11, 0xD7, 0x6C, 0xB5, 0x3E, 0x94, 0xF0, 0x2A, 0x83, 0xC6, 0x9D, 0x1B, 0x5E};
const static uint8_t BROADCAST_MAC[ESP_NOW_ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
static void example_espnow_send_cb(const esp_now_send_info_t *tx_info, esp_now_send_status_t status);
static void example_espnow_recv_cb(const esp_now_recv_info_t *recv_info, const uint8_t *data, int len);
void init_nvs(void) {
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK( nvs_flash_erase() );
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
}
void init_wifi(void)
{
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) );
ESP_ERROR_CHECK( esp_wifi_start());
ESP_ERROR_CHECK( esp_wifi_set_channel(ESPNOW_CHANNEL, WIFI_SECOND_CHAN_NONE));
// enable long range
// ESP_ERROR_CHECK( esp_wifi_set_protocol(ESPNOW_WIFI_IF, WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_LR) );
}
void init_espnow(void) {
ESP_ERROR_CHECK( esp_now_init() );
ESP_ERROR_CHECK( esp_now_register_send_cb(example_espnow_send_cb) );
ESP_ERROR_CHECK( esp_now_register_recv_cb(example_espnow_recv_cb) );
/* Set primary master key. */
ESP_ERROR_CHECK( esp_now_set_pmk(ESPNOW_PMK));
// Add broadcast peer information to peer list, allowing us to send to it
esp_now_peer_info_t peer = {0};
peer.channel = ESPNOW_CHANNEL;
peer.ifidx = WIFI_IF_AP;
peer.encrypt = false;
memcpy(peer.peer_addr, BROADCAST_MAC, ESP_NOW_ETH_ALEN);
ESP_ERROR_CHECK( esp_now_add_peer(&peer) );
}
/* ESPNOW sending or receiving callback function is called in WiFi task.
* Users should not do lengthy operations from this task. Instead, post
* necessary data to a queue and handle it from a lower priority task. */
static void example_espnow_send_cb(const esp_now_send_info_t *tx_info, esp_now_send_status_t status)
{
if (tx_info == NULL) {
ESP_LOGE(TAG, "Send cb arg error");
return;
}
ESP_LOGI(TAG, "sending espnow packet of size: %d to " MACSTR, tx_info->data_len, MAC2STR(tx_info->des_addr));
}
static void example_espnow_recv_cb(const esp_now_recv_info_t *recv_info, const uint8_t *data, int len)
{
uint8_t * src_addr = recv_info->src_addr;
uint8_t * des_addr = recv_info->des_addr;
if (src_addr == NULL || data == NULL || len <= 0) {
ESP_LOGE(TAG, "Receive cb arg error");
return;
}
ESP_LOGI(TAG, "got espnow packet of size: %d from " MACSTR " to " MACSTR, MAC2STR(src_addr), MAC2STR(des_addr));
// if (IS_BROADCAST_ADDR(des_addr)) {
// /* If added a peer with encryption before, the receive packets may be
// * encrypted as peer-to-peer message or unencrypted over the broadcast channel.
// * Users can check the destination address to distinguish it.
// */
// ESP_LOGD(TAG, "Receive broadcast ESPNOW data");
// } else {
// ESP_LOGD(TAG, "Receive unicast ESPNOW data");
// }
}
extern "C" void app_main(void) { extern "C" void app_main(void) {
BlkBoxInitConfig blk_box_cfg = {}; BlkBoxInitConfig blk_box_cfg = {};
init_blk_box(blk_box_cfg); init_blk_box(blk_box_cfg);
@@ -174,14 +85,6 @@ extern "C" void app_main(void) {
SSegController::enable_game_timer(); SSegController::enable_game_timer();
SSegController::enable_module_timer(); SSegController::enable_module_timer();
ESP_LOGI(TAG, "initializing nvs");
init_nvs();
ESP_LOGI(TAG, "initializing wifi");
init_wifi();
ESP_LOGI(TAG, "initializing espnow");
init_espnow();
ESP_LOGI(TAG, "initialized!");
// uint8_t mac[6]; // uint8_t mac[6];
// ESP_ERROR_CHECK(esp_wifi_get_mac(WIFI_IF_STA, mac)); // ESP_ERROR_CHECK(esp_wifi_get_mac(WIFI_IF_STA, mac));
// ESP_LOGI(TAG, "My MAC: %02X:%02X:%02X:%02X:%02X:%02X", // ESP_LOGI(TAG, "My MAC: %02X:%02X:%02X:%02X:%02X:%02X",