Use new annotations instead of @I2cSensor
@ -1,6 +1,3 @@
|
|||||||
## Editorial Note:
|
|
||||||
This article refers to a deprecated approach to writing a driver. A revised document with updated instructions on how to write an I2C driver will post posted soon to replace this version.
|
|
||||||
|
|
||||||
### Tutorial: Writing an I2C Driver
|
### Tutorial: Writing an I2C Driver
|
||||||
I2C (which can be pronounced as either "I squared C" or "I two C") is a type of low cost serial bus that is commonly used to connect peripheral electronic devices, such as a sensor, to a microcontroller (such as the REV Robotics Expansion Hub). The _FIRST_ Tech Challenge software has built-in support for several commercially available sensors. The _FIRST_ Tech Challenge software development kit (SDK) also lets advanced users write their own software driver to integrate an I2C device with the FTC Robot Controller app.
|
I2C (which can be pronounced as either "I squared C" or "I two C") is a type of low cost serial bus that is commonly used to connect peripheral electronic devices, such as a sensor, to a microcontroller (such as the REV Robotics Expansion Hub). The _FIRST_ Tech Challenge software has built-in support for several commercially available sensors. The _FIRST_ Tech Challenge software development kit (SDK) also lets advanced users write their own software driver to integrate an I2C device with the FTC Robot Controller app.
|
||||||
|
|
||||||
@ -130,10 +127,11 @@ public MCP9808(I2cDeviceSynch deviceClient)
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The next thing we can do is create a way to configure this specific sensor in the Robot Controller along with the rest of the hardware. We do this by adding an annotation to the class called I2CSensor, which has 3 strings for us to set: name, description, and an XML tag. The name is what appears in the robot configuration menu, and should be something human readable. The XML tag is what identifies the sensor in the code, and needs to be different for every sensor. This needs to follow XML naming rules, so no spaces. The description is a message that appears in help menus for humans to understand what it is. Make sure all 3 are descriptive, like so:
|
The next thing we can do is create a way to configure this specific sensor in the Robot Controller along with the rest of the hardware. We do this by adding an annotation to the class called `I2cDeviceType`, which must be accompanied by an annotation called `DeviceProperties`. `DeviceProperties` has 2 strings that must be set: a name, and an XML tag. The name is what appears in the robot configuration menu, and should be something human readable. The XML tag is what identifies the sensor in the code, and needs to be different for every sensor. This needs to follow XML naming rules, so it can't have any spaces. Make sure the values you pick are descriptive, like so:
|
||||||
|
|
||||||
```
|
```
|
||||||
@I2cSensor(name = "MCP9808 Temperature Sensor", description = "Temperature Sensor from Adafruit", xmlTag = "MCP9808")
|
@I2cDeviceType
|
||||||
|
@DeviceProperties(name = "MCP9808 Temperature Sensor", xmlTag = "MCP9808")
|
||||||
public class MCP9808 extends I2cDeviceSynchDevice<I2cDeviceSynch>
|
public class MCP9808 extends I2cDeviceSynchDevice<I2cDeviceSynch>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user