Skip to content

Commit

Permalink
encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Aug 27, 2019
1 parent ae9d884 commit 95321b4
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 66 deletions.
3 changes: 1 addition & 2 deletions src/eez/apps/psu/gui/edit_mode_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ void onTouchUp() {
}

Value getCurrentEncoderStepValue() {
auto editValue = data::getEditValue(g_focusCursor, g_focusDataId);
auto stepValues = getUnitStepValues(editValue.getUnit());
auto stepValues = getUnitStepValues(getCurrentEncoderUnit());
return stepValues[mcu::encoder::ENCODER_MODE_STEP5 - mcu::encoder::g_encoderMode];
}

Expand Down
12 changes: 12 additions & 0 deletions src/eez/apps/psu/gui/page_ch_settings_trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,18 @@ bool ChSettingsListsPage::onEncoderClicked() {
return true;
}

Unit ChSettingsListsPage::getEncoderUnit() {
data::Cursor cursor(getCursorIndexWithinPage());

data::Value value = data::get(cursor, getDataIdAtCursor());

if (value.getType() == VALUE_TYPE_STR) {
value = data::getDef(cursor, getDataIdAtCursor());
}

return value.getUnit();
}

void ChSettingsListsPage::showInsertMenu() {
if (getRowIndex() < getMaxListLength()) {
pushPage(PAGE_ID_CH_SETTINGS_LISTS_INSERT_MENU);
Expand Down
1 change: 1 addition & 0 deletions src/eez/apps/psu/gui/page_ch_settings_trigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ChSettingsListsPage : public SetPage {

bool onEncoder(int counter);
bool onEncoderClicked();
Unit getEncoderUnit();

void showInsertMenu();
void showDeleteMenu();
Expand Down
13 changes: 13 additions & 0 deletions src/eez/apps/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,19 @@ bool onEncoderConfirmation() {
return false;
}

Unit getCurrentEncoderUnit() {
Page *activePage = getActivePage();
if (activePage) {
Unit unit = activePage->getEncoderUnit();
if (unit != UNIT_UNKNOWN) {
return unit;
}
}

auto editValue = data::getEditValue(g_focusCursor, g_focusDataId);
return editValue.getUnit();
}

void onEncoder(int counter, bool clicked) {
if (isFrontPanelLocked()) {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/eez/apps/psu/gui/psu.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void changeTemperatureTripDelay(int iChannel);

void psuErrorMessage(const data::Cursor &cursor, data::Value value, void (*ok_callback)() = 0);

Unit getCurrentEncoderUnit();

class PsuAppContext : public AppContext {
public:
PsuAppContext();
Expand Down
4 changes: 4 additions & 0 deletions src/eez/gui/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ bool Page::onEncoderClicked() {
return false;
}

Unit Page::getEncoderUnit() {
return UNIT_UNKNOWN;
}

int Page::getDirty() {
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/eez/gui/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Page {

virtual bool onEncoder(int counter);
virtual bool onEncoderClicked();
virtual Unit getEncoderUnit();

virtual int getDirty();
};
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 @@ -94,7 +94,7 @@ int getCounter() {
int32_t diffTick = tick - g_lastTick;
g_lastTick = tick;

g_acceleration += ((diffCounter > 0 ? CONF_ENCODER_ACCELERATION_INCREMENT_FACTOR : 0) - CONF_ENCODER_ACCELERATION_DECREMENT_PER_MS) * diffTick;
g_acceleration += ((diffCounter != 0 ? CONF_ENCODER_ACCELERATION_INCREMENT_FACTOR : 0) - CONF_ENCODER_ACCELERATION_DECREMENT_PER_MS) * diffTick;
if (g_acceleration < 0) g_acceleration = 0;
if (g_acceleration > 99) g_acceleration = 99;

Expand Down
129 changes: 66 additions & 63 deletions src/eez/platform/stm32/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,68 +52,71 @@ extern "C" void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *p
while (true) {}
}

#if OPTION_SDRAM
#include <assert.h>
#include <stdlib.h>

void SDRAM_Test() {
for (unsigned int seedValue = 0; seedValue < 100000; ++seedValue) {
{
uint32_t *p;

srand(seedValue);
p = (uint32_t *)0xc0000000;

for (int i = 0; i < 8 * 1024 * 1024 / 4; ++i) {
p[i] = (uint32_t)rand();
}

srand(seedValue);
p = (uint32_t *)0xc0000000;

for (int i = 0; i < 8 * 1024 * 1024 / 4; ++i) {
assert(p[i] == (uint32_t)rand());
}
}

{
uint16_t *p;

srand(seedValue);
p = (uint16_t *)0xc0000000;

for (int i = 0; i < 8 * 1024 * 1024 / 2; ++i) {
p[i] = (uint16_t)rand();
}

srand(seedValue);
p = (uint16_t *)0xc0000000;

for (int i = 0; i < 8 * 1024 * 1024 / 2; ++i) {
assert(p[i] == (uint16_t)rand());
}
}

{
uint8_t *p;

srand(seedValue);
p = (uint8_t *)0xc0000000;

for (int i = 0; i < 8 * 1024 * 1024; ++i) {
p[i] = (uint8_t)rand();
}

srand(seedValue);
p = (uint8_t *)0xc0000000;

for (int i = 0; i < 8 * 1024 * 1024; ++i) {
assert(p[i] == (uint8_t)rand());
}
}
}
}
#endif
//#if OPTION_SDRAM
//#include <assert.h>
//#include <stdlib.h>
//
//#define SDRAM_TEST_LOOPS 1
//#define SDRAM_TEST_STEP 64
//
//void SDRAM_Test() {
// for (unsigned int seedValue = 0; seedValue < SDRAM_TEST_LOOPS; ++seedValue) {
// {
// uint32_t *p;
//
// srand(seedValue);
// p = (uint32_t *)0xc0000000;
//
// for (int i = 0; i < 8 * 1024 * 1024 / 4; i += SDRAM_TEST_STEP) {
// p[i] = (uint32_t)rand();
// }
//
// srand(seedValue);
// p = (uint32_t *)0xc0000000;
//
// for (int i = 0; i < 8 * 1024 * 1024 / 4; i += SDRAM_TEST_STEP) {
// assert(p[i] == (uint32_t)rand());
// }
// }
//
// {
// uint16_t *p;
//
// srand(seedValue);
// p = (uint16_t *)0xc0000000;
//
// for (int i = 0; i < 8 * 1024 * 1024 / 2; i += SDRAM_TEST_STEP) {
// p[i] = (uint16_t)rand();
// }
//
// srand(seedValue);
// p = (uint16_t *)0xc0000000;
//
// for (int i = 0; i < 8 * 1024 * 1024 / 2; i += SDRAM_TEST_STEP) {
// assert(p[i] == (uint16_t)rand());
// }
// }
//
// {
// uint8_t *p;
//
// srand(seedValue);
// p = (uint8_t *)0xc0000000;
//
// for (int i = 0; i < 8 * 1024 * 1024; i += SDRAM_TEST_STEP) {
// p[i] = (uint8_t)rand();
// }
//
// srand(seedValue);
// p = (uint8_t *)0xc0000000;
//
// for (int i = 0; i < 8 * 1024 * 1024; i += SDRAM_TEST_STEP) {
// assert(p[i] == (uint8_t)rand());
// }
// }
// }
//}
//#endif

int main(int argc, char **argv) {
HAL_Init();
Expand Down Expand Up @@ -143,7 +146,7 @@ int main(int argc, char **argv) {
#if OPTION_SDRAM
/* SDRAM initialization sequence */
BSP_SDRAM_Initialization_sequence(REFRESH_COUNT);
SDRAM_Test();
// SDRAM_Test();
#endif

DWT_Delay_Init();
Expand Down

0 comments on commit 95321b4

Please sign in to comment.