本文整理汇总了Java中com.google.android.things.pio.PeripheralManagerService.openSpiDevice方法的典型用法代码示例。如果您正苦于以下问题:Java PeripheralManagerService.openSpiDevice方法的具体用法?Java PeripheralManagerService.openSpiDevice怎么用?Java PeripheralManagerService.openSpiDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.things.pio.PeripheralManagerService
的用法示例。
在下文中一共展示了PeripheralManagerService.openSpiDevice方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LedControl
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
public LedControl(String spiGpio) throws IOException {
PeripheralManagerService pioService = new PeripheralManagerService();
spiDevice = pioService.openSpiDevice(spiGpio);
spiDevice.setMode(SpiDevice.MODE0);
spiDevice.setFrequency(1000000); // 1MHz
spiDevice.setBitsPerWord(8); // 8 BPW
spiDevice.setBitJustification(false); // MSB first
spiTransfer(OP_DECODEMODE, 0); // decoding: BCD
setScanLimit(7); // scanlimit: 8 LEDs
spiTransfer(OP_DISPLAYTEST, 0);
shutdown(false);
setIntensity(3);
clearDisplay();
}
示例2: LedControl
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
public LedControl(String spiGpio, int numDevices) throws IOException {
PeripheralManagerService pioService = new PeripheralManagerService();
spiDevice = pioService.openSpiDevice(spiGpio);
spiDevice.setMode(SpiDevice.MODE0);
spiDevice.setFrequency(1000000); // 1MHz
spiDevice.setBitsPerWord(8); // 8 BPW
spiDevice.setBitJustification(false); // MSB first
maxDevices = numDevices;
if (numDevices < 1 || numDevices > 8) {
maxDevices = 8;
}
for (int i = 0; i < maxDevices; i++) {
spiTransfer(i, OP_DISPLAYTEST, 0);
setScanLimit(i, 7); // scanlimit: 8 LEDs
spiTransfer(i, OP_DECODEMODE, 0); // decoding: BCD
clearDisplay(i);
// we go into shutdown-mode on startup
shutdown(i, true);
}
}
示例3: Apa102
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* Create a new Apa102 driver.
*
* @param spiBusPort Name of the SPI bus
* @param ledMode The {@link Mode} indicating the red/green/blue byte ordering for the device.
* @param direction The {@link Direction} or the led strip.
*/
public Apa102(String spiBusPort, Mode ledMode, Direction direction) throws IOException {
mLedMode = ledMode;
mDirection = direction;
PeripheralManagerService pioService = new PeripheralManagerService();
mDevice = pioService.openSpiDevice(spiBusPort);
try {
configure(mDevice);
} catch (IOException|RuntimeException e) {
try {
close();
} catch (IOException|RuntimeException ignored) {
}
throw e;
}
}
示例4: TM1838Driver
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* Setup and initialize object using SPI device (MOSI pulled up to MISO by 1K resistor)
* @param spiDeviceName
* @param brightness desired display brightness 0-7
* @throws IOException
*/
public TM1838Driver(@NonNull String spiDeviceName, int brightness) throws IOException {
PeripheralManagerService service = new PeripheralManagerService();
spiDevice = service.openSpiDevice(spiDeviceName);
spiDevice.setMode(SpiDevice.MODE3);
spiDevice.setFrequency(16000000); // 16MHz
spiDevice.setDelay(80);
spiDevice.setBitsPerWord(8); // 8 BPW
spiDevice.setBitJustification(false); // MSB first
spiDevice.setCsChange(false);
init(brightness);
}
示例5: onCreate
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTagDetectedView = (TextView)findViewById(R.id.tag_read);
mTagUidView = (TextView)findViewById(R.id.tag_uid);
mTagResultsView = (TextView) findViewById(R.id.tag_results);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mRfidTask = new RfidTask(mRc522);
mRfidTask.execute();
((Button)v).setText(R.string.reading);
}
});
PeripheralManagerService pioService = new PeripheralManagerService();
try {
spiDevice = pioService.openSpiDevice(SPI_PORT);
gpioReset = pioService.openGpio(PIN_RESET);
mRc522 = new Rc522(spiDevice, gpioReset);
mRc522.setDebugging(true);
} catch (IOException e) {
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
示例6: Adxl362
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
public Adxl362(String spiPort) throws IOException {
PeripheralManagerService service = new PeripheralManagerService();
device = service.openSpiDevice(spiPort);
connfigureSpi(device);
}
示例7: Adxl362
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* Creates a new SpiDevice instance
* @param spiPort - can be either SPI0.0 or SPI0.1 (for Raspberry Pi)
* @param frequencyInHz - This will vary according to the peripheral to be interfaced, default should be 1MHz.
* ADXL362 has a range of 1MHz to 8MHz
* @param mode - Modes are MODE_0, MODE_1, MODE_2, MODE_3.
* ADXL362 works on MODE_0
* @throws IOException
*/
public Adxl362(String spiPort, int frequencyInHz, int mode) throws IOException {
PeripheralManagerService service = new PeripheralManagerService();
device = service.openSpiDevice(spiPort);
connfigureSpi(device, frequencyInHz, mode);
}