mirror of https://github.com/arendst/Tasmota.git
Zigbee replace qsort with insertion sort
This commit is contained in:
parent
1e49cb5a2a
commit
be5d9f90a8
File diff suppressed because it is too large
Load Diff
|
@ -1856,12 +1856,11 @@ const char ZB_WEB[] PROGMEM = "\x00\x66\x3D\x0E\xCA\xB1\xC1\x33\xF0\xF6\xD1\xEE\
|
||||||
// ++++++++++++++++++++ DO NOT EDIT ABOVE ++++++++++++++++++++
|
// ++++++++++++++++++++ DO NOT EDIT ABOVE ++++++++++++++++++++
|
||||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
extern "C" {
|
// comparator function used to sort Zigbee devices by alphabetical order (if friendlyname)
|
||||||
// comparator function used to sort Zigbee devices by alphabetical order (if friendlyname)
|
// then by shortaddr if they don't have friendlyname
|
||||||
// then by shortaddr if they don't have friendlyname
|
int device_cmp(uint8_t a, uint8_t b) {
|
||||||
int device_cmp(const void * a, const void * b) {
|
const Z_Device &dev_a = zigbee_devices.devicesAt(a);
|
||||||
const Z_Device &dev_a = zigbee_devices.devicesAt(*(uint8_t*)a);
|
const Z_Device &dev_b = zigbee_devices.devicesAt(b);
|
||||||
const Z_Device &dev_b = zigbee_devices.devicesAt(*(uint8_t*)b);
|
|
||||||
const char * fn_a = dev_a.friendlyName;
|
const char * fn_a = dev_a.friendlyName;
|
||||||
const char * fn_b = dev_b.friendlyName;
|
const char * fn_b = dev_b.friendlyName;
|
||||||
|
|
||||||
|
@ -1873,7 +1872,7 @@ extern "C" {
|
||||||
if (fn_a) return -1;
|
if (fn_a) return -1;
|
||||||
else return 1;
|
else return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Convert seconds to a string representing days, hours or minutes present in the n-value.
|
// Convert seconds to a string representing days, hours or minutes present in the n-value.
|
||||||
|
@ -1884,7 +1883,7 @@ extern "C" {
|
||||||
// - char for unit (d for day, h for hour, m for minute)
|
// - char for unit (d for day, h for hour, m for minute)
|
||||||
// - the hex color to be used to display the text
|
// - the hex color to be used to display the text
|
||||||
//
|
//
|
||||||
uint32_t convert_seconds_to_dhm(uint32_t seconds, char *unit, uint8_t *color){
|
uint32_t convert_seconds_to_dhm(uint32_t seconds, char *unit, uint8_t *color){
|
||||||
static uint32_t conversions[3] = {24 * 3600, 3600, 60};
|
static uint32_t conversions[3] = {24 * 3600, 3600, 60};
|
||||||
static char units[3] = { 'd', 'h', 'm'}; // day, hour, minute
|
static char units[3] = { 'd', 'h', 'm'}; // day, hour, minute
|
||||||
uint8_t color_text_8 = WebColor(COL_TEXT) & 0xFF; // color of text on 8 bits
|
uint8_t color_text_8 = WebColor(COL_TEXT) & 0xFF; // color of text on 8 bits
|
||||||
|
@ -1900,8 +1899,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} // extern "C"
|
|
||||||
|
|
||||||
const char HTTP_BTN_ZB_BUTTONS[] PROGMEM =
|
const char HTTP_BTN_ZB_BUTTONS[] PROGMEM =
|
||||||
"<button onclick='la(\"&zbj=1\");'>" D_ZIGBEE_PERMITJOIN "</button>"
|
"<button onclick='la(\"&zbj=1\");'>" D_ZIGBEE_PERMITJOIN "</button>"
|
||||||
|
@ -1927,7 +1925,17 @@ void ZigbeeShow(bool json)
|
||||||
for (uint32_t i = 0; i < zigbee_num; i++) {
|
for (uint32_t i = 0; i < zigbee_num; i++) {
|
||||||
sorted_idx[i] = i;
|
sorted_idx[i] = i;
|
||||||
}
|
}
|
||||||
qsort(sorted_idx, zigbee_num, sizeof(sorted_idx[0]), device_cmp);
|
|
||||||
|
// insertion sort
|
||||||
|
for (uint32_t i = 1; i < zigbee_num; i++) {
|
||||||
|
uint8_t key = sorted_idx[i];
|
||||||
|
uint8_t j = i;
|
||||||
|
while ((j > 0) && (device_cmp(sorted_idx[j - 1], key) > 0)) {
|
||||||
|
sorted_idx[j] = sorted_idx[j - 1];
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
sorted_idx[j] = key;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t now = Rtc.utc_time;
|
uint32_t now = Rtc.utc_time;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue