Tasmota/tasmota
Alexander Schliebner 7df46f051d
Optimized function 'mp'
Leaner syntax of function `mp` and simplified implementation.
New documentation:
Mapping function `mp`

It addresses a standard task with less code and much flexibility: mapping an arbitrary incoming numeric value into a defined schema of allowed/reasonable ranges.
The numeric value `x` passed as the first parameter is compared to the mprules in the order they are provided as subsequent parameters. If the value matches the criteria, the defined value is returned. Subsequent mprules are skipped. If `x` matches none of the mprules, `x` is returned unchanged. 
```
mp(x mprule1 mprule2 ... mprule<n>)
```

An mprule starts with one of the comparison operators `<`, `>` or `=`, followed by a numeric value `v1`, optionally followed by a second numeric value `v2`:
```
<|>|=v1[ v2]
```

Example 1: `<8 0` - this rule reads: If x is less than 8, return 0.
Example 2: `>100` - this rule reads: If x is greater than 100, return 100. 

Example 3:
```
y=mp(x <8 0 >100)
```
Assigns 0 to y if x is less than 8.
Assigns 100 to y if x is greater than 100.
Assigns x to y for all values of x that do not meet the above criteria (8 to 100).

The above code of example 3 does the same as the following code - with just one line of code and 19 characters less:
```
y=x
if x<8 {
y=0
}
if x>100 {
y=100
}
```

Every of the above mentioned numeric values `x`, `v1` and `v2` can be a literal, an expression or a variable.
2020-03-07 16:53:49 +01:00
..
language Fix RO compilation 2020-03-04 12:18:32 +01:00
CHANGELOG.md Update feature information 2020-03-05 14:00:47 +01:00
core_esp8266_timer.c Change Sonoff-Tasmota to Tasmota 2019-10-27 12:04:08 +01:00
core_esp8266_waveform.cpp Sync with https://github.com/esp8266/Arduino/pull/7057 2020-03-04 08:59:45 +01:00
core_esp8266_wiring_digital.c Change Sonoff-Tasmota to Tasmota 2019-10-27 12:04:08 +01:00
core_esp8266_wiring_pwm.c Change Sonoff-Tasmota to Tasmota 2019-10-27 12:04:08 +01:00
i18n.h Update Tx2x Sensor 2020-03-02 15:51:33 +01:00
my_user_config.h Add localization for Romanian 2020-03-04 11:56:35 +01:00
Parsing.cpp Change Sonoff-Tasmota to Tasmota 2019-10-27 12:04:08 +01:00
sendemail.h Change Sonoff-Tasmota to Tasmota 2019-10-27 12:04:08 +01:00
sendemail.ino Change Sonoff-Tasmota to Tasmota 2019-10-27 12:04:08 +01:00
settings.h Add Zigbee use distinct MQTT topics per device for SENSOR, allowing retained messages (#7835) 2020-03-04 21:00:57 +01:00
settings.ino Clean up wifi connection / disconnection 2020-02-26 15:29:13 -06:00
StackThunk_light.cpp Change Sonoff-Tasmota to Tasmota 2019-10-27 12:04:08 +01:00
StackThunk_light.h Change Sonoff-Tasmota to Tasmota 2019-10-27 12:04:08 +01:00
support_button.ino Happy New Year 2019-12-31 14:23:34 +01:00
support_command.ino Update Tx2x Sensor 2020-03-02 15:51:33 +01:00
support_crash_recorder.ino Happy New Year 2019-12-31 14:23:34 +01:00
support_device_groups.ino Add Light skip_light_fade flag and Dimmer3 command, Ignore MCU dimmer changes after sending dimmer command 2020-03-05 18:15:58 -06:00
support_esptool.ino Happy New Year 2019-12-31 14:23:34 +01:00
support_features.ino Update feature information 2020-03-05 14:00:47 +01:00
support_flash_log.ino Happy New Year 2019-12-31 14:23:34 +01:00
support_float.ino Happy New Year 2019-12-31 14:23:34 +01:00
support_legacy_cores.ino Happy New Year 2019-12-31 14:23:34 +01:00
support_rotary.ino Add LightPowerIRAM() for rotary interrupt handler 2020-01-03 17:57:47 +01:00
support_rtc.ino Remove NTP drift information 2020-02-20 14:55:41 +01:00
support_static_buffer.ino Add Zigbee persistence and friendly names 2020-01-18 00:02:01 +01:00
support_statistics.ino Happy New Year 2019-12-31 14:23:34 +01:00
support_switch.ino Fix switchmode 6 according to issue 7778 2020-03-01 09:42:59 +00:00
support_tasmota.ino Fix HASS button discovery 2020-03-04 18:02:27 +01:00
support_udp.ino Use newly allocated settings and flag 2020-02-24 16:34:45 -06:00
support_wifi.ino Clean up wifi connection / disconnection 2020-02-26 15:29:13 -06:00
support.ino Update Tx2x Sensor 2020-03-02 15:51:33 +01:00
tasmota_ca.ino Happy New Year 2019-12-31 14:23:34 +01:00
tasmota_post.h Add updated experimental Sonoff D1 support 2020-03-01 15:31:08 +01:00
tasmota_template.h Add updated experimental Sonoff D1 support 2020-03-01 15:31:08 +01:00
tasmota_version.h Change default my_user_config.h driver and sensor support 2020-02-27 15:10:42 +01:00
tasmota.h Rescale Bri to DimmerRange, Remove BriMin, LedTimeout and PoweredOffLed commands 2020-02-27 13:38:33 -06:00
tasmota.ino Add Light skip_light_fade flag and Dimmer3 command, Ignore MCU dimmer changes after sending dimmer command 2020-03-05 18:15:58 -06:00
user_config_override_sample.h Happy New Year 2019-12-31 14:23:34 +01:00
WiFiClientSecureLightBearSSL.cpp Change Sonoff-Tasmota to Tasmota 2019-10-27 12:04:08 +01:00
WiFiClientSecureLightBearSSL.h Change Sonoff-Tasmota to Tasmota 2019-10-27 12:04:08 +01:00
xdrv_01_webserver.ino Fix -minimal compile error 2020-03-05 18:45:43 +01:00
xdrv_02_mqtt.ino Fix HASS button discovery 2020-03-04 18:02:27 +01:00
xdrv_03_energy.ino Fix MaxPower functionality 2020-02-09 16:21:48 +01:00
xdrv_04_light.ino Add Light skip_light_fade flag and Dimmer3 command, Ignore MCU dimmer changes after sending dimmer command 2020-03-05 18:15:58 -06:00
xdrv_05_irremote_full.ino Fix char[] allocation 2020-01-12 23:31:57 +01:00
xdrv_05_irremote.ino Fix char[] allocation 2020-01-12 23:31:57 +01:00
xdrv_06_snfbridge.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_07_domoticz.ino Initial pwm dimmer support 2020-02-24 07:19:15 -06:00
xdrv_08_serial_bridge.ino Add simple check for serialreceived JSON 2020-01-14 15:58:56 +01:00
xdrv_09_timers.ino Fix char[] allocation 2020-01-12 23:31:57 +01:00
xdrv_10_rules.ino Update Tx2x Sensor 2020-03-02 15:51:33 +01:00
xdrv_10_scripter.ino Optimized function 'mp' 2020-03-07 16:53:49 +01:00
xdrv_11_knx.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_12_home_assistant.ino Fix HASS button discovery 2020-03-04 18:02:27 +01:00
xdrv_13_display.ino Fix some display issues 2020-01-01 15:13:58 +01:00
xdrv_14_mp3.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_15_pca9685.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_16_tuyamcu.ino Add Light skip_light_fade flag and Dimmer3 command, Ignore MCU dimmer changes after sending dimmer command 2020-03-05 18:15:58 -06:00
xdrv_17_rcswitch.ino Fix char[] allocation 2020-01-12 23:31:57 +01:00
xdrv_18_armtronix_dimmers.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_19_ps16dz_dimmer.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_20_hue.ino Fix exception 9 restart on log message 2020-01-14 12:47:48 +01:00
xdrv_21_wemo.ino Fix exception 9 restart on log message 2020-01-14 12:47:48 +01:00
xdrv_22_sonoff_ifan.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_23_zigbee_0_constants.ino Add Zigbee features and improvements 2020-03-01 11:25:59 +01:00
xdrv_23_zigbee_1_headers.ino Initial pwm dimmer support 2020-02-24 07:19:15 -06:00
xdrv_23_zigbee_3_devices.ino Add Zigbee use distinct MQTT topics per device for SENSOR, allowing retained messages (#7835) 2020-03-04 21:00:57 +01:00
xdrv_23_zigbee_4_persistence.ino Fix wrong encoding of Zigbee persistent data 2020-02-12 22:38:17 +01:00
xdrv_23_zigbee_5_converters.ino Add Zigbee features and improvements 2020-03-01 11:25:59 +01:00
xdrv_23_zigbee_6_commands.ino Add Zigbee features and improvements 2020-03-01 11:25:59 +01:00
xdrv_23_zigbee_7_statemachine.ino Add Zigbee features and improvements 2020-03-01 11:25:59 +01:00
xdrv_23_zigbee_8_parsers.ino Add Zigbee features and improvements 2020-03-01 11:25:59 +01:00
xdrv_23_zigbee_9_impl.ino Add Zigbee features and improvements 2020-03-01 11:25:59 +01:00
xdrv_24_buzzer.ino Add Buzzer commands 2020-02-06 16:25:37 +01:00
xdrv_25_A4988_Stepper.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_26_ariluxrf.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_27_shutter.ino Merge pull request #7845 from to-scho/hotfix/shutterbuttons_multipress_window_timing 2020-03-02 21:32:16 +01:00
xdrv_28_pcf8574.ino PCF8574 - skip detection if i2c address is defined in USE_MCP230xx_ADDR 2020-02-06 22:45:39 +01:00
xdrv_29_deepsleep.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_30_exs_dimmer.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_31_tasmota_slave.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_32_hotplug.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_33_nrf24l01.ino Add experimental support for NRF24L01 as BLE-bridge 2020-01-02 16:58:20 +01:00
xdrv_34_wemos_motor_v1.ino Add support for Wemos Motor Shield V1 2020-02-22 12:18:20 +01:00
xdrv_35_pwm_dimmer.ino Add button press count timeout 2020-02-27 23:38:55 -06:00
xdrv_36_keeloq.ino Fix keeloq functionality 2020-02-28 16:35:19 +01:00
xdrv_37_sonoff_d1.ino Add DimmerRange support to Sonoff D1 2020-03-01 16:13:59 +01:00
xdrv_99_debug.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdrv_interface.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdsp_01_lcd.ino Fix some display issues 2020-01-01 15:13:58 +01:00
xdsp_02_ssd1306.ino Reset before initialisation of the SSD1306 when OLED reset pin is set 2020-01-03 10:07:42 +01:00
xdsp_03_matrix.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdsp_04_ili9341.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdsp_05_epaper_29.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdsp_06_epaper_42.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdsp_07_sh1106.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdsp_08_ILI9488.ino i2c: I2cSetDevice wrong behavior 2020-01-19 16:15:18 +03:00
xdsp_09_SSD1351.ino Happy New Year 2019-12-31 14:23:34 +01:00
xdsp_10_RA8876.ino i2c: I2cSetDevice wrong behavior 2020-01-19 16:15:18 +03:00
xdsp_interface.ino Happy New Year 2019-12-31 14:23:34 +01:00
xlgt_01_ws2812.ino Happy New Year 2019-12-31 14:23:34 +01:00
xlgt_02_my92x1.ino Happy New Year 2019-12-31 14:23:34 +01:00
xlgt_03_sm16716.ino Happy New Year 2019-12-31 14:23:34 +01:00
xlgt_04_sm2135.ino Happy New Year 2019-12-31 14:23:34 +01:00
xlgt_05_sonoff_l1.ino Happy New Year 2019-12-31 14:23:34 +01:00
xlgt_interface.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_01_hlw8012.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_02_cse7766.ino Remove the need for GPIO_CSE7766_TX 2020-01-21 17:10:08 +01:00
xnrg_03_pzem004t.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_04_mcp39f501.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_05_pzem_ac.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_06_pzem_dc.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_07_ade7953.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_08_sdm120.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_09_dds2382.ino Fix DDS238-2 total energy 2020-01-08 11:43:39 +01:00
xnrg_10_sdm630.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_11_ddsu666.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_12_solaxX1.ino Happy New Year 2019-12-31 14:23:34 +01:00
xnrg_13_fif_le01mr.ino Add support for FiF LE-01MR energy meter 2020-02-10 15:18:11 +01:00
xnrg_interface.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_01_counter.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_02_analog.ino New ADC Range 2020-01-23 19:21:49 -03:00
xsns_04_snfsc.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_05_ds18x20.ino Fix DS18x20 driver 2020-02-18 18:10:36 +01:00
xsns_06_dht_old.ino Add new DHT driver 2020-02-10 16:29:17 +01:00
xsns_06_dht_v2.ino Add another new DHT driver based on ESPEasy 2020-02-13 17:02:07 +01:00
xsns_06_dht_v3.ino Add a stripped down Add a stripped DHT driver based on ESPEasy (#7717) 2020-02-13 18:12:27 +01:00
xsns_06_dht_v4.ino Another DHT driver with humidity range check 2020-02-15 12:57:23 +01:00
xsns_06_dht_v5.ino Initial pwm dimmer support 2020-02-24 07:19:15 -06:00
xsns_07_sht1x.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_08_htu21.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_09_bmp.ino - Add support to BMP driver to enter reset state (sleep enable) 2020-01-02 22:51:15 +02:00
xsns_10_bh1750.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_11_veml6070.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_12_ads1115.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_13_ina219.ino Use DEBUG_SENSOR macros for debug messages 2020-02-28 23:37:35 +01:00
xsns_14_sht3x.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_15_mhz19.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_16_tsl2561.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_17_senseair.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_18_pms5003.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_19_mgs.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_20_novasds.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_21_sgp30.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_22_sr04.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_24_si1145.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_26_lm75ad.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_27_apds9960.ino Fix APDS9960 compile error 2020-03-04 16:34:06 +01:00
xsns_28_tm1638.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_29_mcp230xx.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_30_mpr121.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_31_ccs811.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_32_mpu6050.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_33_ds3231.ino Eliminating call sntp_get_real_time 2020-02-19 15:23:59 +01:00
xsns_34_hx711.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_35_tx20.ino Update Tx2x Sensor 2020-03-02 15:51:33 +01:00
xsns_36_mgc3130.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_37_rfsensor.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_38_az7798.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_39_max31855.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_40_pn532.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_41_max44009.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_42_scd30.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_43_hre.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_44_sps30.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_45_vl53l0x.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_46_MLX90614.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_47_max31865.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_48_chirp.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_50_paj7620.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_51_rdm6300.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_52_ibeacon.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_53_sml.ino Update xsns_53_sml.ino 2020-02-04 07:09:29 +01:00
xsns_54_ina226.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_55_hih_series.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_56_hpma.ino Remove debug info 2020-01-07 17:10:07 +01:00
xsns_57_tsl2591.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_58_dht12.ino Happy New Year 2019-12-31 14:23:34 +01:00
xsns_59_ds1624.ino Fix DS1624 with KNX compilation error 2020-03-04 15:51:50 +01:00
xsns_60_GPS.ino virtual port improvement, bugfix 2020-02-16 08:36:51 +01:00
xsns_61_MI_NRF24.ino add missing PDU-type, small refactoring 2020-03-06 19:22:30 +01:00
xsns_62_MI_HM10.ino small cleanups 2020-02-09 15:32:45 +01:00
xsns_63_aht1x.ino Add initial support for Sensors AHT1x 2020-02-20 13:38:03 +01:00
xsns_64_hrxl.ino Adding support for MaxBotix HRXL line of sonar ranging sensors 2020-02-28 18:44:30 -06:00
xsns_91_prometheus.ino Fix typo in gauge metric type (#7216) 2020-01-11 10:15:30 +03:00
xsns_interface.ino Happy New Year 2019-12-31 14:23:34 +01:00
xx2c_interface.ino Happy New Year 2019-12-31 14:23:34 +01:00