Skip to content

Commit

Permalink
#40
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jul 23, 2020
1 parent 5645a1d commit 9bddaf8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
37 changes: 37 additions & 0 deletions src/eez/firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void boot() {

psu::ontime::g_mcuCounter.init();

int numInstalledModules = 0;
for (uint8_t slotIndex = 0; slotIndex < NUM_SLOTS; slotIndex++) {
static const uint16_t ADDRESS = 0;
uint16_t value[3];
Expand All @@ -142,6 +143,42 @@ void boot() {
if (moduleType != MODULE_TYPE_NONE) {
psu::persist_conf::loadModuleConf(slotIndex);
psu::ontime::g_moduleCounters[slotIndex].init();

numInstalledModules++;
}
}

if (numInstalledModules == 1) {
g_isCol2Mode = true;

if (g_slots[0]->moduleInfo->moduleType == MODULE_TYPE_NONE) {
int i;
for (i = 1; i < NUM_SLOTS; i++) {
if (g_slots[i]->moduleInfo->moduleType != MODULE_TYPE_NONE) {
g_slotIndexes[0] = i - 1;
g_slotIndexes[1] = i;
break;
}
}

int k = 0;
for (int j = 0; j < i - 1; j++) {
g_slotIndexes[k++] = j;
}
for (int j = i + 1; j < NUM_SLOTS; j++) {
g_slotIndexes[k++] = j;
}
}
} else if (numInstalledModules == 2) {
g_isCol2Mode = true;

int j = 0;
for (int i = 0; i < NUM_SLOTS; i++) {
if (g_slots[i]->moduleInfo->moduleType != MODULE_TYPE_NONE) {
g_slotIndexes[j++] = i;
} else {
g_slotIndexes[2] = i;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/eez/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

namespace eez {

bool g_isCol2Mode = false;
int g_slotIndexes[3] = { 0, 1, 2 };

ModuleInfo::ModuleInfo(uint16_t moduleType_, uint16_t moduleCategory_, const char *moduleName_, const char *moduleBrand_, uint16_t latestModuleRevision_, FlashMethod flashMethod_, uint32_t flashDuration_, uint32_t spiBaudRatePrescaler_, bool spiCrcCalculationEnable_)
: moduleType(moduleType_)
, moduleCategory(moduleCategory_)
Expand Down
3 changes: 3 additions & 0 deletions src/eez/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ ModuleInfo *getModuleInfo(uint16_t moduleType);

void getModuleSerialInfo(uint8_t slotIndex, char *text);

extern bool g_isCol2Mode;
extern int g_slotIndexes[NUM_SLOTS];

} // namespace eez
24 changes: 9 additions & 15 deletions src/eez/modules/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,15 +1420,9 @@ void data_channels_is_max_view(DataOperationEnum operation, Cursor cursor, Value
}
}

bool is2ColMode() {
return g_slots[0]->moduleInfo->moduleType != MODULE_TYPE_NONE &&
g_slots[1]->moduleInfo->moduleType != MODULE_TYPE_NONE &&
g_slots[2]->moduleInfo->moduleType == MODULE_TYPE_NONE;
}

void data_channels_is_2col_view(DataOperationEnum operation, Cursor cursor, Value &value) {
if (operation == DATA_OPERATION_GET) {
value = is2ColMode();
value = g_isCol2Mode;
}
}

Expand Down Expand Up @@ -1531,15 +1525,15 @@ void data_slot_channel_index(int slotIndex, DataOperationEnum operation, Cursor
}

void data_slot1_channel_index(DataOperationEnum operation, Cursor cursor, Value &value) {
data_slot_channel_index(0, operation, cursor, value);
data_slot_channel_index(g_slotIndexes[0], operation, cursor, value);
}

void data_slot2_channel_index(DataOperationEnum operation, Cursor cursor, Value &value) {
data_slot_channel_index(1, operation, cursor, value);
data_slot_channel_index(g_slotIndexes[1], operation, cursor, value);
}

void data_slot3_channel_index(DataOperationEnum operation, Cursor cursor, Value &value) {
data_slot_channel_index(2, operation, cursor, value);
data_slot_channel_index(g_slotIndexes[2], operation, cursor, value);
}

void data_slot_max_channel_index(DataOperationEnum operation, Cursor cursor, Value &value) {
Expand Down Expand Up @@ -1571,20 +1565,20 @@ void data_slot_min2_channel_index(DataOperationEnum operation, Cursor cursor, Va

void data_slot_default_view(int slotIndex, DataOperationEnum operation, Cursor cursor, Value &value) {
if (operation == DATA_OPERATION_GET) {
value = getSlotView(is2ColMode() ? SLOT_VIEW_TYPE_DEFAULT_2COL : SLOT_VIEW_TYPE_DEFAULT, slotIndex, cursor);
value = getSlotView(g_isCol2Mode ? SLOT_VIEW_TYPE_DEFAULT_2COL : SLOT_VIEW_TYPE_DEFAULT, slotIndex, cursor);
}
}

void data_slot1_default_view(DataOperationEnum operation, Cursor cursor, Value &value) {
data_slot_default_view(0, operation, cursor, value);
data_slot_default_view(g_slotIndexes[0], operation, cursor, value);
}

void data_slot2_default_view(DataOperationEnum operation, Cursor cursor, Value &value) {
data_slot_default_view(1, operation, cursor, value);
data_slot_default_view(g_slotIndexes[1], operation, cursor, value);
}

void data_slot3_default_view(DataOperationEnum operation, Cursor cursor, Value &value) {
data_slot_default_view(2, operation, cursor, value);
data_slot_default_view(g_slotIndexes[2], operation, cursor, value);
}

void data_slot_max_view(DataOperationEnum operation, Cursor cursor, Value &value) {
Expand Down Expand Up @@ -1635,7 +1629,7 @@ void data_slot_def_2ch_view(DataOperationEnum operation, Cursor cursor, Value &v
if (operation == DATA_OPERATION_GET) {
Channel &channel = Channel::get(cursor);
int isVert = persist_conf::devConf.channelsViewMode == CHANNELS_VIEW_MODE_NUMERIC || persist_conf::devConf.channelsViewMode == CHANNELS_VIEW_MODE_VERT_BAR;
if (is2ColMode()) {
if (g_isCol2Mode) {
value = channel.isOutputEnabled() ?
(isVert ? PAGE_ID_SLOT_DEF_2CH_VERT_ON_2COL : PAGE_ID_SLOT_DEF_2CH_HORZ_ON_2COL) :
(isVert ? PAGE_ID_SLOT_DEF_2CH_VERT_OFF_2COL : PAGE_ID_SLOT_DEF_2CH_HORZ_OFF_2COL);
Expand Down

0 comments on commit 9bddaf8

Please sign in to comment.