Skip to content

Commit

Permalink
encoder step
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jan 30, 2020
1 parent 1fa920b commit 7381d80
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 25 deletions.
13 changes: 11 additions & 2 deletions modular-psu-firmware.eez-project
Original file line number Diff line number Diff line change
Expand Up @@ -8585,13 +8585,22 @@
{
"type": "ButtonGroup",
"style": {
"inheritFrom": "default_S"
"inheritFrom": "default_S",
"color": "Action color",
"activeBackgroundColor": "Action color"
},
"data": "edit_steps",
"left": 0,
"top": 32,
"width": 54,
"height": 208
"height": 208,
"selectedStyle": {
"inheritFrom": "default_S",
"color": "Background",
"backgroundColor": "text_regular",
"activeColor": "text_regular",
"activeBackgroundColor": "Background"
}
},
{
"type": "Select",
Expand Down
10 changes: 8 additions & 2 deletions src/eez/gui/action_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,14 @@ void action_user_switch_clicked() {
if (getActivePageId() == PAGE_ID_EDIT_MODE_STEP) {
psu::gui::edit_mode_step::switchToNextStepIndex();
} else {
mcu::encoder::switchEncoderMode();
psu::gui::edit_mode_step::showCurrentEncoderMode();
if (g_appContext->getActivePageId() == INTERNAL_PAGE_ID_TOAST_MESSAGE && !((ToastMessagePage *)g_appContext->getActivePage())->hasAction()) {
popPage();
}

if (psu::gui::isEncoderEnabledInActivePage()) {
mcu::encoder::switchEncoderMode();
psu::gui::edit_mode_step::showCurrentEncoderMode();
}
}
#endif
break;
Expand Down
2 changes: 1 addition & 1 deletion src/eez/gui/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ ToastMessagePage *ToastMessagePage::create(ToastType type, const char *message,
}

void ToastMessagePage::onEncoder(int counter) {
if (counter < 0) {
if (counter < 0 || !hasAction()) {
popPage();
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/eez/gui/widgets/button_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ using namespace eez::mcu;
namespace eez {
namespace gui {

void drawButtons(const Widget *widget, int x, int y, const Style *style, int selectedButton,
const data::Value *labels, int count) {
void drawButtons(const Widget *widget, int x, int y, const Style *style, const Style *selectedStyle, int selectedButton, const data::Value *labels, int count) {
if (widget->w > widget->h) {
// horizontal orientation
display::setColor(style->background_color);
Expand All @@ -42,7 +41,7 @@ void drawButtons(const Widget *widget, int x, int y, const Style *style, int sel
for (int i = 0; i < count; ++i) {
char text[32];
labels[i].toText(text, 32);
drawText(text, -1, x, y, w, h, style, i == selectedButton, false, false, nullptr, nullptr, nullptr, nullptr);
drawText(text, -1, x, y, w, h, i == selectedButton ? selectedStyle : style, false, false, false, nullptr, nullptr, nullptr, nullptr);
x += w;
}
} else {
Expand Down Expand Up @@ -71,7 +70,7 @@ void drawButtons(const Widget *widget, int x, int y, const Style *style, int sel

char text[32];
labels[i].toText(text, 32);
drawText(text, -1, x, y + yOffset, w, labelHeight, style, i == selectedButton, false, false, nullptr, nullptr, nullptr, nullptr);
drawText(text, -1, x, y + yOffset, w, labelHeight, i == selectedButton ? selectedStyle: style, false, false, false, nullptr, nullptr, nullptr, nullptr);

int b = y + yOffset + labelHeight;

Expand All @@ -92,6 +91,7 @@ void drawButtons(const Widget *widget, int x, int y, const Style *style, int sel

void ButtonGroupWidget_draw(const WidgetCursor &widgetCursor) {
const Widget *widget = widgetCursor.widget;
const ButtonGroupWidget *buttonGroupWidget = GET_WIDGET_PROPERTY(widget, specific, const ButtonGroupWidget *);

widgetCursor.currentState->size = sizeof(ButtonGroupWidgetState);
widgetCursor.currentState->data = data::get(widgetCursor.cursor, widget->data);
Expand All @@ -111,7 +111,8 @@ void ButtonGroupWidget_draw(const WidgetCursor &widgetCursor) {

if (refresh) {
const Style* style = getStyle(widget->style);
drawButtons(widget, widgetCursor.x, widgetCursor.y, style,
const Style* selectedStyle = getStyle(buttonGroupWidget->selectedStyle);
drawButtons(widget, widgetCursor.x, widgetCursor.y, style, selectedStyle,
widgetCursor.currentState->data.getInt(), labels, count);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/eez/gui/widgets/button_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
namespace eez {
namespace gui {

struct ButtonGroupWidget {
uint16_t selectedStyle;
};

struct ButtonGroupWidgetState {
WidgetState genericState;
const data::Value *labels;
Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/mcu/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void write(int counter, bool clicked) {
#endif

void switchEncoderMode() {
if (g_encoderMode == ENCODER_MODE_STEP5) {
if (g_encoderMode == ENCODER_MODE_STEP4) {
g_encoderMode = ENCODER_MODE_AUTO;
} else {
g_encoderMode = EncoderMode(g_encoderMode + 1);
Expand Down
3 changes: 1 addition & 2 deletions src/eez/modules/mcu/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ enum EncoderMode {
ENCODER_MODE_STEP1,
ENCODER_MODE_STEP2,
ENCODER_MODE_STEP3,
ENCODER_MODE_STEP4,
ENCODER_MODE_STEP5
ENCODER_MODE_STEP4
};

extern EncoderMode g_encoderMode;
Expand Down
29 changes: 19 additions & 10 deletions src/eez/modules/psu/gui/edit_mode_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,56 +44,56 @@ namespace edit_mode_step {

using data::Value;

#define NUM_UNITS 6
#define NUM_UNITS 7

static const Value CONF_GUI_UNIT_STEPS_LIST[NUM_UNITS][NUM_STEPS_PER_UNIT] = {
{
Value(5.0f, UNIT_VOLT),
Value(2.0f, UNIT_VOLT),
Value(1.0f, UNIT_VOLT),
Value(0.5f, UNIT_VOLT),
Value(0.1f, UNIT_VOLT)
},
{
Value(0.5f, UNIT_AMPER),
Value(0.25f, UNIT_AMPER),
Value(0.1f, UNIT_AMPER),
Value(0.05f, UNIT_AMPER),
Value(0.01f, UNIT_AMPER)
},
{
Value(0.005f, UNIT_AMPER),
Value(0.0025f, UNIT_AMPER),
Value(0.001f, UNIT_AMPER),
Value(0.0005f, UNIT_AMPER),
Value(0.0001f, UNIT_AMPER)
},
{
Value(10.0f, UNIT_WATT),
Value(5.0f, UNIT_WATT),
Value(2.0f, UNIT_WATT),
Value(1.0f, UNIT_WATT),
Value(0.5f, UNIT_WATT)
},
{
Value(20.0f, UNIT_CELSIUS),
Value(10.0f, UNIT_CELSIUS),
Value(5.0f, UNIT_CELSIUS),
Value(2.0f, UNIT_CELSIUS),
Value(1.0f, UNIT_CELSIUS)
},
{
Value(30.0f, UNIT_SECOND),
Value(20.0f, UNIT_SECOND),
Value(10.0f, UNIT_SECOND),
Value(5.0f, UNIT_SECOND),
Value(1.0f, UNIT_SECOND)
},
{
Value(0.2f, UNIT_AMPER),
Value(0.1f, UNIT_AMPER),
Value(0.04f, UNIT_AMPER),
Value(0.02f, UNIT_AMPER)
}
};

static int g_stepIndexes[NUM_UNITS][CH_MAX];

static const int DEFAULT_INDEX = 2;
static const int DEFAULT_INDEX = 1;

static bool g_changed;
static int g_startPos;
Expand All @@ -104,9 +104,18 @@ int getUnitStepValuesIndex(Unit unit) {
}

if (unit == UNIT_AMPER) {
if (Channel::get(g_focusCursor.i).flags.currentRangeSelectionMode == CURRENT_RANGE_SELECTION_ALWAYS_LOW) {
Channel &channel = Channel::get(g_focusCursor.i);
if (channel.flags.currentRangeSelectionMode == CURRENT_RANGE_SELECTION_ALWAYS_LOW) {
return 2;
}

// DCM220
int slotIndex = Channel::get(channel.channelIndex).slotIndex;
auto &slot = g_slots[slotIndex];
if (slot.moduleInfo->moduleType == MODULE_TYPE_DCM220) {
return 6;
}

return 1;
}

Expand Down Expand Up @@ -228,7 +237,7 @@ Value getCurrentEncoderStepValue() {
if (!data::getEncoderStepValues(g_focusCursor, g_focusDataId, stepValues)) {
getUnitStepValues(getCurrentEncoderUnit(), stepValues);
}
int stepValueIndex = mcu::encoder::ENCODER_MODE_STEP5 - mcu::encoder::g_encoderMode;
int stepValueIndex = mcu::encoder::ENCODER_MODE_STEP4 - mcu::encoder::g_encoderMode;
if (stepValueIndex >= stepValues.count) {
stepValueIndex = stepValues.count - 1;
}
Expand Down
3 changes: 1 addition & 2 deletions src/eez/modules/psu/gui/edit_mode_step.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#pragma once

#define NUM_STEPS_PER_UNIT 5
#define NUM_STEPS_PER_UNIT 4

namespace eez {
namespace psu {
Expand All @@ -28,7 +28,6 @@ namespace edit_mode_step {
int getStepIndex();

void getStepValues(eez::gui::data::StepValues &stepValues);
void getUnitStepValues(Unit unit, eez::gui::data::StepValues &stepValues);

void setStepIndex(int value);

Expand Down
2 changes: 2 additions & 0 deletions src/eez/modules/psu/gui/psu.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Unit getCurrentEncoderUnit();

float encoderIncrement(data::Value value, int counter, float min, float max, int channelIndex, float precision = 1.0f);

bool isEncoderEnabledInActivePage();

class PsuAppContext : public AppContext {
public:
PsuAppContext();
Expand Down

0 comments on commit 7381d80

Please sign in to comment.