mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 11:38:12 +00:00
SymField rewrite (#1444)
* First WIP symfield * Cleanup widget code * Rebase and format * Fix 'to_integer' bug, fix siggen UI. * to_string_hex fix, unit tests for string code * Pass instance in callback * Fix on_change callbacks * Fix keyfob (not active) * to_byte_array, coaster tx cleanup * Add to_byte_array tests * Changes in ui_numbers * Fix ui_encoders * Format * Fix modemsetup view's symfields * Remove header * Format
This commit is contained in:
@@ -22,12 +22,13 @@
|
||||
#ifndef __UTILITY_H__
|
||||
#define __UTILITY_H__
|
||||
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <complex>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <complex>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#define LOCATE_IN_RAM __attribute__((section(".ramtext")))
|
||||
|
||||
@@ -141,6 +142,16 @@ constexpr std::enable_if_t<is_flags_type_v<TEnum>, bool> flags_enabled(TEnum val
|
||||
return (i_value & i_flags) == i_flags;
|
||||
}
|
||||
|
||||
// TODO: Constrain to integrals?
|
||||
/* Converts an integer into a byte array. */
|
||||
template <typename T, size_t N = sizeof(T)>
|
||||
constexpr std::array<uint8_t, N> to_byte_array(T value) {
|
||||
std::array<uint8_t, N> bytes{};
|
||||
for (size_t i = 0; i < N; ++i)
|
||||
bytes[i] = (value >> ((N - i - 1) * 8)) & 0xFF;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/* Returns value constrained to min and max. */
|
||||
template <class T>
|
||||
constexpr const T& clip(const T& value, const T& minimum, const T& maximum) {
|
||||
|
Reference in New Issue
Block a user