* Refactor object creation logic. Remove unused LVGL features. * Remove unused files. Fix height for widgets. * Rename 'OpenTxTheme' class to 'EdgeTxTheme'. Cleanup commented out code. Cleanup unused code from 'etx_lv_theme.cpp'. * More cleanup. * Move more style code to etx_lv_theme.cpp * Update license * Make default button height match other controls. * Fix curve edit layout. * Fix layouts. * FormWindow and FormGroup provided identical functionality - rename FormGroup to FormWindow and remove duplicate. * Simplify menu icon handling. Remove unused 'flysky.cpp' file. * Fix window size change. * Simplify page header code. Fix statistics view page. * Remove unused file. Replace redundant 'Subtitle' class with a macro. Fix compiler warnings. * Fix compiler warning in LvglWrapper.cpp. Remove unused code in static.h. Simplify about page. * Rename ICON_OPENTX to ICON_EDGETX. * Fix github build error. * Fix github build error (attempt 2). * Move ButtonMatrix styling to etx_lv_theme.cpp. * Scroll bar consistency. * Use styles for ButtonMatrix text color. * Use 'active' color for selected USB advanced setup buttons. Move error message to bottom of page. * Create style for popup window title bar. Simplify advanced USB setup code. Remove unused libopenui/carousel.* files. * Add style for modal popup content. * Remove unused BUTTON_BACKGROUND flag. * Replace GridLayout with FormWindow. Remove unused gridlayout.h file. * Fix rebase. * Merge ChoiceEx class into Choice class code. Remove unused CurveKeyboard. * Use LVGL bar for progress indicator. Update only style colors when theme changes (don't recreate all style settings). * Move ProgressDialog class to dlalog.h/dialog.cpp files. * Simplify trim and slider code in main view. Simplify the hardware inputs code. Fix dialog size. Remove unused code in layout factory. * Cleanup unused code. * Add style for FormWindow class. Merge BaseNumberEdit class into NumberEdit class and remove BaseNumberEdit. Remove more unused files. Cleanup libopenui_config.h files. * Re-organise libopenui include files to fix build error. * Fix build error. * Add missed styles to etx_lv_theme.cpp. Delete commented out #includes. More cleaning up of libopenui_xxx.h files and dependencies. Re-enable LVGL CHECKBOX feature. * Merge libopenui_helpers.h into opentx_helpers.h file. * Fix firmware build. * Use object constructors for LVGL object creation as suggested by gagarinlg. Add style for number edit text alignment. Fix background color for focussed control. * Move color related stuff from libopenui_defines.h to colors.h. Remove need for libopenui_depends.h file. * Merge libopenui_types.h content into opentx_types.h file. * Rename CheckBox class to ToggleSwitch. * Restore code to update flight mode text color when theme changes. * Cleanup some more unused code. * Remove redundant theme.h file. * Fix rebase. * Fix button matrix style. * Fix rebase * Fix rebase * Ensure correct initialisation of Choice object. * Fix rebase. * Make the slider control bigger to make touch activation easier. * Fix build error. * Fix slider logic and cleanup code. * Use ACTIVE theme color for inputs, mixes, LS, GV and SF. * Improved border width consistency and focussed state consistency. * Remove duplicate copy of the default theme colors.
124 lines
2.4 KiB
C++
124 lines
2.4 KiB
C++
/*
|
|
* Copyright (C) EdgeTX
|
|
*
|
|
* Based on code named
|
|
* opentx - https://github.com/opentx/opentx
|
|
* th9x - http://code.google.com/p/th9x
|
|
* er9x - http://code.google.com/p/er9x
|
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
|
*
|
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <cstring>
|
|
|
|
template<class T>
|
|
inline T sgn(T a)
|
|
{
|
|
return a > 0 ? 1 : (a < 0 ? -1 : 0);
|
|
}
|
|
|
|
template<class T>
|
|
inline T min(T a, T b)
|
|
{
|
|
return a < b ? a : b;
|
|
}
|
|
|
|
template<class T>
|
|
inline T max(T a, T b)
|
|
{
|
|
return a > b ? a : b;
|
|
}
|
|
|
|
template<class T>
|
|
inline T limit(T vmin, T x, T vmax)
|
|
{
|
|
return min(max(vmin, x), vmax);
|
|
}
|
|
|
|
inline int divRoundClosest(int n, int d)
|
|
{
|
|
if (d == 0)
|
|
return 0;
|
|
else
|
|
return ((n < 0) ^ (d < 0)) ? ((n - d/2)/d) : ((n + d/2)/d);
|
|
}
|
|
|
|
inline unsigned align32(unsigned n)
|
|
{
|
|
unsigned rest = (n & 3u);
|
|
return rest ? n + 4u - rest : n;
|
|
}
|
|
|
|
inline std::string TEXT_AT_INDEX(const char *const *val, uint8_t idx)
|
|
{
|
|
return std::string(val[idx]);
|
|
}
|
|
|
|
template<class T>
|
|
inline void SWAP(T & a, T & b)
|
|
{
|
|
T tmp = b;
|
|
b = a;
|
|
a = tmp;
|
|
}
|
|
|
|
inline void memclear(void * p, size_t size)
|
|
{
|
|
memset(p, 0, size);
|
|
}
|
|
|
|
inline bool is_memclear(void * p, size_t size)
|
|
{
|
|
uint8_t * buf = (uint8_t *)p;
|
|
return buf[0] == 0 && memcmp(buf, buf + 1, size - 1) == 0;
|
|
}
|
|
|
|
// Circular buffer to send data between two threads
|
|
template<class T, uint8_t N>
|
|
class CircularBuffer {
|
|
protected:
|
|
volatile T buffer[N] = {0};
|
|
uint8_t readPos = 0;
|
|
uint8_t writePos = 0;
|
|
|
|
public:
|
|
void clear()
|
|
{
|
|
memclear(this, sizeof(*this));
|
|
}
|
|
|
|
T read()
|
|
{
|
|
T value = buffer[readPos];
|
|
if (value) {
|
|
buffer[readPos] = 0;
|
|
readPos = (readPos + 1) % N;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
// Values must be non-zero
|
|
bool write(T value)
|
|
{
|
|
if (value && !buffer[writePos]) {
|
|
buffer[writePos] = value;
|
|
writePos = (writePos + 1) % N;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
};
|