Optimize loops

This commit is contained in:
fvanroie 2020-12-15 22:43:58 +01:00
parent ef9441a954
commit 6bf6f67fd9
10 changed files with 24 additions and 36 deletions

View File

@ -286,7 +286,7 @@ class Logging {
{
#ifndef DISABLE_LOGGING
for(uint8_t i = 0; i < 3; i++) {
for(int i = 0; i < 3; i++) {
if(_logOutput[i] == NULL || level > _level[i]) continue;
if(_prefix != NULL) {

View File

@ -384,7 +384,7 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font,
break;
case(0b001):
for(uint8_t i = 0; i < repeats; i++) { // repeats are black
for(int i = 0; i < repeats; i++) { // repeats are black
blackAdd(charBitmap_p, arrindex++);
}
break;
@ -547,28 +547,16 @@ static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos)
}
}
static void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos)
static inline void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos)
{
uint8_t col = pos & 0x0001; // remainder
uint16_t map_p = pos >> 1; // devide by 2
uint32_t col = pos & 0x0001; // remainder
uint32_t map_p = pos >> 1; // devide by 2
// if(color1 == ColorBlack) {
// // && color1 != ColorWhite) { // Don't check white, as the function is only used for colors
// if(col == 0) {
// charBitmap_p[map_p] = 0xf0;
// } else {
// charBitmap_p[map_p] |= color1;
// }
// } else {
// Serial.printf("%u color %u\n", pos, color1);
if(col == 0) {
charBitmap_p[map_p] = color1 << 5;
} else {
charBitmap_p[map_p] |= color1 << 1;
}
// }
// return 1; // shift 1 position
}
/*
@ -610,8 +598,8 @@ void printBuffer(uint8_t * charBitmap_p, uint8_t w, uint8_t h)
uint8_t cols = w + w % 2;
cols /= 2;
for(uint8_t i = 0; i < h; i++) {
for(uint8_t j = 0; j < cols; j++) {
for(int i = 0; i < h; i++) {
for(int j = 0; j < cols; j++) {
uint8_t b = charBitmap_p[i * cols + j];
printPixel(b >> 4);
printPixel(b & 0b1111);

View File

@ -59,7 +59,7 @@ build_flags =
${override.build_flags}
-D HASP_VERSION_MAJOR=0
-D HASP_VERSION_MINOR=3
-D HASP_VERSION_REVISION=1207
-D HASP_VERSION_REVISION=0
; -- Shared library dependencies in all environments
; Warning : don't put comments after github links => causes infinite download loop

View File

@ -395,7 +395,7 @@ void haspSetup()
// _lv_style_list_add_style(list, &pagefont);
/* Create all screens using the theme */
for(uint8_t i = 0; i < (sizeof pages / sizeof *pages); i++) {
for(int i = 0; i < (sizeof pages / sizeof *pages); i++) {
pages[i] = lv_obj_create(NULL, NULL);
// list = lv_obj_get_style_list(pages[i], LV_OBJ_PART_MAIN);
// _lv_style_list_add_style(list, &pagefont);

View File

@ -151,7 +151,7 @@ static bool attribute_lookup_lv_property(uint16_t hash, uint8_t * prop)
#endif
};
for(uint8_t i = 0; i < sizeof(props) / sizeof(props[0]); i++) {
for(uint32_t i = 0; i < sizeof(props) / sizeof(props[0]); i++) {
if(props[i].hash == hash) {
*prop = props[1].prop;
Log.warning(TAG_ATTR, F("%d found and has propery %d"), hash, props[i].prop);

View File

@ -346,7 +346,7 @@ void configSetup()
{
DynamicJsonDocument settings(1024 + 512);
for(uint8_t i = 0; i < 2; i++) {
for(uint32_t i = 0; i < 2; i++) {
Serial.print(__FILE__);
Serial.println(__LINE__);

View File

@ -97,7 +97,7 @@ void aceButtonSetup(void)
void IRAM_ATTR gpioLoop(void)
{
// Should be called every 4-5ms or faster, for the default debouncing time of ~20ms.
for(uint8_t i = 0; i < gpioUsedInputCount; i++) {
for(uint32_t i = 0; i < gpioUsedInputCount; i++) {
if(button[i]) button[i]->check();
}
}
@ -172,7 +172,7 @@ void gpioSetup()
{
aceButtonSetup();
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
for(uint32_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
uint8_t input_mode;
switch(gpioConfig[i].gpio_function) {
case OUTPUT:
@ -256,7 +256,7 @@ void gpio_set_state(hasp_gpio_config_t gpio, bool state)
void gpio_set_group_state(uint8_t groupid, uint8_t eventid)
{
bool state = dispatch_get_event_state(eventid);
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
for(uint32_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
if(gpioConfig[i].group == groupid) {
gpio_set_state(gpioConfig[i], state);
}
@ -266,7 +266,7 @@ void gpio_set_group_state(uint8_t groupid, uint8_t eventid)
void gpio_set_gpio_state(uint8_t pin, uint8_t eventid)
{
bool state = dispatch_get_event_state(eventid);
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
for(uint32_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
if(gpioConfig[i].pin == pin) {
gpio_set_state(gpioConfig[i], state);
return;
@ -385,7 +385,7 @@ bool gpioIsSystemPin(uint8_t gpio)
bool gpioInUse(uint8_t gpio)
{
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
for(uint32_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
if(gpioConfigInUse(i) && (gpioConfig[i].pin == gpio)) {
return true; // pin matches and is in use
}
@ -461,7 +461,7 @@ bool gpioGetConfig(const JsonObject & settings)
/* Build new Gpio array if the count is not correct */
if(i != HASP_NUM_GPIO_CONFIG) {
array = settings[FPSTR(F_GPIO_CONFIG)].to<JsonArray>(); // Clear JsonArray
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
for(uint32_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) |
(gpioConfig[i].gpio_function << 24);
array.add(cur_val);

View File

@ -314,7 +314,7 @@ void handleTouch(int8_t contacts, GTPoint * points)
GT911_points = points;
Log.verbose(TAG_GUI, "Contacts: %d", contacts);
for(uint8_t i = 0; i < contacts; i++) {
for(int i = 0; i < contacts; i++) {
Log.verbose(TAG_GUI, "C%d: #%d %d,%d s:%d", i, points[i].trackId, points[i].x, points[i].y, points[i].area);
yield();
}
@ -435,7 +435,7 @@ void guiCalibrate()
tft_espi_calibrate(calData);
#endif
for(uint8_t i = 0; i < 5; i++) {
for(int i = 0; i < 5; i++) {
Serial.print(calData[i]);
if(i < 4) Serial.print(", ");
}
@ -772,7 +772,7 @@ bool guiGetConfig(const JsonObject & settings)
/* Build new CalData array if the count is not correct */
if(i != 5) {
array = settings[FPSTR(F_GUI_CALIBRATION)].to<JsonArray>(); // Clear JsonArray
for(uint8_t i = 0; i < 5; i++) {
for(int i = 0; i < 5; i++) {
array.add(calData[i]);
}
changed = true;

View File

@ -263,7 +263,7 @@ String halGetMacAddress(int start, const char * seperator)
#if HASP_USE_ETHERNET > 0
#if USE_BUILTIN_ETHERNET > 0
mac_p = Ethernet.MACAddress();
for(uint8_t i = 0; i < 6; i++) mac[i] = *(mac_p + i);
for(int i = 0; i < 6; i++) mac[i] = *(mac_p + i);
#else
Ethernet.macAddress(mac);
#endif

View File

@ -1370,7 +1370,7 @@ void webHandleGpioOptions()
httpMessage += F("</select></p>");
httpMessage += F("<p><b>Group</b> <select id='group' name='group'>");
for(uint8_t i = 0; i < 15; i++) {
for(int i = 0; i < 15; i++) {
httpMessage += getOption(i, "Group " + String(i), i == conf.group);
}
httpMessage += F("</select></p>");
@ -1438,7 +1438,7 @@ void webHandleDebugConfig()
httpMessage += F("'><b>Syslog Facility</b> <select id='log' name='log'>");
uint8_t logid = settings[FPSTR(F_CONFIG_LOG)].as<uint8_t>();
for(uint8_t i = 0; i < 8; i++) {
for(int i = 0; i < 8; i++) {
httpMessage += getOption(i, String(F("Local")) + i, i == logid);
}
@ -1596,7 +1596,7 @@ void httpHandleNotFound()
httpMessage += F("\nArguments: ");
httpMessage += webServer.args();
httpMessage += "\n";
for(uint8_t i = 0; i < webServer.args(); i++) {
for(int i = 0; i < webServer.args(); i++) {
httpMessage += " " + webServer.argName(i) + ": " + webServer.arg(i) + "\n";
}
webServer.send(404, PSTR("text/plain"), httpMessage.c_str());