examples: make main loops finite to ensure proper cleanup
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
32340f6819
commit
c36e4add5a
@@ -44,11 +44,12 @@ public class AioA0 {
|
||||
public static void main(String[] args) {
|
||||
Aio a0 = new Aio(0);
|
||||
|
||||
while (true) {
|
||||
for (int i = 100; i > 0; --i) {
|
||||
int adc_value = a0.read();
|
||||
float adc_value_float = a0.readFloat();
|
||||
System.out.println(String.format("ADC A0 read %X - %d", adc_value, adc_value));
|
||||
System.out.println(String.format("ADC A0 read %.5f", adc_value_float));
|
||||
Thread.sleep(500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class BlinkIO {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
for (int i = 100; i > 0; --i) {
|
||||
gpio.write(1);
|
||||
Thread.sleep(1000);
|
||||
gpio.write(0);
|
||||
|
||||
@@ -64,7 +64,7 @@ public class BlinkOnboard {
|
||||
}
|
||||
|
||||
boolean state = false;
|
||||
while (true) {
|
||||
for (int i = 100; i > 0; --i) {
|
||||
if (gpio_in != null && gpio_in.read() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CyclePwm3 {
|
||||
pwm.enable(true);
|
||||
|
||||
float value = 0;
|
||||
while (true) {
|
||||
for (int i = 100; i > 0; --i) {
|
||||
value += 0.01;
|
||||
pwm.write(value);
|
||||
Thread.sleep(50);
|
||||
|
||||
@@ -50,8 +50,8 @@ public class FTDITest {
|
||||
/* Blink FTDI board LED */
|
||||
Gpio led = new Gpio(514);
|
||||
led.dir(Dir.DIR_OUT);
|
||||
for (int i = 0;; i = (i + 1) % 2) {
|
||||
led.write(i);
|
||||
for (int i = 100; i > 0; --i) {
|
||||
led.write(i % 2);
|
||||
Thread.sleep(500);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class GpioMmapped {
|
||||
|
||||
gpio.useMmap(true);
|
||||
|
||||
while (true) {
|
||||
for (int i = 1000; i > 0; --i) {
|
||||
gpio.write(1);
|
||||
Thread.sleep(50);
|
||||
gpio.write(0);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class GpioRead6 {
|
||||
|
||||
gpio.dir(Dir.DIR_IN);
|
||||
|
||||
while (true) {
|
||||
for (int i = 100; i > 0; --i) {
|
||||
System.out.format("Gpio is %d\n", gpio.read());
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public class I2cCompass {
|
||||
conf_buf[1] = HMC5883L_CONT_MODE;
|
||||
i2c.write(conf_buf);
|
||||
|
||||
while (true) {
|
||||
for (int i = 100; i > 0; --i) {
|
||||
i2c.address(HMC5883L_I2C_ADDR);
|
||||
i2c.writeByte(HMC5883L_DATA_REG);
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SpiMCP4261 {
|
||||
|
||||
System.out.println("Hello, SPI initialised");
|
||||
byte data[] = {0x00, 100};
|
||||
while (true) {
|
||||
for (int cnt = 100; cnt > 0; --cnt) {
|
||||
for (int i = 90; i < 130; i++) {
|
||||
data[1] = (byte) i;
|
||||
byte[] recv = spi.write(data);
|
||||
|
||||
Reference in New Issue
Block a user