Function bodies 879 total
getModeBits function · c · L157-L174 (18 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static char getModeBits(uint8_t version, uint8_t mode) {
// Note: We use 15 instead of 16; since 15 doesn't exist and we cannot store 16 (8 + 8) in 3 bits
// hex(int("".join(reversed([('00' + bin(x - 8)[2:])[-3:] for x in [10, 9, 8, 12, 11, 15, 14, 13, 15]])), 2))
unsigned int modeInfo = 0x7bbb80a;
#if LOCK_VERSION == 0 || LOCK_VERSION > 9
if (version > 9) { modeInfo >>= 9; }
#endif
#if LOCK_VERSION == 0 || LOCK_VERSION > 26
if (version > 26) { modeInfo >>= 9; }
#endif
char result = 8 + ((modeInfo >> (3 * mode)) & 0x07);
if (result == 15) { result = 16; }
return result;
}bb_dump function · c · L186-L193 (8 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
void bb_dump(BitBucket *bitBuffer) {
printf("Buffer: ");
for (uint32_t i = 0; i < bitBuffer->capacityBytes; i++) {
printf("%02x", bitBuffer->data[i]);
if ((i % 4) == 3) { printf(" "); }
}
printf("\n");
}bb_getGridSizeBytes function · c · L195-L198 (4 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static uint16_t bb_getGridSizeBytes(uint8_t size) {
return (((size * size) + 7) >> 3);
}bb_getBufferSizeBytes function · c · L199-L202 (4 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static uint16_t bb_getBufferSizeBytes(uint32_t bits) {
return ((bits + 7) >> 3);
}bb_initBuffer function · c · L203-L210 (8 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void bb_initBuffer(BitBucket *bitBuffer, uint8_t *data, int32_t capacityBytes) {
bitBuffer->bitOffsetOrWidth = 0;
bitBuffer->capacityBytes = capacityBytes;
bitBuffer->data = data;
memset(data, 0, bitBuffer->capacityBytes);
}bb_initGrid function · c · L211-L218 (8 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void bb_initGrid(BitBucket *bitGrid, uint8_t *data, uint8_t size) {
bitGrid->bitOffsetOrWidth = size;
bitGrid->capacityBytes = bb_getGridSizeBytes(size);
bitGrid->data = data;
memset(data, 0, bitGrid->capacityBytes);
}bb_appendBits function · c · L219-L229 (11 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static bool bb_appendBits(BitBucket *bitBuffer, uint32_t val, uint8_t length) {
uint32_t offset = bitBuffer->bitOffsetOrWidth;
for (int_fast8_t i = length - 1; i >= 0; i--, offset++) {
size_t index = offset >> 3;
if (bitBuffer->capacityBytes <= index) return false;
bitBuffer->data[index] |= ((val >> i) & 1) << (7 - (offset & 7));
}
bitBuffer->bitOffsetOrWidth = offset;
return true;
}All rows above produced by Repobility · https://repobility.com
bb_setBits function · c · L231-L235 (5 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
void bb_setBits(BitBucket *bitBuffer, uint32_t val, int offset, uint8_t length) {
for (int8_t i = length - 1; i >= 0; i--, offset++) {
bitBuffer->data[offset >> 3] |= ((val >> i) & 1) << (7 - (offset & 7));
}
}bb_setBit function · c · L237-L245 (9 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void bb_setBit(BitBucket *bitGrid, uint_fast8_t x, uint_fast8_t y, bool on) {
uint32_t offset = y * bitGrid->bitOffsetOrWidth + x;
uint8_t mask = 1 << (7 - (offset & 0x07));
if (on) {
bitGrid->data[offset >> 3] |= mask;
} else {
bitGrid->data[offset >> 3] &= ~mask;
}
}bb_invertBit function · c · L246-L256 (11 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void bb_invertBit(BitBucket *bitGrid, uint_fast8_t x, uint_fast8_t y, bool invert) {
uint32_t offset = y * bitGrid->bitOffsetOrWidth + x;
uint8_t mask = 1 << (7 - (offset & 0x07));
bool on = ((bitGrid->data[offset >> 3] & (1 << (7 - (offset & 0x07)))) != 0);
if (on ^ invert) {
bitGrid->data[offset >> 3] |= mask;
} else {
bitGrid->data[offset >> 3] &= ~mask;
}
}bb_getBit function · c · L257-L261 (5 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static bool bb_getBit(BitBucket *bitGrid, uint_fast8_t x, uint_fast8_t y) {
uint32_t offset = y * bitGrid->bitOffsetOrWidth + x;
return (bitGrid->data[offset >> 3] & (1 << (7 - (offset & 0x07)))) != 0;
}applyMask function · c · L270-L291 (22 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void applyMask(BitBucket *modules, BitBucket *isFunction, uint8_t mask) {
uint8_t size = modules->bitOffsetOrWidth;
for (uint_fast8_t y = 0; y < size; y++) {
for (uint_fast8_t x = 0; x < size; x++) {
if (bb_getBit(isFunction, x, y)) { continue; }
bool invert = 0;
switch (mask) {
case 0: invert = ((x + y) & 1) == 0; break;
case 1: invert = (y & 1) == 0; break;
case 2: invert = (x % 3) == 0; break;
case 3: invert = ((x + y) % 3) == 0; break;
case 4: invert = ((x / 3 + (y >> 1)) & 1) == 0; break;
case 5: invert = (((x * y) & 1) + x * y % 3) == 0; break;
case 6: invert = ((((x * y) & 1) + x * y % 3) & 1) == 0;break;
case 7: invert = ((((x + y) & 1) + x * y % 3) & 1) == 0;break;
}
setFunctionModule function · c · L292-L296 (5 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void setFunctionModule(BitBucket *modules, BitBucket *isFunction, uint_fast8_t x, uint_fast8_t y, bool on) {
bb_setBit(modules, x, y, on);
bb_setBit(isFunction, x, y, true);
}drawFinderPattern function · c · L299-L311 (13 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void drawFinderPattern(BitBucket *modules, BitBucket *isFunction, uint_fast8_t x, uint_fast8_t y) {
uint8_t size = modules->bitOffsetOrWidth;
for (int_fast8_t i = -4; i <= 4; i++) {
for (int_fast8_t j = -4; j <= 4; j++) {
uint_fast8_t dist = max(abs(i), abs(j)); // Chebyshev/infinity norm
int_fast16_t xx = x + j, yy = y + i;
if (0 <= xx && xx < size && 0 <= yy && yy < size) {
setFunctionModule(modules, isFunction, xx, yy, dist != 2 && dist != 4);
}
}
}
}drawAlignmentPattern function · c · L314-L320 (7 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void drawAlignmentPattern(BitBucket *modules, BitBucket *isFunction, uint_fast8_t x, uint_fast8_t y) {
for (int_fast8_t i = -2; i <= 2; i++) {
for (int_fast8_t j = -2; j <= 2; j++) {
setFunctionModule(modules, isFunction, x + j, y + i, max(abs(i), abs(j)) != 1);
}
}
}Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
drawFormatBits function · c · L324-L361 (38 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void drawFormatBits(BitBucket *modules, BitBucket *isFunction, uint8_t ecc, uint8_t mask) {
uint8_t size = modules->bitOffsetOrWidth;
// Calculate error correction code and pack bits
uint32_t data = ecc << 3 | mask; // errCorrLvl is uint2, mask is uint3
uint32_t rem = data;
for (int i = 0; i < 10; i++) {
rem = (rem << 1) ^ ((rem >> 9) * 0x537);
}
data = data << 10 | rem;
data ^= 0x5412; // uint15
// Draw first copy
for (uint_fast8_t i = 0; i <= 5; i++) {
setFunctionModule(modules, isFunction, 8, i, ((data >> i) & 1) != 0);
}
setFunctionModule(modules, isFunction, 8, 7, ((data >> 6) & 1) != 0);
setFunctionModule(modules, isFunction, 8, 8, ((data >> 7) & 1) != 0);
setFunctionModule(modules, isFunction, 7, 8, ((data >> 8) & 1) != 0);
for (int_fast8_t i = 9; i < 15; i++) {
setFunctionModule(modules, isFunction, 14 - i, 8, ((data >> i) & 1) != 0);
}
// Draw second copy
for (int_fadrawVersion function · c · L366-L393 (28 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void drawVersion(BitBucket *modules, BitBucket *isFunction, uint8_t version) {
int8_t size = modules->bitOffsetOrWidth;
#if LOCK_VERSION != 0 && LOCK_VERSION < 7
return;
#else
if (version < 7) { return; }
// Calculate error correction code and pack bits
uint32_t rem = version; // version is uint6, in the range [7, 40]
for (uint_fast8_t i = 0; i < 12; i++) {
rem = (rem << 1) ^ ((rem >> 11) * 0x1F25);
}
uint32_t data = version << 12 | rem; // uint18
// Draw two copies
for (uint_fast8_t i = 0; i < 18; i++) {
bool bit = ((data >> i) & 1) != 0;
uint8_t a = size - 11 + i % 3, b = i / 3;
setFunctionModule(modules, isFunction, a, b, bit);
setFunctionModule(modules, isFunction, b, a, bit);
}
#endif
}drawFunctionPatterns function · c · L394-L450 (57 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void drawFunctionPatterns(BitBucket *modules, BitBucket *isFunction, uint8_t version, uint8_t ecc) {
uint8_t size = modules->bitOffsetOrWidth;
// Draw the horizontal and vertical timing patterns
for (uint_fast8_t i = 0; i < size; i++) {
setFunctionModule(modules, isFunction, 6, i, (i & 1) == 0);
setFunctionModule(modules, isFunction, i, 6, (i & 1) == 0);
}
// Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
drawFinderPattern(modules, isFunction, 3, 3);
drawFinderPattern(modules, isFunction, size - 4, 3);
drawFinderPattern(modules, isFunction, 3, size - 4);
#if LOCK_VERSION == 0 || LOCK_VERSION > 1
if (version > 1) {
// Draw the numerous alignment patterns
uint_fast8_t alignCount = version / 7 + 2;
uint_fast8_t step;
if (version != 32) {
step = (version * 4 + alignCount * 2 + 1) / (2 * alignCount - 2) * 2; // ceil((size - 13) / (2*numAlidrawCodewords function · c · L455-L483 (29 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void drawCodewords(BitBucket *modules, BitBucket *isFunction, BitBucket *codewords) {
uint32_t bitLength = codewords->bitOffsetOrWidth;
uint8_t *data = codewords->data;
uint8_t size = modules->bitOffsetOrWidth;
// Bit index into the data
uint32_t i = 0;
// Do the funny zigzag scan
for (int_fast16_t right = size - 1; right >= 1; right -= 2) { // Index of right column in each column pair
if (right == 6) { right = 5; }
for (uint_fast8_t vert = 0; vert < size; vert++) { // Vertical counter
for (int j = 0; j < 2; j++) {
uint8_t x = right - j; // Actual x coordinate
bool upwards = ((right & 2) == 0) ^ (x < 6);
uint8_t y = upwards ? size - 1 - vert : vert; // Actual y coordinate
if (!bb_getBit(isFunction, x, y) && i < bitLength) {
bb_setBit(modules, x, y, ((data[i >> 3] >> (7 - (i & 7))) & 1) != 0);
i++;
getPenaltyScore function · c · L497-L584 (88 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static uint32_t getPenaltyScore(BitBucket *modules) {
uint32_t result = 0;
uint8_t size = modules->bitOffsetOrWidth;
// Adjacent modules in row having same color
for (uint_fast8_t y = 0; y < size; y++) {
bool colorX = bb_getBit(modules, 0, y);
for (uint_fast8_t x = 1, runX = 1; x < size; x++) {
bool cx = bb_getBit(modules, x, y);
if (cx != colorX) {
colorX = cx;
runX = 1;
} else {
runX++;
if (runX == 5) {
result += PENALTY_N1;
} else if (runX > 5) {
result++;
}
}
}
}
// Adjacent modules in column having same color
for (uint_fast8_t x = 0; x < size; x++) {
bool colorY = bb_getBit(modules, x, 0);
for (uint_fast8_t y = 1, runY = 1; y < size; y++) {
bool cy = bb_getBit(modules, x, y);
if (cy != colorY) {
rs_multiply function · c · L588-L598 (11 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static uint8_t rs_multiply(uint_fast8_t x, uint_fast8_t y) {
// Russian peasant multiplication
// See: https://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication
uint16_t z = 0;
for (int_fast8_t i = 7; i >= 0; i--) {
z = (z << 1) ^ ((z >> 7) * 0x11D);
z ^= ((y >> i) & 1) * x;
}
return z;
}rs_init function · c · L599-L618 (20 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void rs_init(uint8_t degree, uint8_t *coeff) {
memset(coeff, 0, degree);
coeff[degree - 1] = 1;
// Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
// drop the highest term, and store the rest of the coefficients in order of descending powers.
// Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
uint16_t root = 1;
for (uint_fast8_t i = 0; i < degree; i++) {
// Multiply the current product by (x - r^i)
for (uint_fast8_t j = 0; j < degree; j++) {
coeff[j] = rs_multiply(coeff[j], root);
if (j + 1 < degree) {
coeff[j] ^= coeff[j + 1];
}
}
root = (root << 1) ^ ((root >> 7) * 0x11D); // Multiply by 0x02 mod GF(2^8/0x11D)
}
}rs_getRemainder function · c · L619-L637 (19 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static void rs_getRemainder(uint8_t degree, uint8_t *coeff, uint8_t *data, uint8_t length, uint8_t *result, uint8_t stride) {
// Compute the remainder by performing polynomial division
//for (uint8_t i = 0; i < degree; i++) { result[] = 0; }
//memset(result, 0, degree);
for (uint_fast8_t i = 0; i < length; i++) {
uint8_t factor = data[i] ^ result[0];
for (uint_fast8_t j = 1; j < degree; j++) {
result[(j - 1) * stride] = result[j * stride];
}
result[(degree - 1) * stride] = 0;
for (uint_fast8_t j = 0; j < degree; j++) {
result[j * stride] ^= rs_multiply(coeff[j], factor);
}
}
}Repobility — the code-quality scanner for AI-generated software · https://repobility.com
encodeDataCodewords function · c · L642-L701 (60 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static int8_t encodeDataCodewords(BitBucket *dataCodewords, const uint8_t *text, uint16_t length, uint8_t version) {
int8_t mode = MODE_BYTE;
if (isNumeric((char*)text, length)) {
mode = MODE_NUMERIC;
bb_appendBits(dataCodewords, 1 << MODE_NUMERIC, 4);
bb_appendBits(dataCodewords, length, getModeBits(version, MODE_NUMERIC));
uint16_t accumData = 0;
uint8_t accumCount = 0;
for (uint16_t i = 0; i < length; i++) {
accumData = accumData * 10 + ((char)(text[i]) - '0');
accumCount++;
if (accumCount == 3) {
if (!bb_appendBits(dataCodewords, accumData, 10)) return -1;
accumData = 0;
accumCount = 0;
}
}
// 1 or 2 digits remaining
if (accumCount > 0) {
bb_appendBits(dataCodewords, accumData, accumCount * 3 + 1);
}
} else if (isAlphanumeric((char*)text, length)) {
mode = MODE_ALPHANUMERIperformErrorCorrection function · c · L702-L779 (78 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
static bool performErrorCorrection(uint8_t version, uint8_t ecc, BitBucket *data) {
// See: http://www.thonky.com/qr-code-tutorial/structure-final-message
#if LOCK_VERSION == 0
uint8_t numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecc][version - 1];
uint16_t totalEcc = NUM_ERROR_CORRECTION_CODEWORDS[ecc][version - 1];
uint16_t moduleCount = NUM_RAW_DATA_MODULES[version - 1];
#else
uint8_t numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecc];
uint16_t totalEcc = NUM_ERROR_CORRECTION_CODEWORDS[ecc];
uint16_t moduleCount = NUM_RAW_DATA_MODULES;
#endif
uint8_t blockEccLen = totalEcc / numBlocks;
uint8_t numShortBlocks = numBlocks - moduleCount / 8 % numBlocks;
uint8_t shortBlockLen = moduleCount / 8 / numBlocks;
uint8_t shortDataBlockLen = shortBlockLen - blockEccLen;
uint8_t* result = (uint8_t*)alloca(data->capacityBytes);
memset(result, 0, data->capacityBytes);
uint8_t* coeff = (uint8_t*)alloca(blockEccLen);
rs_init(blockEccLen, coeff)lgfx_qrcode_getBufferSize function · c · L787-L790 (4 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
uint16_t lgfx_qrcode_getBufferSize(uint8_t version) {
return bb_getGridSizeBytes(4 * version + 17);
}lgfx_qrcode_initBytes function · c · L793-L869 (77 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
int8_t lgfx_qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, uint8_t *data, uint16_t length) {
uint8_t size = version * 4 + 17;
qrcode->version = version;
qrcode->size = size;
qrcode->ecc = ecc;
qrcode->modules = modules;
uint8_t eccFormatBits = (ECC_FORMAT_BITS >> (2 * ecc)) & 0x03;
#if LOCK_VERSION == 0
uint16_t moduleCount = NUM_RAW_DATA_MODULES[version - 1];
uint16_t dataCapacity = (moduleCount >> 3) - NUM_ERROR_CORRECTION_CODEWORDS[eccFormatBits][version - 1];
#else
version = LOCK_VERSION;
uint16_t moduleCount = NUM_RAW_DATA_MODULES;
uint16_t dataCapacity = (moduleCount >> 3) - NUM_ERROR_CORRECTION_CODEWORDS[eccFormatBits];
#endif
struct BitBucket codewords;
int32_t codewordLen = bb_getBufferSizeBytes(moduleCount);
uint8_t* codewordBytes = (uint8_t*)alloca(codewordLen);
bb_initBuffer(&codewords, codewordBytes, codewordLen);
// Place the data code words into the buffer
int8_t modlgfx_qrcode_initText function · c · L870-L873 (4 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
int8_t lgfx_qrcode_initText(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, const char *data) {
return lgfx_qrcode_initBytes(qrcode, modules, version, ecc, (uint8_t*)data, strlen(data));
}lgfx_qrcode_getModule function · c · L874-L882 (9 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
bool lgfx_qrcode_getModule(QRCode *qrcode, uint_fast8_t x, uint_fast8_t y) {
if (x >= qrcode->size || y >= qrcode->size) {
return false;
}
uint32_t offset = y * qrcode->size + x;
return qrcode->modules[offset >> 3] & (1 << (7 - (offset & 0x07)));
}lgfx_qrcode_getHexLength function · c · L885-L887 (3 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
uint8_t lgfx_qrcode_getHexLength(QRCode *qrcode) {
return ((qrcode->size * qrcode->size) + 7) / 4;
}lgfx_qrcode_getHex function · c · L888-L891 (4 LOC)firmware/lib/lgfx_qrcode/lgfx_qrcode.c
void lgfx_qrcode_getHex(QRCode *qrcode, char *result) {
}About: code-quality intelligence by Repobility · https://repobility.com
parse_offsets function · python · L30-L41 (12 LOC)firmware/merge.py
def parse_offsets():
out = DEFAULT_OFFSETS.copy()
boot = os.environ.get("BOOT_OFFSET")
part = os.environ.get("PART_OFFSET")
app = os.environ.get("APP_OFFSET")
if boot:
out["boot"] = int(boot, 0)
if part:
out["part"] = int(part, 0)
if app:
out["app"] = int(app, 0)
return outread_file function · python · L43-L45 (3 LOC)firmware/merge.py
def read_file(path):
with open(path, "rb") as f:
return f.read()_merge_action function · python · L47-L83 (37 LOC)firmware/merge.py
def _merge_action(source, target, env):
try:
offsets = parse_offsets()
items = []
for name, path in FILES.items():
if os.path.isfile(path):
data = read_file(path)
items.append((name, offsets[name], len(data), data, path))
print("[post-build] found", name, "->", path, "size", hex(len(data)))
else:
print("[post-build] missing", name, "->", path)
if not any(i[0] == "app" for i in items):
print("[post-build] ERROR: firmware.bin not found; aborting merge")
return
# check overlaps
for i in range(len(items)):
n1,o1,s1,_,_ = items[i]
for j in range(i+1, len(items)):
n2,o2,s2,_,_ = items[j]
if o1 < o2 + s2 and o2 < o1 + s1:
print("[post-build] ERROR: overlap between", n1, "and", n2)
return
final_size = max(o + s for _,o,s,_,_ inConfigManager class · c · L37-L99 (63 LOC)firmware/src/core/ConfigManager.h
class ConfigManager
{
public:
static ConfigManager& getInstance() {
static ConfigManager instance;
return instance;
}
void load(IStorage* storage) {
if (!storage || !storage->isAvailable()) return;
String content = storage->readFile("/unigeek/config");
if (content.length() == 0) return;
_data.clear();
int start = 0;
while (start < (int)content.length()) {
int nl = content.indexOf('\n', start);
if (nl < 0) nl = content.length();
String line = content.substring(start, nl);
line.trim();
int sep = line.indexOf('=');
if (sep > 0) _data[line.substring(0, sep)] = line.substring(sep + 1);
start = nl + 1;
}
}
void save(IStorage* storage) {
if (!storage || !storage->isAvailable()) return;
storage->makeDir("/unigeek");
String content;
for (auto& kv : _data) content += kv.first + "=" + kv.second + "\n";
storage->writeFile("/unigeek/config", content.c_str());
}
String get(const StringgetInstance method · c · L40-L44 (5 LOC)firmware/src/core/ConfigManager.h
public:
static ConfigManager& getInstance() {
static ConfigManager instance;
return instance;
}load method · c · L45-L61 (17 LOC)firmware/src/core/ConfigManager.h
void load(IStorage* storage) {
if (!storage || !storage->isAvailable()) return;
String content = storage->readFile("/unigeek/config");
if (content.length() == 0) return;
_data.clear();
int start = 0;
while (start < (int)content.length()) {
int nl = content.indexOf('\n', start);
if (nl < 0) nl = content.length();
String line = content.substring(start, nl);
line.trim();
int sep = line.indexOf('=');
if (sep > 0) _data[line.substring(0, sep)] = line.substring(sep + 1);
start = nl + 1;
}
}save method · c · L62-L69 (8 LOC)firmware/src/core/ConfigManager.h
void save(IStorage* storage) {
if (!storage || !storage->isAvailable()) return;
storage->makeDir("/unigeek");
String content;
for (auto& kv : _data) content += kv.first + "=" + kv.second + "\n";
storage->writeFile("/unigeek/config", content.c_str());
}get method · c · L70-L74 (5 LOC)firmware/src/core/ConfigManager.h
String get(const String& key, const String& def = "") const {
auto it = _data.find(key);
return it != _data.end() ? it->second : def;
}All rows above produced by Repobility · https://repobility.com
set method · c · L75-L78 (4 LOC)firmware/src/core/ConfigManager.h
void set(const String& key, const String& value) {
_data[key] = value;
}getThemeColor method · c · L79-L91 (13 LOC)firmware/src/core/ConfigManager.h
uint16_t getThemeColor() {
String c = get(APP_CONFIG_PRIMARY_COLOR, APP_CONFIG_PRIMARY_COLOR_DEFAULT);
if (c == "Blue") return TFT_BLUE;
if (c == "Red") return TFT_RED;
if (c == "Green") return TFT_DARKGREEN;
if (c == "Cyan") return TFT_DARKCYAN;
if (c == "Purple") return TFT_PURPLE;
if (c == "Brown") return TFT_BROWN;
if (c == "Orange") return TFT_ORANGE;
if (c == "Violet") return TFT_VIOLET;
return TFT_NAVY;
}Device class · c · L18-L88 (71 LOC)firmware/src/core/Device.h
class Device
{
public:
static Device& getInstance() {
static Device* instance = createInstance(); // ← pointer, no copy/default ctor needed
return *instance;
}
void begin()
{
Lcd.begin();
Lcd.setRotation(TFT_DEFAULT_ORIENTATION);
Lcd.invertDisplay(true);
Power.begin();
Nav->begin();
if (Keyboard) Keyboard->begin();
if (Speaker) Speaker->begin();
}
void update()
{
boardHook();
if (Keyboard) Keyboard->update();
Nav->update();
}
void boardHook(); // board-specific per-frame hook, defined in each Device.cpp
void switchNavigation(INavigation* newNav)
{
Nav = newNav;
Nav->begin();
}
virtual void applyNavMode(); // board override: switch nav based on APP_CONFIG_NAV_MODE
IDisplay& Lcd;
IPower& Power;
INavigation* Nav;
IStorage* Storage = nullptr; // primary — set by board
IStorage* StorageSD = nullptr; // direct SD access (nullable)
IStorage* StorageLFS = nullptr; // directgetInstance method · c · L21-L25 (5 LOC)firmware/src/core/Device.h
public:
static Device& getInstance() {
static Device* instance = createInstance(); // ← pointer, no copy/default ctor needed
return *instance;
}begin method · c · L26-L38 (13 LOC)firmware/src/core/Device.h
void begin()
{
Lcd.begin();
Lcd.setRotation(TFT_DEFAULT_ORIENTATION);
Lcd.invertDisplay(true);
Power.begin();
Nav->begin();
if (Keyboard) Keyboard->begin();
if (Speaker) Speaker->begin();
}update method · c · L39-L45 (7 LOC)firmware/src/core/Device.h
void update()
{
boardHook();
if (Keyboard) Keyboard->update();
Nav->update();
}switchNavigation method · c · L48-L53 (6 LOC)firmware/src/core/Device.h
void switchNavigation(INavigation* newNav)
{
Nav = newNav;
Nav->begin();
}IDisplay class · c · L8-L18 (11 LOC)firmware/src/core/IDisplay.h
class IDisplay : public TFT_eSPI
{
public:
// brightness percentage between 0 to 100
virtual void setBrightness(uint8_t brightness) = 0;
virtual void powerOff()
{
setBrightness(0);
}
};Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
powerOff method · c · L14-L17 (4 LOC)firmware/src/core/IDisplay.h
virtual void powerOff()
{
setBrightness(0);
}IKeyboard class · c · L7-L29 (23 LOC)firmware/src/core/IKeyboard.h
class IKeyboard
{
public:
enum Modifier : uint8_t {
MOD_NONE = 0,
MOD_SHIFT = 1 << 0,
MOD_FN = 1 << 1,
MOD_CAPS = 1 << 2,
MOD_CTRL = 1 << 3,
MOD_ALT = 1 << 4,
MOD_OPT = 1 << 5,
};
virtual ~IKeyboard() = default;
virtual void begin() = 0;
virtual void update() = 0;
virtual bool available() = 0;
virtual char peekKey() = 0; // read without consuming
virtual char getKey() = 0;
virtual uint8_t modifiers() { return MOD_NONE; }
virtual bool isKeyHeld() const { return false; } // true while the last consumed key is still physically held
};INavigation class · c · L7-L80 (74 LOC)firmware/src/core/INavigation.h
class INavigation
{
public:
enum Direction
{
DIR_NONE,
DIR_UP,
DIR_DOWN,
DIR_LEFT,
DIR_RIGHT,
DIR_PRESS,
DIR_BACK
};
virtual ~INavigation() = default;
virtual void update() = 0;
virtual void begin() = 0;
bool isPressed() const { return _pressed; }
bool wasPressed() {
if (_wasPressed) {
_wasPressed = false;
return true;
}
return false;
}
Direction readDirection() {
Direction dir = _releasedDirection;
_releasedDirection = DIR_NONE;
return dir;
}
uint32_t pressDuration() const { return _pressDuration; }
uint32_t heldDuration() const { return _pressed ? (millis() - _pressStart) : 0; }
void setSuppressKeys(bool s) { _suppressKeys = s; }
bool suppressKeys() const { return _suppressKeys; }
protected:
void updateState(Direction currentlyHeld) {
uint32_t now = millis();
if (currentlyHeld != DIR_NONE) {
if (!_pressed) {
_pressed = true;
_pressStart = now;