本文整理汇总了Java中com.pi4j.io.i2c.I2CDevice类的典型用法代码示例。如果您正苦于以下问题:Java I2CDevice类的具体用法?Java I2CDevice怎么用?Java I2CDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
I2CDevice类属于com.pi4j.io.i2c包,在下文中一共展示了I2CDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
@Override
public void initialize(ConfigurationProvider configurationProvider) throws IOException {
// this is a "robot leg problem"
// see https://github.com/google/guice/wiki/FrequentlyAskedQuestions#How_do_I_build_two_similar_but_slightly_different_trees_of_objec
// we have a leftMotor and a rightMotor - same class, different configuration
// I did not use the private module solution as it is a bit scary to look at. But maybe:
// TODO: clean this mess up - MotorControllers should be injected
I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
I2CDevice device = bus.getDevice(0x40);
PCA9685PWMGenerator driver = new PCA9685PWMGenerator(device);
driver.open();
driver.setFrequency(50);
leftMotor = new MotorControllerImpl(driver.getOutput(14),
configurationProvider.bind("motorLeft", MotorControllerConfiguration.class));
rightMotor = new MotorControllerImpl(driver.getOutput(15),
configurationProvider.bind("motorRight", MotorControllerConfiguration.class));
LOGGER.debug("Completed setting up DriveController");
}
示例2: main
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public static void main(String[] args)
throws IOException, I2CFactory.UnsupportedBusNumberException,
InterruptedException {
// Connect to I2C bus 1
I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_1);
// Create device object
I2CDevice device = i2c.getDevice(PCF8574P_ADDRESS);
while(true) {
device.write((byte)0x40,(byte)0);
Thread.sleep(1000);
device.write((byte)0x40,(byte)1);
}
}
示例3: initialize
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
@Override
public void initialize(ConfigurationProvider configurationProvider) throws IOException {
super.initialize(configurationProvider);
I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
I2CDevice device = bus.getDevice(0x40);
PCA9685PWMGenerator driver = new PCA9685PWMGenerator(device);
driver.open();
driver.setFrequency(50);
horizontalHeadMotor = new ServoControllerImpl(driver.getOutput(1),
configurationProvider.bind("servo1", ServoConfiguration.class));
verticalHeadMotor = new ServoControllerImpl(driver.getOutput(0),
configurationProvider.bind("servo0", ServoConfiguration.class));
horizontalHeadMotor.setPosition(headPositionHorizontal);
verticalHeadMotor.setPosition(headPositionVertical);
LOGGER.debug("Completed setting up HeadController");
}
示例4: getDevice
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public I2CDevice getDevice(int busAddress, int deviceAddress) {
try {
String key = String.format("%d.%d", busAddress, deviceAddress);
if (!devices.containsKey(key)) {
// FIXME -- remove put in createDevice
I2CBus bus = I2CFactory.getInstance(busAddress);
log.info(String.format("getDevice %d", deviceAddress));
I2CDevice device = bus.getDevice(deviceAddress);
Device d = new Device();
d.bus = bus;
d.device = device;
d.type = "display";
devices.put(key, d);
return d.device;
} else {
return devices.get(key).device;
}
} catch (Exception e) {
Logging.logError(e);
}
return null;
}
示例5: I2CWrite
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public byte I2CWrite(int busAddress, int deviceAddress, byte value) {
I2CDevice device = getDevice(busAddress, deviceAddress);
if (device == null) {
error("bus %d device %d not valid", busAddress, deviceAddress);
return -1;
}
try {
device.write(value);
return value;
} catch (Exception e) {
Logging.logError(e);
}
return -1;
}
示例6: writeToDisplay
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public void writeToDisplay(int address, byte b0, byte b1, byte b2, byte b3) {
try {
I2CBus i2cbus = I2CFactory.getInstance(rasPiBus);
I2CDevice device = i2cbus.getDevice(address);
device.write(address, (byte) 0x80);
I2CDevice display = i2cbus.getDevice(0x38);
display.write(new byte[] { 0, 0x17, b0, b1, b2, b3 }, 0, 6);
device.write(address, (byte) 0x83);
} catch (Exception e) {
Logging.logError(e);
}
}
示例7: processCommand
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public static boolean processCommand(I2CDevice device, byte[] command) throws IOException {
if (Objects.nonNull(device)) {
device.write(command);
return true;
} else {
throw new TankSystemException("device not available for command");
}
}
示例8: main
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
/**
* Alter these values to change device operation
*
* @param args
* @throws java.io.IOException
* @throws com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException
* @throws java.lang.InterruptedException
*/
// Device addresses 0x29, 0x39, 0x49 are possible by setting addr pin to
// GND, Floating, and +3.3V respectively
public static void main(String[] args)
throws IOException, I2CFactory.UnsupportedBusNumberException, InterruptedException {
// Set up the I2C libraries
I2CBus I2C_BUS;
I2CDevice TSL2561;
// Get i2c I2C_BUS
// Number depends on RasPI version
I2C_BUS = I2CFactory.getInstance(I2CBus.BUS_1);
System.out.println("Connected to bus. OK.");
// Get device itself
TSL2561 = I2C_BUS.getDevice(TSL2561_ADDR);
System.out.println("Connected to device.");
System.out.println("Device ID: " + TSL2561.read(TSL2561_REG_ID));
// Initialize device by issuing command with data value 0x03
TSL2561.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);
while (true) {
System.out.println("Waiting...");
Thread.sleep(500);
byte d0L = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_0_LOW));
byte d0H = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_0_HIGH));
byte d1L = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_1_LOW));
byte d1H = (byte) TSL2561.read((byte) (TCS34725_COMMAND_BIT | DATA_1_HIGH));
if (VERBOSE) {
System.out.println("Data 0: " + bytesToInt(d0H, d0L));
System.out.println("Data 1: " + bytesToInt(d1H, d1L));
}
}
}
示例9: probe
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
@Override
public boolean probe(com.diozero.api.I2CDevice.ProbeMode mode) {
try {
return device.read() >= 0;
} catch (IOException e) {
return false;
}
}
示例10: writeToDisplay
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public void writeToDisplay(int address, byte b0, byte b1, byte b2, byte b3) {
try {
I2CBus i2cbus = I2CFactory.getInstance(rasPiBus);
I2CDevice device = i2cbus.getDevice(address);
device.write(address, (byte) 0x80);
I2CDevice display = i2cbus.getDevice(0x38);
display.write(new byte[] { 0, 0x17, b0, b1, b2, b3 }, 0, 6);
device.write(address, (byte) 0x83);
} catch (Exception e) {
Logging.logError(e);
}
}
示例11: createDevice
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public I2CDevice createDevice(int busAddress, int deviceAddress, String type) {
try {
String key = String.format("%d.%d", busAddress, deviceAddress);
I2CBus bus = I2CFactory.getInstance(busAddress);
// PCF8574GpioProvider pcf = new PCF8574GpioProvider(busAddress,
// deviceAddress);
// I2CDevice device = bus.getDevice(deviceAddress);
// PCF8574GpioProvider p = new PCF8574GpioProvider(busAddress,
// deviceAddress);
// p.setValue(pin, value)
if ("com.pi4j.gpio.extension.pcf.PCF8574GpioProvider".equals(type)) {
Device d = new Device();
d.bus = bus;
d.device = (I2CDevice) new PCF8574GpioProvider(busAddress, deviceAddress);
d.type = d.device.getClass().getCanonicalName();// "PCF8574GpioProvider";
// // full type
// name
devices.put(key, d);
return d.device;
} else {
log.error("could not create device %s", type);
return null;
}
} catch (Exception e) {
Logging.logError(e);
}
return null;
}
示例12: writeRaw
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public void writeRaw(int busAddress, int deviceAddress, byte d0, byte d1, byte d2, byte d3, byte d4, byte d5, byte d6, byte d7, byte d8, byte d9, byte d10, byte d11, byte d12,
byte d13, byte d14, byte d15) {
try {
log.info("--------writeRaw begin -------------");
log.info(String.format("test %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15));
I2CDevice device = getDevice(busAddress, deviceAddress);
device.write(0x00, new byte[] { d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15 }, 0, 16);
log.info("--------writeRaw end-------------");
} catch (Exception e) {
Logging.logError(e);
}
}
示例13: writeDisplay
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public byte[] writeDisplay(byte[] data) {
if (device == null) {
log.error("device is null");
return data;
}
try {
if (log.isDebugEnabled()) {
logByteArray("writeDisplay", data);
}
// select display
device.write((byte) (selector &= ~MASK_DISPLAY)); // FIXME NOT
// CORRECT !
I2CDevice display = i2cbus.getDevice(0x38);
display.write(data, 0, data.length);
// de-select display
device.write((byte) (selector |= MASK_DISPLAY));// FIXME NOT CORRECT
// ! for LED
} catch (Exception e) {
log.error(String.format("writeDisplay device %d error in writing", address.controller));
Logging.logError(e);
}
return data;
}
示例14: set_leds
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
/**
* Write the given intensity value to all LEDs
* @param device - the PiGlow I2C device
* @param intensity - the LED intensity value to set
* @throws IOException
*/
static void set_leds(I2CDevice device, byte intensity) throws IOException {
byte[] values = new byte[LED_COUNT];
Arrays.fill(values, intensity);
device.write(CMD_SET_PWM_VALUES, values, 0, values.length);
device.write(CMD_UPDATE, ff);
}
示例15: set_arm
import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
/**
* Sets the leds of the given arm to the given intensity.
* @param device - the PiGlow I2C device
* @param arm - the arm used to index into the
* @param intensity - the LED intensity value to set
* @throws IOException
*/
static void set_arm(I2CDevice device, int arm, byte intensity) throws IOException {
byte[] values = new byte[LED_COUNT];
Arrays.fill(values, (byte)0);
for(int n = 0; n < ARMS[arm].length; n ++)
values[ARMS[arm][n]] = intensity;
device.write(CMD_SET_PWM_VALUES, values, 0, values.length);
device.write(CMD_UPDATE, ff);
}