-
Notifications
You must be signed in to change notification settings - Fork 14
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
mteichtahl
wants to merge
1
commit into
master
Choose a base branch
from
handle_display_types
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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"?