• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java I2CDevice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.pi4j.io.i2c.I2CDevice的典型用法代码示例。如果您正苦于以下问题:Java I2CDevice类的具体用法?Java I2CDevice怎么用?Java I2CDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



I2CDevice类属于com.pi4j.io.i2c包,在下文中一共展示了I2CDevice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
}
 
开发者ID:weiss19ja,项目名称:amos-ss16-proj2,代码行数:21,代码来源:DriveControllerImpl.java


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


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


示例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;
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:27,代码来源:RasPi.java


示例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;
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:17,代码来源:RasPi.java


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


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

}
 
开发者ID:Robo4J,项目名称:robo4j-rpi-ard-tank-example,代码行数:10,代码来源:TankUtil.java


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


示例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;
	}
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:9,代码来源:WiringPiI2CDevice.java


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


示例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;
	}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:36,代码来源:RasPi.java


示例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);
	}
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:15,代码来源:RasPi.java


示例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;
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:31,代码来源:Module.java


示例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);
}
 
开发者ID:starksm64,项目名称:RaspberryPi,代码行数:13,代码来源:PiGlowTests.java


示例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);
}
 
开发者ID:starksm64,项目名称:RaspberryPi,代码行数:16,代码来源:PiGlowTests.java


示例16: set_led

import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
/**
 *
 * @param device
 * @param led
 * @param intensity
 * @throws IOException
 */
static void set_led(I2CDevice device, int led, byte intensity) throws IOException {
   byte[] values = new byte[LED_COUNT];
   Arrays.fill(values, (byte)0);
   values[led] = intensity;
   device.write(CMD_SET_PWM_VALUES, values, 0, values.length);
   device.write(CMD_UPDATE, ff);
}
 
开发者ID:starksm64,项目名称:RaspberryPi,代码行数:15,代码来源:PiGlowTests.java


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


示例18: create

import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public static Optional<NodeController> create(int busNum, int address) {
  try {
    I2CBus bus = I2CFactory.getInstance(busNum);
    LOG.info("Connected to I2C bus.");

    I2CDevice device = bus.getDevice(address);
    LOG.info("Connected to device");
    return Optional.of(new HTU21DControllerImpl(bus, device));
  } catch (IOException e) {
    LOG.error("Cannot create I2C temp sensor controller.", e);
  }
  return Optional.empty();
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:14,代码来源:HTU21DControllerImpl.java


示例19: getLsm9ds1

import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public I2CDevice getLsm9ds1() {
	return lsm9ds1;
}
 
开发者ID:soblenes32,项目名称:LSM9DS1-Pi4j-Driver,代码行数:4,代码来源:Driver.java


示例20: setLsm9ds1

import com.pi4j.io.i2c.I2CDevice; //导入依赖的package包/类
public void setLsm9ds1(I2CDevice lsm9ds1) {
	this.lsm9ds1 = lsm9ds1;
}
 
开发者ID:soblenes32,项目名称:LSM9DS1-Pi4j-Driver,代码行数:4,代码来源:Driver.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MetricsTimeVaryingLong类代码示例发布时间:2022-05-21
下一篇:
Java SendResult类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap