I change nothing in the order of declaration in sketch you write and give me.
-dev:
ThelastSatellites
array should be declared abovesignal_block
andTableSatellitesInView
:
In signal_block and TableSatellitesInView I just replace gps.satellites by lastSatellites and I got error..
-dev:
... andsignal_block
andTableSatellitesInView
should uselastSatellites
instead ofgps.satellites
:void signal_block()
{ int colo, cuid, cuva, floo, idsa, luva, posx, posy, unit, valu;
const int widt = 320; // screen (x left to right)
const int high = 240; // screen (y top to bottom)
...
if (i < nbsat) {
// draw the next satellite
idsa = lastSatellites[ i ].id; <-- NOT gps.satellites
luva = lastSatellites[ i ].snr;
... and:
void TableSatellitesInView()
{
int i = 0;
...
for ( i=0; i < nbsat; i++) {
print( lastSatellites[i].id , 3 ); <- NOT gps.satellites
print( lastSatellites[i].elevation, 3 );
print( lastSatellites[i].azimuth , 4 );
if (lastSatellites[i].tracked)
print( lastSatellites[i].snr, 3 );
else
DEBUG.print( F(" - ") );
It is what I did and got error.
-dev:
Hmm... I don't think you should modify thegps.satellites
array as you insert each element into thelastSatellites
array:nbsat = gps.sat_count;
for(uint8_t i = 0 , j; i < nbsat; i++)
{
for(j = i ; (j > 0) && (lastSatellites[j-1].snr < gps.satellites[i].snr); j--) <-- parens, comparison
{
lastSatellites[j] = lastSatellites[j-1]; <-- move element
}
lastSatellites[j] = gps.satellites[i]; // store element here !!!!<--- not for order !!!!
}
In Loop() I create a variable tempoSatellite and I ordered by snr desc lastSatellites.
Because I have error and can't use lastSatellites, I order also gps.satellites.
Maybe have you a best or faster method to reorder ?
I do not know C, and I think in PHP to write for Arduino. But in PHP exist array.sort arraykeys.sort and associative array.
I read a lot of on web to replace in C what I have in PHP.