TucsonDon
Member
C:
typedef struct
{
uint8_t hr[2]; //[0] = start hour [1] = stop hour
uint8_t min[2]; //[0] = start minute [1] = stop minute
uint8_t operation;
}TmrData_t;
void CheckTimerOrder(void)
{
uint8_t TCount = 0;
uint8_t j = 0;
TmrData_t TmrData[8], Key;
TCount = TmrCount(); //count timers in eeprom
for(uint8_t a = 0; a < TCount; a++)
{
GetTmrData(&TmrData[a], a); //get timer data from eeprom
}
/*to sort timers in chronological order by start hour*/
for(uint8_t i = 1; i < TCount; i++)
{
memcpy(&Key, &TmrData[i], 5);
j = i - 1;
while((j >= 0) && (TmrData[j].hr[0] > Key.hr[0]))
{
memcpy(&TmrData[j + 1], &TmrData[j], 5);
j -= 1;
}
j++;
memcpy(&TmrData[j], &Key, 5);
}
}
I am using this to sort through timers that I have stored in the EEPROM in chronological order by hour. I need to ad another sort that if the hour is the same to sort by minutes, but unsure of how to do it