Skip to content

Commit

Permalink
[69] robo4j-hw-rpi logger update
Browse files Browse the repository at this point in the history
  • Loading branch information
mirage22 committed Oct 7, 2024
1 parent b450f38 commit afe22c5
Show file tree
Hide file tree
Showing 54 changed files with 3,465 additions and 3,523 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,55 @@
*/
package com.robo4j.hw.rpi.i2c.accelerometer;

import java.io.IOException;

import com.robo4j.hw.rpi.i2c.ReadableDevice;
import com.robo4j.math.geometry.Tuple3f;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
* Example useful to check if your accelerometer is working properly.
*
*
* @author Marcus Hirt (@hirt)
* @author Miroslav Wengner (@miragemiko)
*/
public class AccelerometerLSM303Test {
public static void main(String[] args) throws IOException, InterruptedException {
ReadableDevice<Tuple3f> device = new AccelerometerLSM303Device();
getReading(device, "Place the device in the position(s) you want to measure");
}
private static final Logger LOGGER = LoggerFactory.getLogger(AccelerometerLSM303Test.class);

public static void main(String[] args) throws IOException, InterruptedException {
ReadableDevice<Tuple3f> device = new AccelerometerLSM303Device();
getReading(device, "Place the device in the position(s) you want to measure");
}

private static void getReading(ReadableDevice<Tuple3f> device, String message)
throws IOException, InterruptedException {
prompt(message);
print(readValues(device));
}
private static void getReading(ReadableDevice<Tuple3f> device, String message)
throws IOException, InterruptedException {
prompt(message);
print(readValues(device));
}

private static void print(Stats stats) {
System.out.println("Result:");
System.out.println(stats);
}
private static void print(Stats stats) {
LOGGER.debug("Result:{}", stats);
}

private static void prompt(String msg) throws IOException {
System.out.println(msg);
System.out.println("Press <Enter> to continue!");
System.in.read();
}
private static void prompt(String msg) throws IOException {
LOGGER.debug(msg);
LOGGER.debug("Press <Enter> to continue!");
System.in.read();
}

private static Stats readValues(ReadableDevice<Tuple3f> device) throws IOException, InterruptedException {
// TODO: change print...
Stats stats = new Stats();
for (int i = 0; i < 250; i++) {
Tuple3f fl = device.read();
stats.addValue(fl);
Thread.sleep(20);
if (i % 25 == 0) {
System.out.print(".");
}
}
System.out.println("");
return stats;
}
private static Stats readValues(ReadableDevice<Tuple3f> device) throws IOException, InterruptedException {
// TODO: change print...
Stats stats = new Stats();
for (int i = 0; i < 250; i++) {
Tuple3f fl = device.read();
stats.addValue(fl);
Thread.sleep(20);
if (i % 25 == 0) {
LOGGER.debug(".");
}
}
LOGGER.debug("");
return stats;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package com.robo4j.hw.rpi.i2c.adafruitbackpack;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
Expand All @@ -26,18 +29,20 @@
* @author Miroslav Wengner (@miragemiko)
*/
public class AlphanumericDeviceExample {
public static void main(String[] args) throws Exception {
System.out.println("=== Alphanumeric Backpack Example ===");

AlphanumericDevice device = new AlphanumericDevice();
device.clear();
device.display();
System.out.println("Adding Characters");
device.addCharacter('A', false);
device.addCharacter('B', true);
device.addCharacter('C', false);
device.addCharacter('D', true);
device.display();
private static final Logger LOGGER = LoggerFactory.getLogger(AlphanumericDeviceExample.class);

public static void main(String[] args) throws Exception {
LOGGER.debug("=== Alphanumeric Backpack Example ===");

AlphanumericDevice device = new AlphanumericDevice();
device.clear();
device.display();
LOGGER.debug("Adding Characters");
device.addCharacter('A', false);
device.addCharacter('B', true);
device.addCharacter('C', false);
device.addCharacter('D', true);
device.display();
TimeUnit.SECONDS.sleep(3);
device.clear();
device.display();
Expand All @@ -48,10 +53,10 @@ public static void main(String[] args) throws Exception {
device.display();


System.out.println("Press <Enter> to quit!");
LOGGER.debug("Press <Enter> to quit!");
System.in.read();
device.clear();
device.display();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,54 @@

package com.robo4j.hw.rpi.i2c.adafruitbackpack;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
* Simple example of using Adafruit BiColor Bargraph {@link BiColor24BarDevice}
*
*
* @author Marcus Hirt (@hirt)
* @author Miroslav Wengner (@miragemiko)
*/
public class BiColor24BargraphExample {
private static final Logger LOGGER = LoggerFactory.getLogger(BiColor24BargraphExample.class);

public static void main(String[] args) throws Exception {
System.out.println("=== Bi-BiColor 24 Bargraph ===");
public static void main(String[] args) throws Exception {
LOGGER.debug("=== Bi-BiColor 24 Bargraph ===");

BiColor24BarDevice device = new BiColor24BarDevice();
device.clear();
device.display();
BiColor24BarDevice device = new BiColor24BarDevice();
device.clear();
device.display();

for (int i = 0; i < device.getMaxBar(); i++) {
device.setBar(i, BiColor.GREEN);
device.display();
TimeUnit.MILLISECONDS.sleep(200);
}
for (int i = 0; i < device.getMaxBar(); i++) {
device.setBar(i, BiColor.GREEN);
device.display();
TimeUnit.MILLISECONDS.sleep(200);
}

for (int i = device.getMaxBar() - 1; i >= 0; i--) {
device.setBar(i, BiColor.OFF);
device.display();
TimeUnit.MILLISECONDS.sleep(100);
}
for (int i = device.getMaxBar() - 1; i >= 0; i--) {
device.setBar(i, BiColor.OFF);
device.display();
TimeUnit.MILLISECONDS.sleep(100);
}

int counter = 0;
while (counter < 3) {
for (int i = 0; i < 12; i++) {
int colorNumber = (i + counter) % 3 + 1;
device.setBar(i, BiColor.getByValue(colorNumber));
TimeUnit.MILLISECONDS.sleep(200);
device.display();
}
counter++;
}
int counter = 0;
while (counter < 3) {
for (int i = 0; i < 12; i++) {
int colorNumber = (i + counter) % 3 + 1;
device.setBar(i, BiColor.getByValue(colorNumber));
TimeUnit.MILLISECONDS.sleep(200);
device.display();
}
counter++;
}

System.out.println("Press <Enter> to quit!");
System.in.read();
device.clear();
device.display();
}
LOGGER.debug("Press <Enter> to quit!");
System.in.read();
device.clear();
device.display();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package com.robo4j.hw.rpi.i2c.adafruitbackpack;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
Expand All @@ -26,35 +29,36 @@
* @author Miroslav Wengner (@miragemiko)
*/
public class BiColor8x8MatrixExample {
private static final Logger LOGGER = LoggerFactory.getLogger(BiColor8x8MatrixExample.class);

public static void main(String[] args) throws Exception {
LOGGER.debug("=== BiColor 8x8 Matrix Example ===");

BiColor8x8MatrixDevice matrix = new BiColor8x8MatrixDevice();
matrix.clear();
matrix.display();

MatrixRotation[] rotations = {MatrixRotation.DEFAULT_X_Y, MatrixRotation.RIGHT_90, MatrixRotation.RIGHT_180,
MatrixRotation.RIGHT_270, MatrixRotation.LEFT_90};
for (MatrixRotation rotation : rotations) {
matrix.setRotation(rotation);
matrix.drawPixel(0, 0, BiColor.RED);
matrix.drawPixel(1, 0, BiColor.GREEN);
matrix.drawPixel(2, 0, BiColor.YELLOW);
matrix.drawPixel(3, 0, BiColor.RED);
matrix.drawPixel(0, 1, BiColor.GREEN);
matrix.drawPixel(0, 2, BiColor.YELLOW);
matrix.drawPixel(7, 7, BiColor.GREEN);
matrix.drawPixel(7, 6, BiColor.GREEN);
matrix.display();
TimeUnit.SECONDS.sleep(1);
matrix.clear();
}

LOGGER.debug("Press <Enter> to quit!");
System.in.read();
matrix.clear();
matrix.display();

public static void main(String[] args) throws Exception {
System.out.println("=== BiColor 8x8 Matrix Example ===");

BiColor8x8MatrixDevice matrix = new BiColor8x8MatrixDevice();
matrix.clear();
matrix.display();

MatrixRotation[] rotations = { MatrixRotation.DEFAULT_X_Y, MatrixRotation.RIGHT_90, MatrixRotation.RIGHT_180,
MatrixRotation.RIGHT_270, MatrixRotation.LEFT_90 };
for (MatrixRotation rotation : rotations) {
matrix.setRotation(rotation);
matrix.drawPixel(0, 0, BiColor.RED);
matrix.drawPixel(1, 0, BiColor.GREEN);
matrix.drawPixel(2, 0, BiColor.YELLOW);
matrix.drawPixel(3, 0, BiColor.RED);
matrix.drawPixel(0, 1, BiColor.GREEN);
matrix.drawPixel(0, 2, BiColor.YELLOW);
matrix.drawPixel(7, 7, BiColor.GREEN);
matrix.drawPixel(7, 6, BiColor.GREEN);
matrix.display();
TimeUnit.SECONDS.sleep(1);
matrix.clear();
}

System.out.println("Press <Enter> to quit!");
System.in.read();
matrix.clear();
matrix.display();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package com.robo4j.hw.rpi.i2c.adafruitbackpack;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -28,31 +31,32 @@
* @author Miroslav Wengner (@miragemiko)
*/
public class BiColor8x8MatrixFaceExample {
private static final Logger LOGGER = LoggerFactory.getLogger(BiColor8x8MatrixFaceExample.class);

public static void main(String[] args) throws Exception {
System.out.println("=== BiColor 8x8 Matrix Face Example ===");
public static void main(String[] args) throws Exception {
LOGGER.debug("=== BiColor 8x8 Matrix Face Example ===");

BiColor8x8MatrixDevice led = new BiColor8x8MatrixDevice();
BiColor8x8MatrixDevice led = new BiColor8x8MatrixDevice();

char[] faceSmile = "00333300,03000030,30300303,30000003,30300303,30033003,03000030,00333300".toCharArray();
char[] faceNeutral = "00222200,02000020,20200202,20000002,20222202,20000002,02000020,00222200".toCharArray();
char[] faceSad = "00111100,01000010,10100101,10000001,10011001,10100101,01000010,00111100".toCharArray();
char[] faceSmile = "00333300,03000030,30300303,30000003,30300303,30033003,03000030,00333300".toCharArray();
char[] faceNeutral = "00222200,02000020,20200202,20000002,20222202,20000002,02000020,00222200".toCharArray();
char[] faceSad = "00111100,01000010,10100101,10000001,10011001,10100101,01000010,00111100".toCharArray();

List<char[]> availableFaces = Arrays.asList(faceSad, faceNeutral, faceSmile);
List<char[]> availableFaces = Arrays.asList(faceSad, faceNeutral, faceSmile);

for (char[] face : availableFaces) {
led.clear();
led.display();
byte[] faceBytes = LedBackpackUtils.createMatrixBiColorArrayByCharSequence(led.getWidth(), ',', face);
LedBackpackUtils.paintByBiColorByteArray(led, faceBytes);
led.display();
TimeUnit.SECONDS.sleep(1);
}
for (char[] face : availableFaces) {
led.clear();
led.display();
byte[] faceBytes = LedBackpackUtils.createMatrixBiColorArrayByCharSequence(led.getWidth(), ',', face);
LedBackpackUtils.paintByBiColorByteArray(led, faceBytes);
led.display();
TimeUnit.SECONDS.sleep(1);
}

System.out.println("Press <Enter> to quit!");
System.in.read();
led.clear();
led.display();
LOGGER.debug("Press <Enter> to quit!");
System.in.read();
led.clear();
led.display();

}
}
}
Loading

0 comments on commit afe22c5

Please sign in to comment.