Compare commits
4 Commits
a3265543a5
...
80caf298db
Author | SHA1 | Date | |
---|---|---|---|
80caf298db | |||
1bbac4537d | |||
9466290ff3 | |||
58dd4ae8d3 |
@ -8,7 +8,7 @@
|
||||
#include <mvp/View.hpp>
|
||||
#include <gui/debugview_screen/DebugViewPresenter.hpp>
|
||||
#include <touchgfx/widgets/Box.hpp>
|
||||
#include <touchgfx/containers/scrollers/ScrollList.hpp>
|
||||
#include <touchgfx/containers/scrollers/ScrollWheel.hpp>
|
||||
#include <gui/containers/DebugViewLine.hpp>
|
||||
#include <touchgfx/widgets/canvas/Line.hpp>
|
||||
#include <touchgfx/widgets/canvas/PainterRGB565.hpp>
|
||||
@ -24,6 +24,19 @@ public:
|
||||
{
|
||||
// Override and implement this function in DebugView
|
||||
}
|
||||
virtual void handleKeyEvent(uint8_t key);
|
||||
|
||||
/*
|
||||
* Virtual Action Handlers
|
||||
*/
|
||||
virtual void scrollUp()
|
||||
{
|
||||
// Override and implement this function in DebugView
|
||||
}
|
||||
virtual void scrollDown()
|
||||
{
|
||||
// Override and implement this function in DebugView
|
||||
}
|
||||
|
||||
protected:
|
||||
FrontendApplication& application() {
|
||||
@ -34,7 +47,7 @@ protected:
|
||||
* Member Declarations
|
||||
*/
|
||||
touchgfx::Box __background;
|
||||
touchgfx::ScrollList list;
|
||||
touchgfx::ScrollWheel list;
|
||||
touchgfx::DrawableListItems<DebugViewLine, 13> listListItems;
|
||||
touchgfx::Line line1;
|
||||
touchgfx::PainterRGB565 line1Painter;
|
||||
|
@ -17,14 +17,14 @@ DebugViewViewBase::DebugViewViewBase() :
|
||||
list.setPosition(15, 15, 450, 290);
|
||||
list.setHorizontal(false);
|
||||
list.setCircular(true);
|
||||
list.setEasingEquation(touchgfx::EasingEquations::backEaseOut);
|
||||
list.setEasingEquation(touchgfx::EasingEquations::linearEaseOut);
|
||||
list.setSwipeAcceleration(10);
|
||||
list.setDragAcceleration(10);
|
||||
list.setNumberOfItems(1);
|
||||
list.setPadding(0, 0);
|
||||
list.setSnapping(false);
|
||||
list.setSelectedItemOffset(0);
|
||||
list.setDrawableSize(26, 0);
|
||||
list.setDrawables(listListItems, updateItemCallback);
|
||||
list.animateToItem(0, 0);
|
||||
add(list);
|
||||
|
||||
line1.setPosition(15, 15, 1, 290);
|
||||
@ -69,6 +69,27 @@ void DebugViewViewBase::setupScreen()
|
||||
}
|
||||
}
|
||||
|
||||
void DebugViewViewBase::handleKeyEvent(uint8_t key)
|
||||
{
|
||||
if(104 == key)
|
||||
{
|
||||
//ScrollUp
|
||||
//When hardware button 104 clicked call virtual function
|
||||
//Call scrollUp
|
||||
scrollUp();
|
||||
|
||||
}
|
||||
|
||||
if(108 == key)
|
||||
{
|
||||
//ScrollDown
|
||||
//When hardware button 108 clicked call virtual function
|
||||
//Call scrollDown
|
||||
scrollDown();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DebugViewViewBase::updateItemCallbackHandler(touchgfx::DrawableListItemsInterface* items, int16_t containerIndex, int16_t itemIndex)
|
||||
{
|
||||
if (items == &listListItems)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef NAMEDFIELD_HPP
|
||||
#define NAMEDFIELD_HPP
|
||||
|
||||
#include "params.h"
|
||||
#include "touchgfx/TypedText.hpp"
|
||||
#include "touchgfx/Unicode.hpp"
|
||||
#include <stddef.h>
|
||||
@ -29,6 +30,13 @@ struct NamedFieldDescription {
|
||||
extern NamedFieldDescription dataFieldDescs[];
|
||||
extern NamedFieldDescription paramFieldDescs[];
|
||||
|
||||
extern DataFieldType dataFieldByAlphaIndex[];
|
||||
extern size_t dataFieldAlphaIndexByField[];
|
||||
extern ParamType paramByAlphaIndex[];
|
||||
extern size_t paramAlphaIndexByParam[];
|
||||
|
||||
void namedFieldSort();
|
||||
|
||||
template <class T> class NamedField {
|
||||
public:
|
||||
NamedField(const NamedFieldDescription *fieldDescs);
|
||||
|
@ -13,9 +13,16 @@ public:
|
||||
|
||||
virtual void listUpdateItem(DebugViewLine &line, int16_t itemIndex) override;
|
||||
|
||||
void scrollUp() override;
|
||||
void scrollDown() override;
|
||||
|
||||
void updateFieldValues();
|
||||
|
||||
protected:
|
||||
private:
|
||||
void updateScrollIndex(size_t index);
|
||||
|
||||
size_t scrollIndex;
|
||||
};
|
||||
|
||||
#endif // DEBUGVIEWVIEW_HPP
|
||||
|
@ -46,10 +46,11 @@ private:
|
||||
DriverViewField &getField(size_t i);
|
||||
|
||||
void updateSelectedField(size_t select);
|
||||
void updateSelectedFieldType(size_t select, bool animate = true);
|
||||
void updateSelectedFieldIndex(size_t index, bool animate = true);
|
||||
void updateSelectedFieldType(DataFieldType type, bool animate = true);
|
||||
|
||||
size_t selectedField;
|
||||
size_t selectedFieldType;
|
||||
size_t selectedFieldIndex;
|
||||
DataFieldType fieldTypes[NUM_FIELDS];
|
||||
|
||||
touchgfx::Unicode::UnicodeChar r2dProgBuffer[16];
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include <gui/common/FrontendApplication.hpp>
|
||||
|
||||
FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
|
||||
: FrontendApplicationBase(m, heap)
|
||||
{
|
||||
#include "gui/common/NamedField.hpp"
|
||||
|
||||
FrontendApplication::FrontendApplication(Model &m, FrontendHeap &heap)
|
||||
: FrontendApplicationBase(m, heap) {
|
||||
namedFieldSort();
|
||||
}
|
||||
|
@ -6,6 +6,9 @@
|
||||
#include "params.h"
|
||||
#include "vehicle_state.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#define VEH_FIELD(FIELD) []() { return (void *)&vehicle_state.FIELD; }
|
||||
#define VEH_BIT_FIELD(FIELD) \
|
||||
[]() { \
|
||||
@ -300,6 +303,42 @@ static_assert(sizeof(paramFieldDescs) / sizeof(paramFieldDescs[0]) ==
|
||||
ParamType_COUNT,
|
||||
"Incorrect number of param field descriptions");
|
||||
|
||||
DataFieldType dataFieldByAlphaIndex[DataFieldType_COUNT];
|
||||
size_t dataFieldAlphaIndexByField[DataFieldType_COUNT];
|
||||
ParamType paramByAlphaIndex[ParamType_COUNT];
|
||||
size_t paramAlphaIndexByParam[ParamType_COUNT];
|
||||
|
||||
template <class T> struct NFAlphabeticComp {
|
||||
NFAlphabeticComp(const NamedFieldDescription *fieldDescs)
|
||||
: fieldDescs{fieldDescs} {}
|
||||
|
||||
const NamedFieldDescription *fieldDescs;
|
||||
|
||||
bool operator()(const T &a, const T &b) const {
|
||||
return strcmp(fieldDescs[a].title, fieldDescs[b].title) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void namedFieldSort(const NamedFieldDescription *fieldDescs, T *fieldByAlpha,
|
||||
size_t *alphaIndexByField, size_t numFields) {
|
||||
for (size_t i = 0; i < numFields; i++) {
|
||||
fieldByAlpha[i] = static_cast<T>(i);
|
||||
}
|
||||
std::sort(fieldByAlpha, fieldByAlpha + numFields,
|
||||
NFAlphabeticComp<T>(fieldDescs));
|
||||
for (size_t i = 0; i < numFields; i++) {
|
||||
alphaIndexByField[fieldByAlpha[i]] = i;
|
||||
}
|
||||
}
|
||||
|
||||
void namedFieldSort() {
|
||||
namedFieldSort(dataFieldDescs, dataFieldByAlphaIndex,
|
||||
dataFieldAlphaIndexByField, DataFieldType_COUNT);
|
||||
namedFieldSort(paramFieldDescs, paramByAlphaIndex, paramAlphaIndexByParam,
|
||||
ParamType_COUNT);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
NamedField<T>::NamedField(const NamedFieldDescription *fieldDescs)
|
||||
: fieldDescs{fieldDescs} {}
|
||||
|
@ -16,10 +16,10 @@ void DebugViewView::tearDownScreen() { DebugViewViewBase::tearDownScreen(); }
|
||||
|
||||
void DebugViewView::listUpdateItem(DebugViewLine &line, int16_t itemIndex) {
|
||||
size_t idx = itemIndex * 2;
|
||||
line.setFieldType(0, static_cast<DataFieldType>(idx));
|
||||
line.setFieldType(0, dataFieldByAlphaIndex[idx]);
|
||||
idx++;
|
||||
if (idx < DataFieldType_COUNT) {
|
||||
line.setFieldType(1, static_cast<DataFieldType>(idx));
|
||||
line.setFieldType(1, dataFieldByAlphaIndex[idx]);
|
||||
line.setFieldVisible(1, true);
|
||||
} else {
|
||||
line.setFieldVisible(1, false);
|
||||
@ -32,3 +32,26 @@ void DebugViewView::updateFieldValues() {
|
||||
el.updateFieldValues();
|
||||
}
|
||||
}
|
||||
|
||||
void DebugViewView::scrollUp() {
|
||||
if (scrollIndex == 0) {
|
||||
updateScrollIndex(list.getNumberOfItems() - 1);
|
||||
} else {
|
||||
updateScrollIndex(scrollIndex - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugViewView::scrollDown() {
|
||||
updateScrollIndex((scrollIndex + 1) % list.getNumberOfItems());
|
||||
}
|
||||
|
||||
void DebugViewView::updateScrollIndex(size_t index) {
|
||||
scrollIndex = index;
|
||||
if (scrollIndex == 0) {
|
||||
// Just animating to 0 looks very broken when scrolling forwards. Animating
|
||||
// to numItems looks good in both directions.
|
||||
list.animateToItem(list.getNumberOfItems(), 2);
|
||||
} else {
|
||||
list.animateToItem(scrollIndex, 2);
|
||||
}
|
||||
}
|
||||
|
@ -58,8 +58,9 @@ void DriverViewView::tearDownScreen() { DriverViewViewBase::tearDownScreen(); }
|
||||
|
||||
void DriverViewView::fieldTypeSelectionUpdateItem(
|
||||
DriverViewFieldSelection &item, int16_t itemIndex) {
|
||||
item.setName(dataFieldDescs[itemIndex].title);
|
||||
item.setSelected(itemIndex == (int)selectedFieldType);
|
||||
DataFieldType fieldType = dataFieldByAlphaIndex[itemIndex];
|
||||
item.setName(dataFieldDescs[fieldType].title);
|
||||
item.setSelected(itemIndex == (int)selectedFieldIndex);
|
||||
}
|
||||
|
||||
void DriverViewView::setFieldType(size_t i, DataFieldType type) {
|
||||
@ -186,7 +187,7 @@ void DriverViewView::selectNextFieldType() {
|
||||
return;
|
||||
}
|
||||
|
||||
updateSelectedFieldType((selectedFieldType + 1) % DataFieldType_COUNT);
|
||||
updateSelectedFieldIndex((selectedFieldIndex + 1) % DataFieldType_COUNT);
|
||||
}
|
||||
|
||||
void DriverViewView::selectPrevFieldType() {
|
||||
@ -194,10 +195,10 @@ void DriverViewView::selectPrevFieldType() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedFieldType == 0) {
|
||||
updateSelectedFieldType(DataFieldType_COUNT - 1);
|
||||
if (selectedFieldIndex == 0) {
|
||||
updateSelectedFieldIndex(DataFieldType_COUNT - 1);
|
||||
} else {
|
||||
updateSelectedFieldType(selectedFieldType - 1);
|
||||
updateSelectedFieldIndex(selectedFieldIndex - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,11 +207,11 @@ void DriverViewView::confirmFieldType() {
|
||||
return;
|
||||
}
|
||||
|
||||
DataFieldType fieldType = dataFieldByAlphaIndex[selectedFieldIndex];
|
||||
DriverViewField &field = getField(selectedField);
|
||||
presenter->setFieldType(selectedField,
|
||||
static_cast<DataFieldType>(selectedFieldType));
|
||||
presenter->setFieldType(selectedField, fieldType);
|
||||
field.setSelected(false);
|
||||
fieldTypes[selectedField] = static_cast<DataFieldType>(selectedFieldType);
|
||||
fieldTypes[selectedField] = fieldType;
|
||||
fieldTypeSelection.setVisible(false);
|
||||
fieldTypeSelection.invalidate();
|
||||
}
|
||||
@ -237,19 +238,23 @@ void DriverViewView::updateSelectedField(size_t selected) {
|
||||
updateSelectedFieldType(fieldTypes[selectedField], false);
|
||||
}
|
||||
|
||||
void DriverViewView::updateSelectedFieldType(size_t selected, bool animate) {
|
||||
size_t previousSelected = selectedFieldType;
|
||||
selectedFieldType = selected;
|
||||
void DriverViewView::updateSelectedFieldType(DataFieldType type, bool animate) {
|
||||
updateSelectedFieldIndex(dataFieldAlphaIndexByField[type], animate);
|
||||
}
|
||||
|
||||
void DriverViewView::updateSelectedFieldIndex(size_t selected, bool animate) {
|
||||
size_t previousSelected = selectedFieldIndex;
|
||||
selectedFieldIndex = selected;
|
||||
// Trigger update of the background
|
||||
fieldTypeSelection.itemChanged(previousSelected);
|
||||
fieldTypeSelection.itemChanged(selectedFieldType);
|
||||
fieldTypeSelection.itemChanged(selectedFieldIndex);
|
||||
|
||||
int16_t steps = animate ? 2 : 0;
|
||||
if (selectedFieldType == 0) {
|
||||
if (selectedFieldIndex == 0) {
|
||||
// Just animating to 0 looks very broken when scrolling forwards. Animating
|
||||
// to DataFieldType_COUNT looks good in both directions.
|
||||
fieldTypeSelection.animateToItem(DataFieldType_COUNT, steps);
|
||||
} else {
|
||||
fieldTypeSelection.animateToItem(selectedFieldType, steps);
|
||||
fieldTypeSelection.animateToItem(selectedFieldIndex, steps);
|
||||
}
|
||||
}
|
||||
|
@ -854,7 +854,7 @@
|
||||
"CanvasBufferSize": 7200,
|
||||
"Components": [
|
||||
{
|
||||
"Type": "ScrollList",
|
||||
"Type": "ScrollWheel",
|
||||
"Name": "list",
|
||||
"X": 15,
|
||||
"Y": 15,
|
||||
@ -863,7 +863,7 @@
|
||||
"IsCircular": true,
|
||||
"ItemTemplateName": "DebugViewLine",
|
||||
"NumberofItems": 1,
|
||||
"Easing": "Back",
|
||||
"Easing": "Linear",
|
||||
"EasingOption": "Out",
|
||||
"SwipeAcceleration": 1.0,
|
||||
"DragAcceleration": 1.0
|
||||
@ -917,7 +917,30 @@
|
||||
"LineEndingStyle": "Round"
|
||||
}
|
||||
],
|
||||
"Interactions": []
|
||||
"Interactions": [
|
||||
{
|
||||
"InteractionName": "ScrollUp",
|
||||
"Trigger": {
|
||||
"Type": "TriggerPhysicalButtonClicked",
|
||||
"ButtonKey": 104
|
||||
},
|
||||
"Action": {
|
||||
"Type": "ActionCustom",
|
||||
"FunctionName": "scrollUp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"InteractionName": "ScrollDown",
|
||||
"Trigger": {
|
||||
"Type": "TriggerPhysicalButtonClicked",
|
||||
"ButtonKey": 108
|
||||
},
|
||||
"Action": {
|
||||
"Type": "ActionCustom",
|
||||
"FunctionName": "scrollDown"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "VehicleConfig",
|
||||
|
Loading…
x
Reference in New Issue
Block a user