MAX7219 Display Problem
Hi Ian,
I have a litlle problem with display on max7219 using LedControl library.
i'm using the latest DCS-BIOS Arduino Library (v0.2.1)
1- what i try to do : displaying M2000C UVHF Report Frequency + Selected Preset.
2 - What is the problem : Selected preset is displayed, frequency report is blank (only the DP)
this is my function to keep the frequency report string, in my M2000C library:
local function getUHFFrequency()
local ret = {}
local li = list_indication(9)
if li == "" then return nil end
local m = li:gmatch("-----------------------------------------\n([^\n]+)\n([^\n]*)\n")
while true do
local name, value = m()
if not name then break end
ret[name] = value
end
local freqStatus = ret["text_COM_UHF2"]
return freqStatus:sub(0,3) .. freqStatus:sub(5,6)
end
local function getVHFFrequency()
local ret = {}
local li = list_indication(9)
if li == "" then return nil end
local m = li:gmatch("-----------------------------------------\n([^\n]+)\n([^\n]*)\n")
while true do
local name, value = m()
if not name then break end
ret[name] = value
end
local freqStatus = ret["text_COM_UHF1"]
return freqStatus:sub(0,3) .. freqStatus:sub(5,6)
end
this is my calls to function, in M2000C library to :
defineString("UHF_FREQUENCY", getUHFFrequency, 5, "UHF Radio", "UHF Frequency Report Display")
defineString("VHF_FREQUENCY", getVHFFrequency, 5, "U/VHF Radio", "U/VHF Frequency Report Display")
this is my use of defineFloat function to get the Selected preset value :
defineFloat("UVHF_PRESET", 445, {0,1}, "U/VHF Radio", "U/VHF PRESET Display")
defineFloat("UHF_PRESET", 435, {0,1}, "UHF Radio", "UHF PRESET Display")
and this is my sketch :
#define DCSBIOS_DEFAULT_SERIAL
#include "DcsBios.h"
#include <LedControl.h> //on inclus la librairie pour commander le MAX7219
LedControl lc=LedControl(10,11,12,1);
void onVhfFrequencyChange(char* newValue) {
char hundredths = newValue[0];
char tenths = newValue[1];
char ones = newValue[2];
char tens = newValue[3];
char hundreds = newValue[4];
lc.setChar(0,0,hundredths,false);
lc.setChar(0,1,tenths,false);
lc.setChar(0,2,ones,true);
lc.setChar(0,3,tens,false);
lc.setChar(0,4,hundreds,false);
}
DcsBios::StringBuffer<6> vhfFrequencyBuffer(0x30a0, onVhfFrequencyChange);
void onUvhfPresetChange(unsigned int uvhfPresetValue) {
unsigned int firstDigit;
unsigned int secondDigit;
if (uvhfPresetValue>2000 && uvhfPresetValue<5000){firstDigit=0;secondDigit=1;}
else if (uvhfPresetValue>5000 && uvhfPresetValue<7000){firstDigit=0;secondDigit=2;}
else if (uvhfPresetValue>7000 && uvhfPresetValue<11000){firstDigit=0;secondDigit=3;}
else if (uvhfPresetValue>11000 && uvhfPresetValue<14500){firstDigit=0;secondDigit=4;}
else if (uvhfPresetValue>14500 && uvhfPresetValue<17500){firstDigit=0;secondDigit=5;}
else if (uvhfPresetValue>17500 && uvhfPresetValue<21500){firstDigit=0;secondDigit=6;}
else if (uvhfPresetValue>21500 && uvhfPresetValue<24000){firstDigit=0;secondDigit=7;}
else if (uvhfPresetValue>24000 && uvhfPresetValue<27500){firstDigit=0;secondDigit=8;}
else if (uvhfPresetValue>27500 && uvhfPresetValue<30500){firstDigit=0;secondDigit=9;}
else if (uvhfPresetValue>30500 && uvhfPresetValue<34000){firstDigit=1;secondDigit=0;}
else if (uvhfPresetValue>34000 && uvhfPresetValue<37500){firstDigit=1;secondDigit=1;}
else if (uvhfPresetValue>37500 && uvhfPresetValue<41000){firstDigit=1;secondDigit=2;}
else if (uvhfPresetValue>41000 && uvhfPresetValue<44000){firstDigit=1;secondDigit=3;}
else if (uvhfPresetValue>44000 && uvhfPresetValue<47000){firstDigit=1;secondDigit=4;}
else if (uvhfPresetValue>47000 && uvhfPresetValue<51000){firstDigit=1;secondDigit=5;}
else if (uvhfPresetValue>51000 && uvhfPresetValue<54000){firstDigit=1;secondDigit=6;}
else if (uvhfPresetValue>54000 && uvhfPresetValue<56500){firstDigit=1;secondDigit=7;}
else if (uvhfPresetValue>56500 && uvhfPresetValue<60000){firstDigit=1;secondDigit=8;}
else if (uvhfPresetValue>60000 && uvhfPresetValue<63000){firstDigit=1;secondDigit=9;}
else if (uvhfPresetValue>63000 && uvhfPresetValue<=65535){firstDigit=2;secondDigit=0;}
lc.setDigit(0,5,firstDigit,false);
lc.setDigit(0,6,secondDigit,false);
}
DcsBios::IntegerBuffer uvhfPresetBuffer(0x30a6, 0xffff, 0, onUvhfPresetChange);
DcsBios::RotaryEncoder uvhfPresetRot("UVHF_PRESET_ROT", "DEC", "INC", 6, 7);
void setup() {
DcsBios::setup();
lc.shutdown(0, false);
lc.setIntensity(0,9);
}
void loop() {
DcsBios::loop();
}
if i look in the liveData ControlReference, the values are good.
Separatly, the functions are working well, but when them are both in my sketch only the Selected Preset works.
The same functions works well with UHF Radio..
i don't understand where is the problem... i'm working on it since many days...
Thanks for your help and for my burning head..:thumbup: