41 lines
847 B
Go
41 lines
847 B
Go
package core
|
|
|
|
import "errors"
|
|
|
|
type KeypadDimension struct {
|
|
AttrsPerKey int `json:"attrs_per_key"`
|
|
NumbOfKeys int `json:"numb_of_keys"`
|
|
}
|
|
|
|
func (kp *KeypadDimension) TotalAttrs() int {
|
|
return kp.AttrsPerKey * kp.NumbOfKeys
|
|
}
|
|
|
|
func (kp *KeypadDimension) IsDispersable() bool {
|
|
return kp.AttrsPerKey <= kp.NumbOfKeys
|
|
}
|
|
|
|
func (kp *KeypadDimension) IsValidKeypadDimension() error {
|
|
if KeypadMin.AttrsPerKey > kp.AttrsPerKey || KeypadMax.AttrsPerKey < kp.AttrsPerKey || KeypadMin.NumbOfKeys > kp.NumbOfKeys || KeypadMax.NumbOfKeys < kp.NumbOfKeys {
|
|
return errors.New("keypad dimensions out of range")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var (
|
|
KeypadMax = KeypadDimension{
|
|
AttrsPerKey: 16,
|
|
NumbOfKeys: 15,
|
|
}
|
|
|
|
KeypadMin = KeypadDimension{
|
|
AttrsPerKey: 5,
|
|
NumbOfKeys: 4,
|
|
}
|
|
|
|
KeypadDefault = KeypadDimension{
|
|
AttrsPerKey: 14,
|
|
NumbOfKeys: 7,
|
|
}
|
|
)
|