From 5abfcebd40ba67932ba0c101c7744f3b0c4e2aab Mon Sep 17 00:00:00 2001 From: Marc Teichtahl Date: Fri, 17 Nov 2017 11:51:09 +1100 Subject: [PATCH] Adding display driver types - Basic - no -ve support, no leading zero - Advanced - 0 left padded, leading zero support, -ve support --- bin/config/pokey_test.cfg | 5 +- src/libs/plugins/pokey/main.cpp | 22 ++++-- src/libs/plugins/pokey/main.h | 4 +- src/libs/plugins/pokey/pokeyDevice.cpp | 93 +++++++++++++++++++------- src/libs/plugins/pokey/pokeyDevice.h | 5 +- 5 files changed, 93 insertions(+), 36 deletions(-) diff --git a/bin/config/pokey_test.cfg b/bin/config/pokey_test.cfg index 05dc298..cbadd49 100644 --- a/bin/config/pokey_test.cfg +++ b/bin/config/pokey_test.cfg @@ -20,8 +20,9 @@ configuration = ), displays = ( { - type = "microdriver", - name="OH_FLT_DISPLAY", + driver = "microdriver", # these are the drivers from flightsim.eu + type = "advanced" # basic (like elec panel) , advanced (like ALT ALT) + name = "OH_FLT_DISPLAY", enabled = 1, groups= ( { diff --git a/src/libs/plugins/pokey/main.cpp b/src/libs/plugins/pokey/main.cpp index 5625cc6..a76ed64 100644 --- a/src/libs/plugins/pokey/main.cpp +++ b/src/libs/plugins/pokey/main.cpp @@ -481,16 +481,18 @@ bool PokeyDevicePluginStateManager::deviceDisplaysConfiguration(libconfig::Setti for (libconfig::SettingIterator iter = displays->begin(); iter != displays->end(); iter++) { std::string name = "None"; std::string type = ""; + std::string driver = ""; int enabled = 0; try { iter->lookupValue("name", name); iter->lookupValue("type", type); + iter->lookupValue("driver", driver); iter->lookupValue("enabled", enabled); _logger(LOG_INFO, " [%s] - %s [%s]", pokeyDevice->name().c_str(), name.c_str(), type.c_str()); - int matrixRows = deviceDisplaysGroupsConfiguration(&iter->lookup("groups"), displayIndex, pokeyDevice, type); + int matrixRows = deviceDisplaysGroupsConfiguration(&iter->lookup("groups"), displayIndex, pokeyDevice, type, driver); _logger(LOG_INFO, " [%s] - Added %i digits", pokeyDevice->name().c_str(), matrixRows); pokeyDevice->configMatrixLED(displayIndex, 8, 8, enabled); @@ -506,7 +508,8 @@ bool PokeyDevicePluginStateManager::deviceDisplaysConfiguration(libconfig::Setti return retVal; } -int PokeyDevicePluginStateManager::deviceDisplaysGroupsConfiguration(libconfig::Setting *displayGroups, int displayId, std::shared_ptr pokeyDevice, std::string type) +int PokeyDevicePluginStateManager::deviceDisplaysGroupsConfiguration( + libconfig::Setting *displayGroups, int displayId, std::shared_ptr pokeyDevice, std::string type, std::string driver) { int groupCount = displayGroups->getLength(); int totalDigits = 0; @@ -527,12 +530,17 @@ int PokeyDevicePluginStateManager::deviceDisplaysGroupsConfiguration(libconfig:: iter->lookupValue("digits", digits); iter->lookupValue("position", position); - _logger(LOG_INFO, " [%s] - %s %i digits / position %i", pokeyDevice->name().c_str(), name.c_str(), digits, position); - pokeyDevice->addMatrixLED(displayId, name, type); + if (driver == "microdriver") { + _logger(LOG_INFO, " [%s] - %s %i digits / position %i", pokeyDevice->name().c_str(), name.c_str(), digits, position); + pokeyDevice->addMatrixLED(displayId, name, type, driver); - pokeyDevice->addGroupToMatrixLED(id++, displayId, name, digits, position); - addTargetToDeviceTargetList(name, pokeyDevice); - totalDigits += digits; + pokeyDevice->addGroupToMatrixLED(id++, displayId, name, digits, position); + addTargetToDeviceTargetList(name, pokeyDevice); + totalDigits += digits; + } + else { + _logger(LOG_INFO, " WARNING - Unknown display driver %s\n", driver.c_str()); + } } catch (const libconfig::SettingNotFoundException &nfex) { _logger(LOG_ERROR, "Could not find %s. Skipping....", nfex.what()); diff --git a/src/libs/plugins/pokey/main.h b/src/libs/plugins/pokey/main.h index e159527..f7e320b 100644 --- a/src/libs/plugins/pokey/main.h +++ b/src/libs/plugins/pokey/main.h @@ -4,8 +4,8 @@ #include #include #include -#include #include +#include #include #include "PoKeysLib.h" @@ -40,7 +40,7 @@ class PokeyDevicePluginStateManager : public PluginStateManager bool deviceEncodersConfiguration(libconfig::Setting *encoders, std::shared_ptr pokeyDevice); bool deviceDisplaysConfiguration(libconfig::Setting *displays, std::shared_ptr pokeyDevice); bool devicePWMConfiguration(libconfig::Setting *pwm, std::shared_ptr pokeyDevice); - int deviceDisplaysGroupsConfiguration(libconfig::Setting *displayGroups, int id, std::shared_ptr pokeyDevice, std::string type); + int deviceDisplaysGroupsConfiguration(libconfig::Setting *displayGroups, int id, std::shared_ptr pokeyDevice, std::string type, std::string driver); bool addTargetToDeviceTargetList(std::string, std::shared_ptr device); std::shared_ptr targetFromDeviceTargetList(std::string); void enumerateDevices(void); diff --git a/src/libs/plugins/pokey/pokeyDevice.cpp b/src/libs/plugins/pokey/pokeyDevice.cpp index 6f9c614..a4755e5 100644 --- a/src/libs/plugins/pokey/pokeyDevice.cpp +++ b/src/libs/plugins/pokey/pokeyDevice.cpp @@ -477,11 +477,12 @@ void PokeyDevice::addEncoder( } } -void PokeyDevice::addMatrixLED(int id, std::string name, std::string type) +void PokeyDevice::addMatrixLED(int id, std::string name, std::string type, std::string driver) { PK_MatrixLEDConfigurationGet(_pokey); _matrixLED[id].name = name; _matrixLED[id].type = type; + _matrixLED[id].driver = driver; mapNameToMatrixLED(name, id); } @@ -545,48 +546,92 @@ uint32_t PokeyDevice::targetValue(std::string targetName, bool value) uint8_t PokeyDevice::displayNumber(uint8_t displayNumber, std::string targetName, int value) { int groupIndex = 0; + std::string displayType = ""; + std::string charString = ""; for (int i = 0; i < MAX_MATRIX_LED_GROUPS; i++) { if (_matrixLED[displayNumber].group[i].name == targetName) { groupIndex = i; + displayType = _matrixLED[displayNumber].type; + break; } } - // we should only display +ve values - if (value < -1) { - value = value * -1; - } - - std::string charString = std::to_string(value); int numberOfChars = charString.length(); int groupLength = _matrixLED[displayNumber].group[groupIndex].length; - if (value == 0) { - int position = _matrixLED[displayNumber].group[groupIndex].position; - for (int i = position; i < (groupLength + position); i++) { - _pokey->MatrixLED[displayNumber].data[i] = 0b00000000; + if (displayType == DISPLAY_FORMAT_TYPE_BASIC) { + if (value < -1) { + value = value * -1; } - _pokey->MatrixLED[displayNumber].data[(position + groupLength) - 1] = _intToDisplayRow[0]; - } - if (numberOfChars <= groupLength) { + charString = std::to_string(value); - for (int i = 0; i < numberOfChars; i++) { - int displayOffset = (int)charString.at(i) - 48; - int convertedValue = _intToDisplayRow[displayOffset]; - int position = groupIndex + i; + if (value == 0) { + int position = _matrixLED[displayNumber].group[groupIndex].position; + for (int i = position; i < (groupLength + position); i++) { + _pokey->MatrixLED[displayNumber].data[i] = 0b00000000; + } + _pokey->MatrixLED[displayNumber].data[(position + groupLength) - 1] = _intToDisplayRow[0]; + } - if (value > 0) { - _matrixLED[displayNumber].group[groupIndex].value = convertedValue; - _pokey->MatrixLED[displayNumber].data[position] = convertedValue; + if (numberOfChars <= groupLength) { + + for (int i = 0; i < numberOfChars; i++) { + int displayOffset = (int)charString.at(i) - 48; + int convertedValue = _intToDisplayRow[displayOffset]; + int position = groupIndex + i; + + if (value > 0) { + _matrixLED[displayNumber].group[groupIndex].value = convertedValue; + _pokey->MatrixLED[displayNumber].data[position] = convertedValue; + } + else if (value == -1) { + for (int i = groupIndex; i < groupLength + groupIndex; i++) { + _pokey->MatrixLED[displayNumber].data[i] = 0b00000000; + } + } } - else if (value == -1) { - for (int i = groupIndex; i < groupLength + groupIndex; i++) { - _pokey->MatrixLED[displayNumber].data[i] = 0b00000000; + } + } + else if (displayType == DISPLAY_FORMAT_TYPE_ADVANCED) { + std::string charString = std::to_string(value); + int numberOfChars = charString.length(); + int groupLength = _matrixLED[displayNumber].group[groupIndex].length; + + if (value == 18) { + value = 0; + int position = _matrixLED[displayNumber].group[groupIndex].position; + for (int i = position; i < (groupLength + position); i++) { + _pokey->MatrixLED[displayNumber].data[i] = _intToDisplayRow[0]; + } + } + else if (numberOfChars <= groupLength) { + int offset = groupLength - numberOfChars; + + for (int i = 0; i < numberOfChars; i++) { + int displayOffset = (int)charString.at(i) - 48; + int convertedValue = _intToDisplayRow[displayOffset]; + int position = groupIndex + i; + + // zero out the leading positions + if (position < offset) { + if (value < 0) { + _pokey->MatrixLED[displayNumber].data[i] = 0b00000010; + } + else { + _pokey->MatrixLED[displayNumber].data[i] = _intToDisplayRow[0]; + } } + _matrixLED[displayNumber].group[groupIndex].value = convertedValue; + _pokey->MatrixLED[displayNumber].data[position + offset] = convertedValue; } } } + else { + printf("----> Unknown display driver %s \n", displayType.c_str()); + return -1; + } _pokey->MatrixLED[displayNumber].RefreshFlag = 1; diff --git a/src/libs/plugins/pokey/pokeyDevice.h b/src/libs/plugins/pokey/pokeyDevice.h index 04125db..6f952a3 100644 --- a/src/libs/plugins/pokey/pokeyDevice.h +++ b/src/libs/plugins/pokey/pokeyDevice.h @@ -29,6 +29,8 @@ #define MAX_MATRIX_LED_GROUPS 8 #define MAX_DIGITS 10 #define MAX_PWM_CHANNELS 6 +#define DISPLAY_FORMAT_TYPE_BASIC "basic" +#define DISPLAY_FORMAT_TYPE_ADVANCED "advanced" typedef struct { std::string pinName; @@ -67,6 +69,7 @@ typedef struct { typedef struct { uint8_t id; std::string type; + std::string driver; std::string name; device_matrixLED_group_t group[MAX_MATRIX_LED_GROUPS]; } device_matrixLED_t; @@ -178,7 +181,7 @@ class PokeyDevice void addEncoder(int encoderNumber, uint32_t defaultValue, std::string name = DEFAULT_ENCODER_NAME, std::string description = DEFAULT_ENCODER_DESCRIPTION, int min = DEFAULT_ENCODER_MIN, int max = DEFAULT_ENCODER_MAX, int step = DEFAULT_ENCODER_STEP, int invertDirection = DEFAULT_ENCODER_DIRECTION, std::string units = ""); - void addMatrixLED(int id, std::string name, std::string type); + void addMatrixLED(int id, std::string name, std::string type, std::string driver); void configMatrixLED(int id, int rows, int cols = 8, int enabled = 0); void addGroupToMatrixLED(int id, int displayId, std::string name, int digits, int position); void startPolling();