Last active
November 25, 2017 12:56
-
-
Save archishou/97f0e533c1ef4835d0484d1f2d33076b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressWarnings({"WeakerAccess", "unused"}) | |
@I2cSensor(name = "MasqColorSensor", description = "I2C Sensor that supports color number", xmlTag = "MasqColorSensor") | |
public class MasqColorSensorDriver extends I2cDeviceSynchDevice<I2cDeviceSynch> { | |
private static final int | |
READ_WINDOW_START = 0x04, | |
READ_WINDOW_LENGTH = 5; | |
public void write(int reg, int value) {deviceClient.write(reg, TypeConversion.shortToByteArray((short) value));} | |
public short read(int reg) {return TypeConversion.byteArrayToShort(deviceClient.read(reg, 2));} | |
private MasqColorSensorDriver(I2cDeviceSynch i2cDeviceSynch, boolean deviceClientIsOwned) {super(i2cDeviceSynch, deviceClientIsOwned);} | |
private MasqColorSensorDriver(I2cDeviceSynch deviceClient, int read) { | |
super(deviceClient, true); | |
this.setOptimalReadWindow(); | |
this.deviceClient.setI2cAddress(I2cAddr.create8bit(read)); | |
super.registerArmingStateCallback(false); | |
this.deviceClient.engage(); | |
} | |
private void setOptimalReadWindow() { | |
I2cDeviceSynch.ReadWindow readWindow = new I2cDeviceSynch.ReadWindow(READ_WINDOW_START, READ_WINDOW_LENGTH, I2cDeviceSynch.ReadMode.REPEAT); | |
this.deviceClient.setReadWindow(readWindow); | |
} | |
public void setEngage () {engage();} | |
@Override | |
public boolean doInitialize() { | |
return true; | |
} | |
@Override | |
public Manufacturer getManufacturer() { | |
return Manufacturer.Adafruit; | |
} | |
@Override | |
public String getDeviceName() { | |
return "MASQ COLOR SENSOR"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment