reference: 早先那版 C 写的装甲板固件(ESP-IDF 工程)
`armor/` 是它的 Rust 改写版,这一份留着当参考:ADC 阈值的 2000 就是从它标定出来的 (`.env.example` 里那句 "same as the reference firmware" 指的就是它),而且它的 README 记着实测设备与 MAC,换硬件时是有用的现场记录。 只收了 20 个源文件。它自带的 `.gitignore` 已经排掉 `build/`(211 MB 的 ESP-IDF 构建产物) 与生成的 `sdkconfig`,所以仓库里不会多出这些东西。 两处顺带处理: - `reference/armor/.git` 是一个**空的**仓库壳(`git init` 过,零提交、零 remote、零 ref), 而外层 git 正因为它的存在而拒绝索引 `reference/` 下的任何文件 (`error: 'reference/armor/' does not have a commit checked out`)。它被挪到 `desktop/.dev/backup/reference-armor-git`(可逆,且该目录已被忽略),不是删除。 - 它的 README 指着 `../armor-platformio-backup/`,那份备份并不存在。改成明说"没有进仓库", 免得以后有人照着找一个不存在的目录。 另外把 `/docs/` 加进 .gitignore:那是工作区里另起的一个 Astro 文档站,与本仓库无关。
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "esp_now.h"
|
||||
#include "esp_wifi.h"
|
||||
|
||||
/**
|
||||
* @brief ESP-NOW peer link (ported from the Arduino/ESP-NOW version).
|
||||
*
|
||||
* Runs ESP-NOW on the station interface of channel 14 with a broadcast peer
|
||||
* used for pairing requests, plus a stored unicast peer used for the normal
|
||||
* game traffic.
|
||||
*/
|
||||
class Air {
|
||||
public:
|
||||
/**
|
||||
* Over-the-air packet. The original declared it `alignas(1)`; `packed`
|
||||
* expresses the same intent (sizeof == 19, no trailing padding) in a way
|
||||
* that is portable C++.
|
||||
*/
|
||||
struct __attribute__((packed)) packet_t {
|
||||
uint32_t color = 0;
|
||||
uint32_t hit_cnt = 0;
|
||||
uint8_t dbus[10] = {0};
|
||||
int8_t rssi = 0;
|
||||
};
|
||||
|
||||
static packet_t my_packet, peer_packet;
|
||||
static volatile uint32_t last_air_ms;
|
||||
|
||||
static volatile bool is_pairing;
|
||||
static volatile bool pairing_found;
|
||||
|
||||
static void begin();
|
||||
static void entryPairing();
|
||||
static void savePairing();
|
||||
static void onLoop();
|
||||
|
||||
// The USB-CDC task writes my_packet.dbus while the application task reads
|
||||
// it, so the copy/clear are serialised here instead of being done inline.
|
||||
static void dbusSet(const uint8_t *src, size_t len);
|
||||
static void dbusClear();
|
||||
|
||||
private:
|
||||
static const uint8_t empty_mac[6];
|
||||
static const uint8_t pairing_data[4];
|
||||
|
||||
static esp_now_peer_info_t broadcast_peer;
|
||||
static esp_now_peer_info_t peer;
|
||||
|
||||
static volatile int8_t pairing_best_rssi;
|
||||
|
||||
static void onRecv(const esp_now_recv_info_t *info, const uint8_t *data, int data_len);
|
||||
static void promiscuous_rx_cb(void *buf, wifi_promiscuous_pkt_type_t type);
|
||||
};
|
||||
Reference in New Issue
Block a user