Add helper macros to parse nibbles
Also made the button operations and nibbles constant since they should not be modified.
This commit is contained in:
parent
e6a3fa5e40
commit
8dbb883971
|
|
@ -243,8 +243,6 @@ static const char * const errorDescs[] PROGMEM = {
|
||||||
descRUNTIME_ERROR,
|
descRUNTIME_ERROR,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BUTTON_OP_HIGH_NIBBLE_MSK 0xF0
|
|
||||||
#define BUTTON_OP_LOW_NIBBLE_MSK 0x0F
|
|
||||||
|
|
||||||
/// Will be mapped onto dialog button responses in the FW
|
/// Will be mapped onto dialog button responses in the FW
|
||||||
/// Those responses have their unique+translated texts as well
|
/// Those responses have their unique+translated texts as well
|
||||||
|
|
@ -285,6 +283,10 @@ static const char * const btnOperation[] PROGMEM = {
|
||||||
btnDisableMMU
|
btnDisableMMU
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper macros to parse the operations from Btns()
|
||||||
|
#define BUTTON_OP_HI_NIBBLE(X) ( ( X & 0xF0 ) >> 4 )
|
||||||
|
#define BUTTON_OP_LO_NIBBLE(X) ( X & 0x0F )
|
||||||
|
|
||||||
// We have 8 different operations/buttons at this time, so we need at least 4 bits to encode each.
|
// We have 8 different operations/buttons at this time, so we need at least 4 bits to encode each.
|
||||||
// Since one of the buttons is always "More", we can skip that one.
|
// Since one of the buttons is always "More", we can skip that one.
|
||||||
// Therefore we need just 1 byte to describe the necessary buttons for each screen.
|
// Therefore we need just 1 byte to describe the necessary buttons for each screen.
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,9 @@ void ReportErrorHook(CommandInProgress cip, uint16_t ec) {
|
||||||
|
|
||||||
// Read and determine what operations should be shown on the menu
|
// Read and determine what operations should be shown on the menu
|
||||||
// Note: uint16_t is used here to avoid compiler warning. uint8_t is only half the size of void*
|
// Note: uint16_t is used here to avoid compiler warning. uint8_t is only half the size of void*
|
||||||
uint8_t button_operation = reinterpret_cast<uint16_t>(const_cast<void*>(pgm_read_ptr(&errorButtons[ei])));
|
const uint8_t button_operation = reinterpret_cast<uint16_t>(const_cast<void*>(pgm_read_ptr(&errorButtons[ei])));
|
||||||
uint8_t button_high_nibble = (button_operation & BUTTON_OP_HIGH_NIBBLE_MSK) >> 4;
|
const uint8_t button_high_nibble = BUTTON_OP_HI_NIBBLE(button_operation);
|
||||||
uint8_t button_low_nibble = button_operation & BUTTON_OP_LOW_NIBBLE_MSK;
|
const uint8_t button_low_nibble = BUTTON_OP_LO_NIBBLE(button_operation);
|
||||||
|
|
||||||
// Check if the menu should have three or two choices
|
// Check if the menu should have three or two choices
|
||||||
if (button_low_nibble == (uint8_t)ButtonOperations::NoOperation)
|
if (button_low_nibble == (uint8_t)ButtonOperations::NoOperation)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue