Skip to content

Commit

Permalink
#42
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 27, 2020
1 parent 1635cca commit 98bee89
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 43 deletions.
40 changes: 5 additions & 35 deletions src/eez/modules/dib-mio168/dib-mio168.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1908,28 +1908,15 @@ void data_dib_mio168_din_state(DataOperationEnum operation, Cursor cursor, Value
}
}

static int g_pin;

static EnumItem g_dinRangeEnumDefinition[] = {
{ 0, "Low" },
{ 1, "High" },
{ 0, 0 }
};

void data_dib_mio168_din_range(DataOperationEnum operation, Cursor cursor, Value &value) {
if (operation == DATA_OPERATION_GET) {
value = g_dinConfigurationPage.getPinRange(cursor % 8);
}
}

void onSetPinRanges(uint16_t value) {
popPage();
g_dinConfigurationPage.setPinRange(g_pin, value);
}

void action_dib_mio168_din_select_range() {
g_pin = getFoundWidgetAtDown().cursor % 8;
pushSelectFromEnumPage(g_dinRangeEnumDefinition, g_dinConfigurationPage.getPinRange(g_pin), nullptr, onSetPinRanges);
uint8_t pin = getFoundWidgetAtDown().cursor % 8;
g_dinConfigurationPage.setPinRange(pin, g_dinConfigurationPage.getPinRange(pin) ? 0 : 1);
}

void data_dib_mio168_din_has_speed(DataOperationEnum operation, Cursor cursor, Value &value) {
Expand All @@ -1938,26 +1925,15 @@ void data_dib_mio168_din_has_speed(DataOperationEnum operation, Cursor cursor, V
}
}

static EnumItem g_dinSpeedEnumDefinition[] = {
{ 0, "Fast" },
{ 1, "Slow" },
{ 0, 0 }
};

void data_dib_mio168_din_speed(DataOperationEnum operation, Cursor cursor, Value &value) {
if (operation == DATA_OPERATION_GET) {
value = g_dinConfigurationPage.getPinSpeed(cursor % 8);
}
}

void onSetPinSpeeds(uint16_t value) {
popPage();
g_dinConfigurationPage.setPinSpeed(g_pin, value);
}

void action_dib_mio168_din_select_speed() {
g_pin = getFoundWidgetAtDown().cursor % 8;
pushSelectFromEnumPage(g_dinSpeedEnumDefinition, g_dinConfigurationPage.getPinSpeed(g_pin), nullptr, onSetPinSpeeds);
uint8_t pin = getFoundWidgetAtDown().cursor % 8;
g_dinConfigurationPage.setPinSpeed(pin, g_dinConfigurationPage.getPinSpeed(pin) ? 0 : 1);
}

void action_dib_mio168_din_show_configuration() {
Expand Down Expand Up @@ -2219,12 +2195,6 @@ void data_dib_mio168_aout_output_enabled(DataOperationEnum operation, Cursor cur
}
}

static EnumItem g_aoutOutputModeEnumDefinition[] = {
{ SOURCE_MODE_CURRENT, "Current" },
{ SOURCE_MODE_VOLTAGE, "Voltage" },
{ 0, 0 }
};

void data_dib_mio168_aout_output_mode(DataOperationEnum operation, Cursor cursor, Value &value) {
if (operation == DATA_OPERATION_GET) {
value = g_aoutDac7760ConfigurationPage.m_mode;
Expand All @@ -2237,7 +2207,7 @@ void onSetOutputMode(uint16_t value) {
}

void action_dib_mio168_aout_select_output_mode() {
pushSelectFromEnumPage(g_aoutOutputModeEnumDefinition, g_aoutDac7760ConfigurationPage.m_mode, nullptr, onSetOutputMode);
g_aoutDac7760ConfigurationPage.m_mode = g_aoutDac7760ConfigurationPage.m_mode == SOURCE_MODE_VOLTAGE ? SOURCE_MODE_CURRENT : SOURCE_MODE_VOLTAGE;
}

static EnumItem g_aoutVoltageRangeEnumDefinition[] = {
Expand Down
16 changes: 11 additions & 5 deletions src/eez/modules/mcu/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ static uint16_t g_totalCounter;
static volatile int16_t g_counter;

bool g_accelerationEnabled = false;
float g_range;
float g_step;

#if defined(EEZ_PLATFORM_SIMULATOR)
bool g_simulatorClicked;
Expand All @@ -68,8 +70,10 @@ void read(int &counter, bool &clicked) {
counter = getCounter();
}

void enableAcceleration(bool enable) {
void enableAcceleration(bool enable, float range, float step) {
g_accelerationEnabled = enable;
g_range = range;
g_step = step;
}

EncoderMode getEncoderMode() {
Expand Down Expand Up @@ -226,10 +230,9 @@ static int getAcceleratedCounter(int increment) {
dt = clamp(dt, MIN_DT_MS, MAX_DT_MS);
}

// Heuristic: when dt is MIN_DT_MS and speed options is MAX_MOVING_SPEED then 1/2 rotation (= 12 pulses)
// should give us full range of 40 V if one pulse is 5mV.
const float MIN_VELOCITY = 1.0F;
const float MAX_VELOCITY = 40.0f / 12.0f / 0.005f;
// Heuristic: when dt is MIN_DT_MS and speed options is MAX_MOVING_SPEED then 1/2 rotation (= 12 pulses) should give us full range.
const float MIN_VELOCITY = 1.0f;
const float MAX_VELOCITY = g_range / 12.0f / g_step;

uint8_t speedOption = increment > 0 ? psu::persist_conf::devConf.encoderMovingSpeedUp : psu::persist_conf::devConf.encoderMovingSpeedDown;
float maxVelocity = remap(
Expand All @@ -238,6 +241,9 @@ static int getAcceleratedCounter(int increment) {
1.0f * MAX_MOVING_SPEED, MAX_VELOCITY);

float velocity = remap(dt, MIN_DT_MS, maxVelocity, MAX_DT_MS, MIN_VELOCITY);
if (velocity < 1.0f) {
velocity = 1.0f;
}

//printf("inc=%d, dt=%f, sign=%d, v=%f\n", increment, dt, sign, adjustedVelocity);

Expand Down
5 changes: 4 additions & 1 deletion src/eez/modules/mcu/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ static const uint8_t MIN_MOVING_SPEED = 1;
static const uint8_t DEFAULT_MOVING_DOWN_SPEED = 8;
static const uint8_t DEFAULT_MOVING_UP_SPEED = 6;

static const float DEFAULT_ENCODER_RANGE = 40.0f;
static const float DEFAULT_ENCODER_STEP = 5E-3f;

void read(int &counter, bool &clicked);

void enableAcceleration(bool enable);
void enableAcceleration(bool enable, float range = DEFAULT_ENCODER_RANGE, float step = DEFAULT_ENCODER_STEP);

enum EncoderMode {
ENCODER_MODE_MIN,
Expand Down
8 changes: 8 additions & 0 deletions src/eez/modules/psu/gui/page_ch_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,14 @@ void ChSettingsListsPage::onEncoder(int counter) {
float min = getMin(cursor, dataId).getFloat();
float max = getMax(cursor, dataId).getFloat();

if (dataId == DATA_ID_CHANNEL_LIST_DWELL) {
mcu::encoder::enableAcceleration(true);
} else {
StepValues stepValues;
edit_mode_step::getStepValues(stepValues);
mcu::encoder::enableAcceleration(true, max - min, stepValues.values[0]);
}

float newValue;

Value stepValue = getEncoderStep(g_focusCursor, g_focusDataId);
Expand Down
8 changes: 6 additions & 2 deletions src/eez/modules/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1755,8 +1755,6 @@ void onEncoder(int counter, bool clicked) {
}

bool encoderEnabled = isEncoderEnabledInActivePage();
mcu::encoder::enableAcceleration(encoderEnabled || getActivePageId() == PAGE_ID_DEBUG_VARIABLES || getActivePageId() == PAGE_ID_CH_SETTINGS_LISTS);

if (encoderEnabled) {
Value value;
if (persist_conf::devConf.encoderConfirmationMode && g_focusEditValue.getType() != VALUE_TYPE_NONE) {
Expand All @@ -1768,6 +1766,10 @@ void onEncoder(int counter, bool clicked) {
float min = getMin(g_focusCursor, g_focusDataId).getFloat();
float max = getMax(g_focusCursor, g_focusDataId).getFloat();

StepValues stepValues;
edit_mode_step::getStepValues(stepValues);
mcu::encoder::enableAcceleration(true, max - min, stepValues.values[0]);

float newValue;

Value stepValue = getEncoderStep(g_focusCursor, g_focusDataId);
Expand Down Expand Up @@ -1805,6 +1807,8 @@ void onEncoder(int counter, bool clicked) {
psuErrorMessage(g_focusCursor, result);
}
}
} else {
mcu::encoder::enableAcceleration(false);
}

if (activePageId == PAGE_ID_EDIT_MODE_KEYPAD || activePageId == PAGE_ID_NUMERIC_KEYPAD) {
Expand Down

0 comments on commit 98bee89

Please sign in to comment.