Skip to content

Commit

Permalink
Merge pull request #31 from norberttak/30-bug-negative-number-display…
Browse files Browse the repository at this point in the history
…-doesnt-work

Suppor negative number for display
  • Loading branch information
norberttak authored Jul 30, 2022
2 parents 454650c + ca12277 commit f7ef591
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/multi_purpose_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ bool MultiPurposeDisplay::is_registered_selector(std::string selector_sw_name)

bool MultiPurposeDisplay::get_decimal_components(int number, int max_dec_pos, unsigned char* buffer)
{
bool negative = false;
if (number < 0)
{
number = abs(number);
negative = true;
}

if (number >= pow(10, max_dec_pos + 1))
return false;

Expand All @@ -85,6 +92,10 @@ bool MultiPurposeDisplay::get_decimal_components(int number, int max_dec_pos, un
buffer[max_dec_pos - dec_pos] = remain / (int)pow(10, dec_pos);
remain = remain % (int)pow(10, dec_pos);
}

if (negative)
buffer[0] = 0xfe; // minus sign

return true;
}

Expand Down Expand Up @@ -112,12 +123,12 @@ bool MultiPurposeDisplay::get_display_value(unsigned char* digits)
void MultiPurposeDisplay::evaluate_and_store_dataref_value()
{
guard.lock();
if (conditions.count(active_condition) != 0 ||
const_values.count(active_condition) != 0 ||
lua_functions.count(active_condition) !=0 )
if (conditions.count(active_condition) != 0 ||
const_values.count(active_condition) != 0 ||
lua_functions.count(active_condition) != 0)
{
turn_off = false;

switch (data_ref_types[active_condition]) {
case xplmType_Int:
display_value = (double)XPLMGetDatai(conditions[active_condition]);
Expand All @@ -132,7 +143,7 @@ void MultiPurposeDisplay::evaluate_and_store_dataref_value()
if (const_values.count(active_condition) != 0)
display_value = const_values[active_condition];
else if (lua_functions.count(active_condition) != 0)
display_value = LuaHelper::get_instace()->do_string("return "+lua_functions[active_condition]);
display_value = LuaHelper::get_instace()->do_string("return " + lua_functions[active_condition]);

break;
}
Expand Down

0 comments on commit f7ef591

Please sign in to comment.