本文整理汇总了Java中com.pi4j.io.i2c.I2CFactory类的典型用法代码示例。如果您正苦于以下问题:Java I2CFactory类的具体用法?Java I2CFactory怎么用?Java I2CFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
I2CFactory类属于com.pi4j.io.i2c包,在下文中一共展示了I2CFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import com.pi4j.io.i2c.I2CFactory; //导入依赖的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.I2CFactory; //导入依赖的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: PumpDiagGuiSingle
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
/**
* Creates new form MainWindow
*
* @throws com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException
* @throws java.io.IOException
*/
public PumpDiagGuiSingle() throws I2CFactory.UnsupportedBusNumberException, IOException, IOException, InterruptedException {
gpio = GpioFactory.getInstance(); // Singleton instance
mcpProvider = new MCP23017GpioProvider(I2CBus.BUS_1, 0x23);
// Provision direction control pins as outputs
System.out.println("Provisioning direction pin");
dir = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A7, "Direction", PinState.LOW);
// Provision step control pins as outputs
System.out.println("Provisioning step pin");
step = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A6, "Step", PinState.LOW);
// Provision enable pins as outputs.
// Note that the pin state "high" means the pump is disabled;
// the enable pump on the chip is inverted.
System.out.println("Provisioning enable pin");
enable = gpio.provisionDigitalOutputPin(mcpProvider, MCP23017Pin.GPIO_A5, "~Enable", PinState.HIGH);
}
示例4: RgbSensor
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
public RgbSensor()
throws IOException, I2CFactory.UnsupportedBusNumberException {
// Get the I2C Bus
this.i2cBus = I2CFactory.getInstance(I2CBus.BUS_1);
// Get device
this.device = i2cBus.getDevice(ADDR_DEFAULT);
// Initialize device
this.readU8(0x44);
// Enable device
this.write8(TCS34725_ENABLE, (byte) TCS34725_ENABLE_PON);
waitfor(10);
this.write8(TCS34725_ENABLE, (byte) (TCS34725_ENABLE_PON | TCS34725_ENABLE_AEN));
}
示例5: initialize
import com.pi4j.io.i2c.I2CFactory; //导入依赖的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");
}
示例6: WiringPiI2CDevice
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
public WiringPiI2CDevice(String key, DeviceFactoryInterface deviceFactory, int controller, int address,
int addressSize, int clockFrequency) throws RuntimeIOException {
super(key, deviceFactory);
this.controller = controller;
this.address = address;
/*
handle = I2C.wiringPiI2CSetup(address);
if (handle == -1) {
handle = CLOSED;
throw new IOException("Error in I2C.wiringPiI2CSetup(" + address + ")");
}
*/
Logger.debug("Opening I2C device ({}, 0x{})...",
Integer.valueOf(controller), Integer.toHexString(address));
try {
device = I2CFactory.getInstance(controller).getDevice(address);
} catch (UnsupportedBusNumberException | IOException e) {
throw new RuntimeIOException(e);
}
Logger.debug("I2C device ({}, 0x{}) opened",
Integer.valueOf(controller), Integer.toHexString(address));
}
示例7: Pi4jI2CDevice
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
public Pi4jI2CDevice(String key, DeviceFactoryInterface deviceFactory, int controller, int address,
int addressSize, int clockFrequency) throws RuntimeIOException {
super(key, deviceFactory);
this.controller = controller;
this.address = address;
Logger.debug(String.format("Opening I2C device ({}, 0x{})...",
Integer.valueOf(controller), Integer.toHexString(address)));
try {
device = I2CFactory.getInstance(controller).getDevice(address);
} catch (UnsupportedBusNumberException | IOException e) {
throw new RuntimeIOException(e);
}
Logger.debug(String.format("I2C device ({}, 0x{}) opened",
Integer.valueOf(controller), Integer.toHexString(address)));
}
示例8: BMP280
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
public BMP280(Protocol protocol, int deviceID, int i2cBusID) throws Exception {
this.protocol = protocol;
if(protocol == Protocol.I2C) {
I2Cbus = I2CFactory.getInstance(i2cBusID);
I2Cdevice = I2Cbus.getDevice(deviceID);
}
else if(protocol == Protocol.SPI) {
/* Set SPI to run default speed (1Mhz) in default mode (Mode 0) */
SPIdevice = SpiFactory.getInstance(SpiChannel.CS0, SpiDevice.DEFAULT_SPI_SPEED, SpiDevice.DEFAULT_SPI_MODE);
}
else {
throw new Exception("Invalid protocol set: " + protocol);
}
loadCurrentConfigSettingsFromDevice();
loadCompensationValues();
}
示例9: initialize
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
public void initialize() throws Exception {
if (this.bus == null) {
this.bus = I2CFactory.getInstance(I2CBus.BUS_1);
}
if (this.i2CDevice == null) {
this.i2CDevice = bus.getDevice(BLUEESC_ADDRESS + device);
resetEsc();
Runtime.getRuntime().addShutdownHook(new ShutdownThread());
if (this.keepAlive && keepAliveThread == null) {
this.keepAliveThread = new KeepAliveThread();
this.keepAliveThread.start();
}
}
}
示例10: Module
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
public Module(int bus, int i2cAddress) {
try {
address.setI2CBus(bus);
address.setI2CAddress(i2cAddress);
Platform platform = Platform.getLocalInstance();
if (platform.isArm()) {
// create I2C communications bus instance
i2cbus = I2CFactory.getInstance(bus);
// create I2C device instance
device = i2cbus.getDevice(i2cAddress);
}
if (!translationInitialized) {
initTranslation();
}
} catch (Exception e) {
Logging.logError(e);
}
}
示例11: init
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
public void init(){
try {
_gpioController = GpioFactory.getInstance();
_i2cbus = I2CFactory.getInstance(I2CBus.BUS_1);
_temperatureSensor = _i2cbus.getDevice(0x40);
_lightActuator = _gpioController.provisionDigitalMultipurposePin(RaspiPin.GPIO_00, "led", PinMode.DIGITAL_OUTPUT);
_lightActuator.setShutdownOptions(true); // unexport on shutdown
// monitor temperature changes
// every change of more than 0.1C will notify SensorChangedListeners
_scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
_handle = _scheduledThreadPoolExecutor.scheduleAtFixedRate(temperatureReader, 0, 100, TimeUnit.MILLISECONDS);
} catch (IOException e) {
log.error("An error occurred whilst trying to read temperature from GPIO Pins.");
}
}
示例12: writeToDisplay
import com.pi4j.io.i2c.I2CFactory; //导入依赖的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);
}
}
示例13: Module
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
public Module(int bus, int i2cAddress) {
try {
address.setI2CBus(bus);
address.setI2CAddress(i2cAddress);
Platform platform = Platform.getLocalInstance();
if (platform.isArm()) {
// create I2C communications bus instance
i2cbus = I2CFactory.getInstance(bus);
// create I2C device instance
device = i2cbus.getDevice(i2cAddress);
}
if (!translationInitialized) {
initTranslation();
}
} catch (Exception e) {
Logging.logError(e);
}
}
示例14: testBmp180BarometricSensorNewRaspi
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
@Test
public void testBmp180BarometricSensorNewRaspi() throws IOException {
new NonStrictExpectations() {
{
I2CFactory.getInstance(withEqual(I2CBus.BUS_1));
result = i2cBus;
i2cBus.getDevice(withEqual(0x77));
result = device;
// calibration
device.read(anyInt);
result = 1;
times = 22;
}
};
Bmp180BarometricSensor sensor = new Bmp180BarometricSensor(true, 0);
assertTrue(sensor.isInitiated());
}
示例15: create
import com.pi4j.io.i2c.I2CFactory; //导入依赖的package包/类
@Override
public RpiBaseMotor create(RpiMotor motor) {
RpiDevice device = (RpiDevice) motor;
try {
device.setBus(I2CFactory.getInstance(BUS_NUMBER));
device.setDevice(motor.getAddress());
} catch (IOException | I2CFactory.UnsupportedBusNumberException e) {
throw new RpiMotorException("wrong: ", e);
}
SimpleLoggingUtil.debug(getClass(), "port= " + ((RpiBaseMotor) device).getPort());
return (RpiBaseMotor) device;
}