Skip to content

Commit

Permalink
#77
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 19, 2020
1 parent 3af4226 commit 219011b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
4 changes: 0 additions & 4 deletions src/eez/firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ void boot() {

psu::trigger::init();

#if OPTION_ENCODER
mcu::encoder::init();
#endif

// TEST

g_bootTestSuccess = true;
Expand Down
17 changes: 9 additions & 8 deletions src/eez/modules/mcu/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ static uint16_t g_totalCounter;
static volatile int16_t g_counter;

bool g_accelerationEnabled = false;
EncoderMode g_encoderMode = ENCODER_MODE_AUTO;

#if defined(EEZ_PLATFORM_SIMULATOR)
bool g_simulatorClicked;
Expand All @@ -64,9 +63,6 @@ static int getAcceleratedCounter(int increment);

////////////////////////////////////////////////////////////////////////////////

void init() {
}

void read(int &counter, bool &clicked) {
clicked = isButtonClicked();
counter = getCounter();
Expand All @@ -76,11 +72,16 @@ void enableAcceleration(bool enable) {
g_accelerationEnabled = enable;
}

EncoderMode getEncoderMode() {
return (EncoderMode)psu::persist_conf::devConf.encoderMode;
}

void switchEncoderMode() {
if (g_encoderMode == ENCODER_MODE_STEP4) {
g_encoderMode = ENCODER_MODE_AUTO;
EncoderMode encoderMode = getEncoderMode();
if (encoderMode == ENCODER_MODE_STEP4) {
psu::persist_conf::setEncoderMode(ENCODER_MODE_AUTO);
} else {
g_encoderMode = EncoderMode(g_encoderMode + 1);
psu::persist_conf::setEncoderMode(encoderMode + 1);
}
}

Expand Down Expand Up @@ -198,7 +199,7 @@ static int getCounter() {
}

static int getAcceleratedCounter(int increment) {
if (increment == 0 || !g_accelerationEnabled || g_encoderMode != ENCODER_MODE_AUTO) {
if (increment == 0 || !g_accelerationEnabled || getEncoderMode() != ENCODER_MODE_AUTO) {
return increment;
}

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 @@ -29,7 +29,6 @@ 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;

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

void enableAcceleration(bool enable);
Expand All @@ -41,7 +40,7 @@ enum EncoderMode {
ENCODER_MODE_STEP3,
ENCODER_MODE_STEP4
};
extern EncoderMode g_encoderMode;
extern EncoderMode getEncoderMode();
void switchEncoderMode();

#if defined(EEZ_PLATFORM_SIMULATOR)
Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/psu/gui/edit_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ Value getCurrentEncoderStepValue() {
StepValues stepValues;
getStepValues(stepValues);

int stepValueIndex = mcu::encoder::ENCODER_MODE_STEP4 - mcu::encoder::g_encoderMode;
int stepValueIndex = mcu::encoder::ENCODER_MODE_STEP4 - mcu::encoder::getEncoderMode();
if (stepValueIndex >= stepValues.count) {
stepValueIndex = stepValues.count - 1;
}
Expand All @@ -372,7 +372,7 @@ Value getCurrentEncoderStepValue() {

void showCurrentEncoderMode() {
#if OPTION_ENCODER
if (mcu::encoder::g_encoderMode == mcu::encoder::ENCODER_MODE_AUTO) {
if (mcu::encoder::getEncoderMode() == mcu::encoder::ENCODER_MODE_AUTO) {
infoMessage("Auto");
} else {
infoMessage(getCurrentEncoderStepValue());
Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ uint32_t g_focusEditValueChangedTime;
float encoderIncrement(Value value, int counter, float min, float max, float precision) {
float step;

if (mcu::encoder::g_encoderMode == mcu::encoder::ENCODER_MODE_AUTO) {
if (mcu::encoder::getEncoderMode() == mcu::encoder::ENCODER_MODE_AUTO) {
StepValues stepValues;
edit_mode_step::getStepValues(stepValues);
step = stepValues.values[stepValues.count - 1];
Expand Down Expand Up @@ -1773,7 +1773,7 @@ void onEncoder(int counter, bool clicked) {
Value stepValue = getEncoderStep(g_focusCursor, g_focusDataId);
if (stepValue.getType() != VALUE_TYPE_NONE) {
float step;
if (mcu::encoder::g_encoderMode == mcu::encoder::ENCODER_MODE_AUTO) {
if (mcu::encoder::getEncoderMode() == mcu::encoder::ENCODER_MODE_AUTO) {
step = stepValue.getFloat();
} else {
step = edit_mode_step::getCurrentEncoderStepValue().getFloat();
Expand Down
4 changes: 4 additions & 0 deletions src/eez/modules/psu/persist_conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,10 @@ void setEventQueueFilter(int eventQueueFilter) {
g_devConf.eventQueueFilter = eventQueueFilter;
}

void setEncoderMode(uint8_t encoderMode) {
g_devConf.encoderMode = encoderMode;
}

void setIsInhibitedByUser(int isInhibitedByUser) {
g_devConf.isInhibitedByUser = isInhibitedByUser;
}
Expand Down
5 changes: 4 additions & 1 deletion src/eez/modules/psu/persist_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ struct DeviceConfiguration {
SortFilesOption sortFilesOption;
int eventQueueFilter;
ViewFlags viewFlags;
uint8_t reserved6[48];
uint8_t encoderMode;
uint8_t reserved6[47];

// block 8
char ethernetHostName[ETHERNET_HOST_NAME_SIZE + 1];
Expand Down Expand Up @@ -329,6 +330,8 @@ void setSortFilesOption(SortFilesOption sortFilesOption);

void setEventQueueFilter(int eventQueueFilter);

void setEncoderMode(uint8_t encoderMode);

void setIsInhibitedByUser(int isInhibitedByUser);

void setDlogViewLegendViewOption(DlogViewLegendViewOption dlogViewLegendViewOption);
Expand Down
2 changes: 1 addition & 1 deletion src/third_party/stm32_truestudio/bb3.elf.launch
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${TOOLCHAIN_PATH}/arm-atollic-eabi-gdb"/>
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/bb3.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="C:\work\eez\modular-psu-firmware\src\third_party\stm32_truestudio\Debug\bb3-v1.4.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="bb3"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
Expand Down

0 comments on commit 219011b

Please sign in to comment.