Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding display driver types #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bin/config/pokey_test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we give this flag a more specific value like "counted" vs "value"?

name = "OH_FLT_DISPLAY",
enabled = 1,
groups= (
{
Expand Down
22 changes: 15 additions & 7 deletions src/libs/plugins/pokey/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -506,7 +508,8 @@ bool PokeyDevicePluginStateManager::deviceDisplaysConfiguration(libconfig::Setti
return retVal;
}

int PokeyDevicePluginStateManager::deviceDisplaysGroupsConfiguration(libconfig::Setting *displayGroups, int displayId, std::shared_ptr<PokeyDevice> pokeyDevice, std::string type)
int PokeyDevicePluginStateManager::deviceDisplaysGroupsConfiguration(
libconfig::Setting *displayGroups, int displayId, std::shared_ptr<PokeyDevice> pokeyDevice, std::string type, std::string driver)
{
int groupCount = displayGroups->getLength();
int totalDigits = 0;
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/libs/plugins/pokey/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <assert.h>
#include <iostream>
#include <iterator>
#include <thread>
#include <mutex>
#include <thread>
#include <unistd.h>

#include "PoKeysLib.h"
Expand Down Expand Up @@ -40,7 +40,7 @@ class PokeyDevicePluginStateManager : public PluginStateManager
bool deviceEncodersConfiguration(libconfig::Setting *encoders, std::shared_ptr<PokeyDevice> pokeyDevice);
bool deviceDisplaysConfiguration(libconfig::Setting *displays, std::shared_ptr<PokeyDevice> pokeyDevice);
bool devicePWMConfiguration(libconfig::Setting *pwm, std::shared_ptr<PokeyDevice> pokeyDevice);
int deviceDisplaysGroupsConfiguration(libconfig::Setting *displayGroups, int id, std::shared_ptr<PokeyDevice> pokeyDevice, std::string type);
int deviceDisplaysGroupsConfiguration(libconfig::Setting *displayGroups, int id, std::shared_ptr<PokeyDevice> pokeyDevice, std::string type, std::string driver);
bool addTargetToDeviceTargetList(std::string, std::shared_ptr<PokeyDevice> device);
std::shared_ptr<PokeyDevice> targetFromDeviceTargetList(std::string);
void enumerateDevices(void);
Expand Down
93 changes: 69 additions & 24 deletions src/libs/plugins/pokey/pokeyDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this condition code is starting to get too long - refactor cases into methods


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;

Expand Down
5 changes: 4 additions & 1 deletion src/libs/plugins/pokey/pokeyDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see first comment

#define DISPLAY_FORMAT_TYPE_ADVANCED "advanced"

typedef struct {
std::string pinName;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down