This commit is contained in:
Totoo
2026-02-24 11:23:41 +01:00
committed by GitHub
parent b09efb4d3c
commit e63f54c0a2
24 changed files with 96 additions and 63 deletions
+1 -1
View File
@@ -205,7 +205,7 @@ uint16_t I2cDev::read16_1(uint8_t reg) {
}
uint32_t I2cDev::read24_1(uint8_t reg) {
uint8_t buffer[3];
i2c_read(&reg, 1, buffer, 2);
i2c_read(&reg, 1, buffer, 3);
return uint32_t(buffer[0]) << 16 | uint32_t(buffer[1]) << 8 | uint32_t(buffer[2]);
}
+1 -1
View File
@@ -41,7 +41,7 @@ size_t morse_encode(std::string& message, const uint32_t time_unit_ms, const uin
i = 0;
for (char& ch : message) {
if (i > 256) return 0; // Message too long
if (i >= 256) return 0; // Message too long
if ((ch >= 'a') && (ch <= 'z')) // Make uppercase
ch -= 32;
+10 -8
View File
@@ -272,9 +272,8 @@ void View::add_child(Widget* const widget) {
}
void View::add_children(const std::initializer_list<Widget*> children) {
children_.insert(std::end(children_), children);
for (auto child : children) {
child->set_parent(this);
add_child(child);
}
}
@@ -622,8 +621,8 @@ ProgressBar::ProgressBar(
void ProgressBar::set_max(const uint32_t max) {
if (max == _max) return;
if (_value > _max)
_value = _max;
if (_value > max)
_value = max;
_max = max;
set_dirty();
@@ -651,9 +650,11 @@ void ProgressBar::paint(Painter& painter) {
const auto sr = screen_rect();
const auto s = style();
v_scaled = (sr.size().width() * (uint64_t)_value) / _max;
if (_max == 0) {
v_scaled = 0;
} else {
v_scaled = (sr.size().width() * (uint64_t)_value) / _max;
}
painter.fill_rectangle({sr.location(), {v_scaled, sr.size().height()}}, style().foreground);
painter.fill_rectangle({{sr.location().x() + v_scaled, sr.location().y()}, {sr.size().width() - v_scaled, sr.size().height()}}, s.background);
@@ -1267,7 +1268,7 @@ bool ButtonWithEncoder::on_encoder(const EncoderEvent delta) {
if (delta != 0) {
encoder_delta += delta;
delta_change = true;
on_change();
if (on_change) on_change();
} else
delta_change = 0;
return true;
@@ -1904,6 +1905,7 @@ void OptionsField::on_focus() {
}
bool OptionsField::on_encoder(const EncoderEvent delta) {
if (options_.empty()) return false;
int32_t new_value = selected_index() + delta;
if (new_value < 0)
new_value = options_.size() - 1;
+18 -2
View File
@@ -22,6 +22,7 @@
#include "utility.hpp"
#include <cstdint>
#include <string.h>
#if 0
uint32_t gcd(const uint32_t u, const uint32_t v) {
@@ -257,8 +258,23 @@ std::string join(char c, std::initializer_list<std::string_view> strings) {
}
uint32_t simple_checksum(uint32_t buffer_address, uint32_t length) {
if (buffer_address == 0 || length == 0) {
return 0;
}
uint32_t checksum = 0;
for (uint32_t i = 0; i < length; i += 4)
checksum += *(uint32_t*)(buffer_address + i);
const uint8_t* ptr = (const uint8_t*)(uintptr_t)buffer_address;
uint32_t i = 0;
for (; i + 3 < length; i += 4) {
uint32_t chunk;
// memcpy prevents unaligned access hard-faults on embedded processors
memcpy(&chunk, ptr + i, 4);
checksum += chunk;
}
// Leftover bytes (won't happen hopefully)
if (i < length) {
uint32_t remainder = 0;
memcpy(&remainder, ptr + i, length - i);
checksum += remainder;
}
return checksum;
}