Skip to content

Commit

Permalink
Added conversion from speed to register raw value
Browse files Browse the repository at this point in the history
  • Loading branch information
pvainio committed Oct 28, 2021
1 parent 10fce3e commit 8398ca3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vallox.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ func valueToSpeed(value byte) int8 {
return -1
}

func speedToValue(speed int8) byte {
return fanSpeedConversion[speed-1]
}

func valueToTemp(value byte) int8 {
return tempConversion[value]
}
Expand Down
39 changes: 39 additions & 0 deletions vallox_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package valloxrs485

import (
"testing"
)

func TestValueToTemp(t *testing.T) {
assertTemp(0, -74, t)
assertTemp(255, 100, t)
assertTemp(246, 97, t)
assertTemp(247, 100, t)
}

func TestValueToSpeed(t *testing.T) {
assertSpeed(1, 1, t)
assertSpeed(3, 2, t)
assertSpeed(7, 3, t)
assertSpeed(15, 4, t)
assertSpeed(31, 5, t)
assertSpeed(63, 6, t)
assertSpeed(127, 7, t)
assertSpeed(255, 8, t)
}

func assertTemp(raw byte, value int8, t *testing.T) {
if c := valueToTemp(raw); c != value {
t.Errorf("temp %d was not converted to %d but to %d", raw, value, c)
}
}

func assertSpeed(raw byte, value int8, t *testing.T) {
if c := valueToSpeed(raw); c != value {
t.Errorf("raw %d to speed was not converted to %d but to %d", raw, value, c)
}

if c := speedToValue(value); c != raw {
t.Errorf("speed %d to raw was not converted to %d but to %d", value, raw, c)
}
}

0 comments on commit 8398ca3

Please sign in to comment.