Files
MeshCore/variants/m5stack_cardputer_adv/hw/CardputerLayout.h
T
mjgodatandClaude Opus 5.5 5681898ad4 Add M5Stack Cardputer-Adv variant with keyboard/display companion UI
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>
2026-10-27 16:24:43 -07:00

78 lines
2.0 KiB
C++

#pragma once
#include "CardputerKeyboard.h"
#include "globals.h"
#include <FS.h>
#include <stdint.h>
#define TOTAL_KEYS 56
namespace Keyboard {
namespace Layout {
enum LayoutType { LAYOUT_TYPE_MAIN, LAYOUT_TYPE_ALT };
enum LayerMask {
LAYER_MASK_BASE = 0x00,
LAYER_MASK_FN = 0x01,
LAYER_MASK_CTRL = 0x02,
LAYER_MASK_SHIFT = 0x04,
LAYER_MASK_OPT = 0x08,
LAYER_MASK_ALT = 0x10
};
struct LayoutEntry {
char data[KB_LAYOUT_CHAR_MAX + 1];
};
struct LayoutLayer {
uint8_t modifiers_mask;
LayoutEntry entries[TOTAL_KEYS];
};
struct LayoutData {
char language_code[3];
uint8_t layers_count;
LayoutLayer *layers;
};
class CardputerLayout {
private:
LayoutData *main_layout = nullptr;
LayoutData *alternate_layout = nullptr;
LayoutData *current_layout = nullptr;
LayoutType current_layout_type = LAYOUT_TYPE_MAIN;
void parseLayout(FS &fs, LayoutType layoutType);
uint8_t getLayerMask(Keyboard::Modifiers modifiers) const;
public:
CardputerLayout();
void begin(FS &fs);
/// @brief Tries to find a matching layout utf-8 character
/// @param event Keyboard event
/// @param force_default Ignores custom layout and uses the default one
/// @return Utf-8 character or empty string. NULL is never returned.
const char *lookup(Keyboard::Event &event, bool force_default = false);
inline const char *lookupDefault(Keyboard::Event &event) { return lookup(event, true); }
void switchLayout();
inline Keyboard::Layout::LayoutType getCurrentLayoutType() const { return current_layout_type; }
inline bool hasAlternateLayout() const { return alternate_layout; }
inline const char *getMainLayoutCode() const { return main_layout ? main_layout->language_code : "??"; }
inline const char *getAlternateLayoutCode() const {
return alternate_layout ? alternate_layout->language_code : "??";
}
inline const char *getCurrentCode() const {
return getCurrentLayoutType() == LAYOUT_TYPE_MAIN ? getMainLayoutCode() : getAlternateLayoutCode();
}
};
} // namespace Layout
} // namespace Keyboard
using Keyboard::Layout::CardputerLayout;