-
-
Notifications
You must be signed in to change notification settings - Fork 686
Closed
Labels
Description
Trying to understand the latest G115 update
// number of repetitions from data returned
calcReps := len(payload) / len(ids)
// version 1
repetitions = 255
if calcReps > 0 && calcReps < math.MaxUint8 {
repetitions = uint8(calcReps) // G115 triggered
}
// version 2
if calcReps < 0 || calcReps >= math.MaxUint8 {
// repetitions exceed limits - setting max
repetitions = 255
} else {
repetitions = uint8(calcReps) // G115 triggered
}
// version 3
if calcReps < 0 || calcReps >= math.MaxUint8 {
return // well ... not really what I need
}
repetitions = uint8(calcReps) // no G115
Alternatives 1 and 2 were passing before 2.23.0
So now in order to fulfill the return requirement do I have to setup all possible conversion helpers with/without defaults?
func IntToUint8WithDefault(n int, def uint8) uint8 {
if n < 0 || n >= math.MaxUint8 {
return def
}
return uint8(n)
}
Reactions are currently unavailable