Skip to content

Commit

Permalink
Add direction parameter for slide switches. Set Befaco 7-pos vert switch
Browse files Browse the repository at this point in the history
  • Loading branch information
danngreen committed Nov 11, 2023
1 parent cfc54a5 commit c3c6881
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions firmware/src/VCV_adaptor/widget_convert/Befaco.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace MetaModule

template<>
inline Element make_element<::CKSSVert7>(BaseElement b) {
return SlideSwitch{{b}, 7, "SwitchTallVert.png", "SwitchTallVertHandle.png"};
return SlideSwitch{{b}, 7, "SwitchTallVert.png", "SwitchTallVertHandle.png", SlideSwitch::Ascend::UpLeft};
}

template<>
Expand All @@ -65,7 +65,7 @@ inline Element make_element<::CKSSNarrow3>(BaseElement b) {

template<>
inline Element make_element<::CKSSThreeDragable>(BaseElement b) {
return SlideSwitch{{b}, 3, "CKSSThree_bg.png", "CKSSThree_fg.png"};
return SlideSwitch{{b}, 3, "CKSSThree_bg.png", "CKSSThree_fg.png", SlideSwitch::Ascend::UpLeft};
}

template<>
Expand Down
16 changes: 11 additions & 5 deletions firmware/src/gui/elements/redraw.hh
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,28 @@ inline bool redraw_element(const SlideSwitch &element, const GuiElement &gui_el,
auto width = lv_obj_get_width(gui_el.obj);
bool vert = height > width;
auto major_dim = vert ? height : width;
auto handle_major_dim = major_dim / element.num_pos;
lv_coord_t major_range = major_dim - handle_major_dim;

lv_obj_refr_size(handle);
lv_obj_refr_pos(handle);
int32_t cur_pos = vert ? lv_obj_get_y(handle) : lv_obj_get_x(handle);

auto handle_major_dim = major_dim / element.num_pos;
lv_coord_t major_range = major_dim - handle_major_dim;
if (element.direction == SlideSwitch::Ascend::UpLeft)
cur_pos = major_range - cur_pos;

// cur_pos ranges from 0 to major_range
auto cur_state = StateConversion::convertState(element, (float)cur_pos / (float)major_range) - 1;
auto state = StateConversion::convertState(element, val) - 1; //0..N-1 0..6
auto new_state = StateConversion::convertState(element, val) - 1; //0..N-1 0..6

bool did_update_position = false;

if (state != cur_state) {
lv_coord_t new_pos = ((float)state / (float)(element.num_pos - 1)) * major_range;
if (new_state != cur_state) {
lv_coord_t new_pos = ((float)new_state / (float)(element.num_pos - 1)) * major_range;

if (element.direction == SlideSwitch::Ascend::UpLeft)
new_pos = major_range - new_pos;

if (vert)
lv_obj_set_y(handle, new_pos);
else
Expand Down
3 changes: 1 addition & 2 deletions firmware/src/gui/pages/manual_control_popup.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "elements/elements.hh"
#include "CoreModules/elements/elements.hh"
#include "gui/elements/context.hh"
#include "gui/elements/state_names.hh"
#include "gui/helpers/lv_helpers.hh"
Expand Down Expand Up @@ -161,7 +161,6 @@ private:
}

void update_control_arc_text() {
printf("update text\n");
auto range = lv_arc_get_max_value(ui_ControlArc) - lv_arc_get_min_value(ui_ControlArc);
auto value = lv_arc_get_value(ui_ControlArc) - lv_arc_get_min_value(ui_ControlArc);

Expand Down
20 changes: 12 additions & 8 deletions shared/CoreModules/elements/base_element.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

// Hierarchy:
// BaseElement
// |---------------------------------'--------------|----------------------------|
// +---------------------------------'--------------+---------------------------+
// | | |
// ParamElement JackElement LightElement
// |----------|---'----|----------|-----------| |------'-----| |---------|'-------|---------|
// | | | | | | | | | | |
// Pot FlipSwitch Encoder SlideSwitch Button JackInput JackOutput MonoLight DualLight RGBLight Display
// |--'--| | |----'---------|
// Knob Slider | MomBut LatchingBut
// | | |---'---| |
// SliderLight EncoderRGB MomButWhite MomButRGB LatButMonoLight
// +----------+---'--------+------------------+ +------'-----+ +---------+'-------+---------+
// | | | | | | | | | |
// Pot Encoder Switch Button JackInput JackOutput MonoLight DualLight RGBLight Display
// +--'--+ | +----'---+ +----'---------+
// | | | | | | |
// Knob Slider | FlipSw SlideSw MomBut LatchingBut
// | | +---'---+ |
// | | | | |
// SliderLight EncoderRGB MomButWhite MomButRGB LatButMonoLight
//

namespace MetaModule
Expand Down Expand Up @@ -124,6 +127,7 @@ struct SlideSwitch : Switch {
State_t num_pos = 2;
std::string_view image_bg = "";
std::string_view image_fg = "";
enum class Ascend { UpLeft, DownRight } direction = Ascend::DownRight;
std::array<std::string_view, 8> pos_names{};
};

Expand Down

0 comments on commit c3c6881

Please sign in to comment.