Expose a non-deprecated constructor from the driver
@ -83,7 +83,7 @@ public class MCP9808 extends I2cDeviceSynchDevice<I2cDeviceSynch>
|
||||
}
|
||||
```
|
||||
|
||||
The device synch class requires that we implement a few methods in this class. This is indicated by an error message saying you need to implement a method called getManufacturer(), so we can add that in. Because the manufacturer is Adafruit, we can just return that as shown below. Once that method is done, we get another error at the top saying we need to include a method called doInitialize(). We have to return a boolean indicating whether the initialization was successful. Right now, we don’t have a way to check for that, and we don’t yet need to initialize anything, so we can just return true for now. Another error message appears saying we need to include a method called getDeviceName(). This returns a string, so we can just create one ourselves with the name of the sensor as shown below. The exact phrasing isn’t important. The last error we get asks us to create a constructor for the class. Because we’re using the I2C device, we have to include parameters for a device client, and pass that back to the super method as shown:
|
||||
The device synch class requires that we implement a few methods in this class. This is indicated by an error message saying you need to implement a method called getManufacturer(), so we can add that in. Because the manufacturer is Adafruit, we can just return that as shown below. Once that method is done, we get another error at the top saying we need to include a method called doInitialize(). We have to return a boolean indicating whether the initialization was successful. Right now, we don’t have a way to check for that, and we don’t yet need to initialize anything, so we can just return true for now. Another error message appears saying we need to include a method called getDeviceName(). This returns a string, so we can just create one ourselves with the name of the sensor as shown below. The exact phrasing isn’t important. The last error we get asks us to create a constructor for the class. We have to include parameters for an I2C "device client" and whether that device client is owned by our driver, and pass those to the super method as shown:
|
||||
|
||||
|
||||
```
|
||||
@ -109,9 +109,9 @@ public class MCP9808 extends I2cDeviceSynchDevice<I2cDeviceSynch>
|
||||
return "Adafruit MCP9808 Temperature Sensor";
|
||||
}
|
||||
|
||||
public MCP9808(I2cDeviceSynch deviceClient)
|
||||
public MCP9808(I2cDeviceSynch deviceClient, boolean deviceClientIsOwned)
|
||||
{
|
||||
super(deviceClient, true);
|
||||
super(deviceClient, deviceClientIsOwned);
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -152,9 +152,9 @@ If you want to have multiple I2C sensors on the same bus, they each need to have
|
||||
Now that we know what the sensor address is, we need to put that into our driver class. We can indicate this as the default address, which assumes the address pins are pulled low. We also need to inform the device client of the address during construction:
|
||||
|
||||
```
|
||||
public MCP9808(I2cDeviceSynch deviceClient)
|
||||
public MCP9808(I2cDeviceSynch deviceClient, boolean deviceClientIsOwned)
|
||||
{
|
||||
super(deviceClient, true);
|
||||
super(deviceClient, deviceClientIsOwned);
|
||||
|
||||
this.deviceClient.setI2cAddress(ADDRESS_I2C_DEFAULT);
|
||||
|
||||
@ -608,9 +608,9 @@ This parameters class then needs to be specified in the extended class and in th
|
||||
|
||||
```
|
||||
public class MCP9808Params extends I2cDeviceSynchDeviceWithParameters<I2cDeviceSynch, MCP9808Params.Parameters>
|
||||
public MCP9808Params(I2cDeviceSynch deviceClient)
|
||||
public MCP9808Params(I2cDeviceSynch deviceClient, boolean deviceClientIsOwned)
|
||||
{
|
||||
super(deviceClient, true, new Parameters());
|
||||
super(deviceClient, deviceClientIsOwned, new Parameters());
|
||||
```
|
||||
|
||||
Now that we have the parameters class, we need to add a few things to it. First, we’re going to need to be able to clone parameter objects later on, so we’ll add code to implement the cloneable interface and add a method to create clones:
|
||||
|
Reference in New Issue
Block a user