letscontrolit / ESPEasy

Easy MultiSensor device based on ESP8266/ESP32
http://www.espeasy.com
Other
3.22k stars 2.2k forks source link

Code Optimization #396

Closed papperone closed 7 years ago

papperone commented 7 years ago

Looking some plugins code for learning I realized that some optimization can be performed here and there. Here's an example in the BH1750 plugin:

sensors_resolution_t mode; if (Settings.TaskDevicePluginConfig[event->TaskIndex][1]==RESOLUTION_LOW) mode = RESOLUTION_LOW; if (Settings.TaskDevicePluginConfig[event->TaskIndex][1]==RESOLUTION_NORMAL) mode = RESOLUTION_NORMAL; if (Settings.TaskDevicePluginConfig[event->TaskIndex][1]==RESOLUTION_HIGH) mode = RESOLUTION_HIGH; if (Settings.TaskDevicePluginConfig[event->TaskIndex][1]==RESOLUTION_AUTO_HIGH) mode = RESOLUTION_AUTO_HIGH;

which IMHO can be replaced by just 2 lines below: sensors_resolution_t mode; mode = Settings.TaskDevicePluginConfig[event->TaskIndex][1];

Can I submit those as Pull Requests? I ask as I don't want to mess up with who actually wrote and maintain each plugin.

psy0rz commented 7 years ago

thats strange code indeed. maybe its leftover when the code was doing something extra. you can create a pull request if you like.