github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/apis/v1/devicetypes.go (about)

     1  // Copyright 2020 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  // DeviceType identifies a type of devices (typically chip name)
    21  type DeviceType string
    22  
    23  const (
    24  	// DeviceTypeMCP23008 is the device type of a General Purpose I/O
    25  	DeviceTypeMCP23008 DeviceType = "mcp23008"
    26  	// DeviceTypeMCP23017 is the device type of a General Purpose I/O
    27  	DeviceTypeMCP23017 DeviceType = "mcp23017"
    28  	// DeviceTypePCA9685 is the device type of a Pulse Width Modulation device
    29  	DeviceTypePCA9685 DeviceType = "pca9685"
    30  	// DeviceTypePCF8574 is the device type of a General Purpose I/O
    31  	DeviceTypePCF8574 DeviceType = "pcf8574"
    32  	// DeviceTypeADS1115 is the device type of a A/D conversion
    33  	DeviceTypeADS1115 DeviceType = "ads1115"
    34  	// DeviceTypeBinkyCarSensor is the device type of a BinkyCar sensor
    35  	// https://easyeda.com/editor?from=oshwlab#id=4b79ca953a7e4ea8971153b438ae1339|5964111c75b2459481dac75f8581f77e
    36  	DeviceTypeBinkyCarSensor DeviceType = "binkyCarSensor"
    37  )
    38  
    39  // Validate the given type, returning nil on ok,
    40  // or an error upon validation issues.
    41  func (t DeviceType) Validate() error {
    42  	switch t {
    43  	case DeviceTypeMCP23008, DeviceTypeMCP23017, DeviceTypePCA9685, DeviceTypePCF8574, DeviceTypeADS1115, DeviceTypeBinkyCarSensor:
    44  		return nil
    45  	default:
    46  		return InvalidArgument("invalid device type '%s'", string(t))
    47  	}
    48  }
    49  
    50  // AllDeviceTypes returns all possible device types.
    51  func AllDeviceTypes() []DeviceType {
    52  	return []DeviceType{DeviceTypeMCP23008, DeviceTypeMCP23017, DeviceTypePCA9685, DeviceTypePCF8574, DeviceTypeADS1115, DeviceTypeBinkyCarSensor}
    53  }