Skip to content
Snippets Groups Projects
Commit 3446061a authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Add normalizeUnit

parent 20a3af23
No related branches found
No related tags found
No related merge requests found
......@@ -96,6 +96,22 @@ func roundToDecimal(value float64, places int) float64 {
return math.Round(value*pow) / pow
}
func normalizeUnit(value float64, unit string) (float64, error) {
switch unit {
case "lqi":
return value * 100 / 255, nil
case "°F":
return (value - 32) * 5 / 9, nil
case "°K":
return value - 273.15, nil
case "mV", "mW", "mA":
return value / 1000, nil
case "V", "%", "A", "W", "Wh":
return value, nil
}
return 0, fmt.Errorf("Unknown unit %s", unit)
}
// convert Mired to Kelvin and Kelvin to Mired
// Mired = 1,000,000 / Temperature in Kelvin
func convertMired(value int) int {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment