mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-10-29 03:32:22 +00:00
New variant variants/m5stack_cardputer_adv for the Cardputer-Adv (ESP32-S3, 8 MB) with the Cap LoRa-1262 (SX1262 + GNSS): - Envs: companion_radio_ble, companion_radio_usb, repeater, room_server. - Board: enables the Cap's antenna path via the PI4IOE5V6408 on the internal I2C bus (Wire1, G8/G9); Wire stays on the Grove port. LoRa and microSD share FSPI because the display owns SPI3. TCXO 1.8 V. - Companion UI adapted from MultiMote/meshcore-cardputer-adv (MIT, LICENSE.MultiMote), running on the standard companion so the USB terminal CLI stays available. Contacts/identity stay in internal SPIFFS; the microSD card is optional (chat history, keyboard layouts). - Sticky Shift, one-shot Fn with Fn+letter shortcuts, top button (G0) sends a flood advert, brightness control. - Text size setting (Normal/Large/Extra large) with DejaVu Sans fonts generated by tools/gen_vlw_font.py; layouts derive from the font size. - Power save maps to the companion's powersaving pref; the UI vetoes light sleep while the screen is on. Low-battery power-off at 3.4 V. - win_long_cmdline.py: Windows-only -iprefix include shortening so the ESP32 compile command stays under the 32,767-character limit. Shared companion changes are guarded by CARDPUTER_ADV_UI: main.cpp selects CardputerDataStore/CardputerUITask/CardputerMesh, and MyMesh.h maps the_mesh to the subclass like the PSRAM storage path does. Tested on hardware (910.525 MHz mesh): radio RX/TX, USB CLI, BLE, UI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
1.3 KiB
C++
74 lines
1.3 KiB
C++
#pragma once
|
|
#include <cstddef>
|
|
|
|
template <typename T, size_t Size> class RingBuffer {
|
|
private:
|
|
T buf[Size];
|
|
size_t head_idx;
|
|
size_t tail_idx;
|
|
bool is_full;
|
|
|
|
public:
|
|
RingBuffer() : head_idx(0), tail_idx(0), is_full(false) {}
|
|
|
|
// Nothing cleared, but index is reset
|
|
inline void clear() {
|
|
head_idx = 0;
|
|
tail_idx = 0;
|
|
is_full = false;
|
|
}
|
|
|
|
// Push element using copy
|
|
void push(T data) {
|
|
if (is_full) {
|
|
tail_idx = (tail_idx + 1) % Size;
|
|
}
|
|
|
|
buf[head_idx] = data;
|
|
head_idx = (head_idx + 1) % Size;
|
|
|
|
if (head_idx == tail_idx) {
|
|
is_full = true;
|
|
}
|
|
}
|
|
|
|
// Not exactly push, but returns the address of the element to push and updates the index, we can use it to modify the element
|
|
T* push_ref() {
|
|
if (is_full) {
|
|
tail_idx = (tail_idx + 1) % Size;
|
|
}
|
|
|
|
T* ptr = &buf[head_idx];
|
|
|
|
head_idx = (head_idx + 1) % Size;
|
|
|
|
if (head_idx == tail_idx) {
|
|
is_full = true;
|
|
}
|
|
|
|
return ptr;
|
|
}
|
|
|
|
bool get(size_t index, const T* &data) const {
|
|
if (index >= count()) {
|
|
return false;
|
|
}
|
|
|
|
size_t real_idx = (tail_idx + index) % Size;
|
|
data = &buf[real_idx];
|
|
return true;
|
|
}
|
|
|
|
size_t count() const {
|
|
if (is_full) {
|
|
return Size;
|
|
}
|
|
|
|
if (head_idx >= tail_idx) {
|
|
return head_idx - tail_idx;
|
|
}
|
|
|
|
return Size + head_idx - tail_idx;
|
|
}
|
|
};
|