github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/apis/v1/connectionname.go (about) 1 // Copyright 2020-2021 Ewout Prangsma 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // Author Ewout Prangsma 16 // 17 18 package v1 19 20 // ConnectionName is a strongly typed well known know of a connection of an object type. 21 type ConnectionName string 22 23 const ( 24 ConnectionNameSensor ConnectionName = "sensor" 25 ConnectionNameOutput ConnectionName = "output" 26 ConnectionNameServo ConnectionName = "servo" 27 ConnectionNameStraightRelay ConnectionName = "straight-relay" 28 ConnectionNameOffRelay ConnectionName = "off-relay" 29 ConnectionNamePhaseStraightRelay ConnectionName = "phase-straight-relay" 30 ConnectionNamePhaseOffRelay ConnectionName = "phase-off-relay" 31 ConnectionNameRelayOutAInA ConnectionName = "relay-out-a-in-a" 32 ConnectionNameRelayOutBInA ConnectionName = "relay-out-b-in-a" 33 ConnectionNameRelayOutAInB ConnectionName = "relay-out-a-in-b" 34 ConnectionNameRelayOutBInB ConnectionName = "relay-out-b-in-b" 35 ConnectionNameMagneticStraightA ConnectionName = "magnetic-straight-a" 36 ConnectionNameMagneticStraightB ConnectionName = "magnetic-straight-b" 37 ConnectionNameMagneticOffA ConnectionName = "magnetic-off-a" 38 ConnectionNameMagneticOffB ConnectionName = "magnetic-off-b" 39 ) 40 41 func AllConnectionNames() []ConnectionName { 42 return []ConnectionName{ 43 ConnectionNameSensor, 44 ConnectionNameOutput, 45 ConnectionNameServo, 46 ConnectionNameStraightRelay, 47 ConnectionNameOffRelay, 48 ConnectionNamePhaseStraightRelay, 49 ConnectionNamePhaseOffRelay, 50 ConnectionNameRelayOutBInA, 51 ConnectionNameRelayOutAInA, 52 ConnectionNameRelayOutAInB, 53 ConnectionNameRelayOutBInB, 54 ConnectionNameMagneticStraightA, 55 ConnectionNameMagneticStraightB, 56 ConnectionNameMagneticOffA, 57 ConnectionNameMagneticOffB, 58 } 59 } 60 61 // ExpectedPins returns the expected number of pins for a connection with given name 62 func (name ConnectionName) ExpectedPins() int { 63 switch name { 64 default: 65 return 1 66 } 67 } 68 69 // ExpectedConfigurations returns the configuration keys that are expected for a connection 70 // with given name. 71 // Returns: Required keys, Optional keys 72 func (ot ConnectionName) ExpectedConfigurations() ([]ConfigKey, []ConfigKey) { 73 switch ot { 74 case ConnectionNameSensor: 75 return nil, []ConfigKey{ConfigKeyDebug, ConfigKeyInvert, ConfigKeyThreshold} 76 case ConnectionNameOutput: 77 return nil, []ConfigKey{ConfigKeyDebug, ConfigKeyInvert} 78 case ConnectionNameStraightRelay, ConnectionNameOffRelay: 79 return nil, []ConfigKey{ConfigKeyDebug, ConfigKeyInvert, ConfigKeyPulse} 80 case ConnectionNamePhaseStraightRelay, ConnectionNamePhaseOffRelay: 81 return nil, []ConfigKey{ConfigKeyDebug, ConfigKeyInvert} 82 case ConnectionNameRelayOutAInA, ConnectionNameRelayOutAInB, ConnectionNameRelayOutBInA, ConnectionNameRelayOutBInB: 83 return nil, []ConfigKey{ConfigKeyDebug, ConfigKeyInvert} 84 case ConnectionNameServo: 85 return nil, []ConfigKey{ConfigKeyDebug, ConfigKeyServoStraight, ConfigKeyServoOff, ConfigKeyServoStep} 86 case ConnectionNameMagneticStraightA, ConnectionNameMagneticStraightB, ConnectionNameMagneticOffA, ConnectionNameMagneticOffB: 87 return nil, []ConfigKey{ConfigKeyDebug, ConfigKeyInvert} 88 default: 89 return nil, nil 90 } 91 }