当前位置: 首页>>代码示例>>Java>>正文


Java I2CFactory.getInstance方法代码示例

本文整理汇总了Java中com.pi4j.io.i2c.I2CFactory.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java I2CFactory.getInstance方法的具体用法?Java I2CFactory.getInstance怎么用?Java I2CFactory.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.pi4j.io.i2c.I2CFactory的用法示例。


在下文中一共展示了I2CFactory.getInstance方法的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");
}
 
开发者ID:weiss19ja,项目名称:amos-ss16-proj2,代码行数:21,代码来源:DriveControllerImpl.java

示例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);
    }
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:17,代码来源:PFC8574P.java

示例3: 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));
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:18,代码来源:RgbSensor.java

示例4: 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");
}
 
开发者ID:weiss19ja,项目名称:amos-ss16-proj2,代码行数:20,代码来源:HeadControllerImpl.java

示例5: 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();		
}
 
开发者ID:whitestripes,项目名称:BMP280,代码行数:19,代码来源:BMP280.java

示例6: 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();
        }
    }
}
 
开发者ID:slipperyseal,项目名称:B9,代码行数:18,代码来源:BlueESC.java

示例7: 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);
	}

}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:26,代码来源:Module.java

示例8: 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.");
	}
}
 
开发者ID:wso2-incubator,项目名称:iot-server-appliances,代码行数:19,代码来源:AgentOperationManagerImpl.java

示例9: 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);
  }
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:17,代码来源:PickToLight.java

示例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);
  }

}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:26,代码来源:Module.java

示例11: 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());
   }
 
开发者ID:PoJD,项目名称:hawa,代码行数:20,代码来源:Bmp180BarometricSensorTestCase.java

示例12: BME280

import com.pi4j.io.i2c.I2CFactory; //导入方法依赖的package包/类
public BME280() {
    try {
        // Create I2C bus
        I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
        // Get I2C device, BME280 I2C address is 0x76(108)
        device = bus.getDevice(0x76);
    } catch (Exception e) {
        Logger.error("Failed to get BME280.");
        e.printStackTrace();
    }
}
 
开发者ID:Siketyan,项目名称:TempMonitor,代码行数:12,代码来源:BME280.java

示例13: createProvider

import com.pi4j.io.i2c.I2CFactory; //导入方法依赖的package包/类
private PCA9685GpioProvider createProvider() throws UnsupportedBusNumberException, IOException {
    BigDecimal frequency = PCA9685GpioProvider.ANALOG_SERVO_FREQUENCY;
    BigDecimal frequencyCorrectionFactor = new BigDecimal("1.0578");

    I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
    return new PCA9685GpioProvider(bus, 0x40, frequency, frequencyCorrectionFactor);
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:8,代码来源:PCA9685GpioServoExample.java

示例14: LuxSensor

import com.pi4j.io.i2c.I2CFactory; //导入方法依赖的package包/类
/**
 * 
 * @param addr I2C hardware address of the device. For us that's 0x39
 * @throws IOException If there is a hardware I/O error
 * @throws com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException If bus number is invalid
 * @throws InterruptedException If thread fails to sleep.
 */
public LuxSensor(byte addr)
        throws IOException, I2CFactory.UnsupportedBusNumberException, InterruptedException {
    // Get i2c i2cBus
    // Number depends on RasPI version
    i2cBus = I2CFactory.getInstance(I2CBus.BUS_1);

    // Get device itself
    TSL2561 = i2cBus.getDevice(addr);

    // Initialize device by issuing command with data value 0x03        
    TSL2561.write(TSL2561_REG_CONTROL, TSL2561_POWER_UP);

}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:21,代码来源:LuxSensor.java

示例15: main

import com.pi4j.io.i2c.I2CFactory; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    System.out.println("Starting:");

    // get I2C bus instance
    final I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);

    WiiMotionPlus wiiMotionPlus = new WiiMotionPlus(bus);
    wiiMotionPlus.init();

    int iteration = 0;

    makeBackup("log.txt");

    FileWriter logFile = new FileWriter("log.txt");
    BufferedWriter bw = new BufferedWriter(logFile, 2048);
    PrintWriter log = new PrintWriter(bw);

    try {
        while (true) {
            long now = System.currentTimeMillis();
            ThreeAxis threeAxis = wiiMotionPlus.read();
            long lasted = System.currentTimeMillis() - now;

            System.out.print(formatInt(iteration));
            System.out.print(' ');

            System.out.print(formatLong(lasted));
            System.out.print(' ');

            System.out.print(formatInt(threeAxis.x));
            System.out.print(' ');

            System.out.print(formatInt(threeAxis.y));
            System.out.print(' ');

            System.out.print(formatInt(threeAxis.z));
            System.out.print(' ');

            // System.out.print('\r');
            System.out.println();

            log.println(formatInt(iteration) + "," + formatLong(lasted) + "," + formatInt(threeAxis.x) + "," + formatInt(threeAxis.y) + "," + formatInt(threeAxis.z));
            //log.flush();

            Thread.sleep(500);
            iteration = iteration + 1;
        }
    } finally {
        bw.flush();
        bw.close();
        logFile.close();
    }
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:57,代码来源:I2CWiiMotionPlusExample.java


注:本文中的com.pi4j.io.i2c.I2CFactory.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。