Skip to content

Commit

Permalink
Add debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
FDelporte committed Jun 10, 2024
1 parent 7578e3a commit b22309e
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class Pi4JService {
private static final Logger logger = LoggerFactory.getLogger(Pi4JService.class);
private static final int PIN_LED = 22; // PIN 15 = BCM 22
private static final int PIN_BUTTON = 24; // PIN 18 = BCM 24
private final DigitalOutput led;
private final DigitalInput button;
private final LcdDisplay lcd;
private DigitalOutput led = null;
private DigitalInput button = null;
private LcdDisplay lcd = null;

public Pi4JService(@Autowired Context pi4j) {
try {
Expand Down Expand Up @@ -56,6 +56,11 @@ private void handleButtonChange(DigitalStateChangeEvent e) {
}

public boolean setLedState(Boolean state) {
if (led == null) {
logger.error("LED is not initialized");
return false;
}

try {
led.state(state ? DigitalState.HIGH : DigitalState.LOW);
logger.info("LED state is set to {}", state);
Expand All @@ -66,7 +71,21 @@ public boolean setLedState(Boolean state) {
return false;
}

public DigitalState getButtonState() {
if (button == null) {
logger.error("Button is not initialized");
return DigitalState.LOW;
}

return button.state();
}

public boolean setLcdText(Integer line, String text) {
if (lcd == null) {
logger.error("LCD is not initialized");
return false;
}

try {
lcd.displayLineOfText(text, line);
logger.info("LCD text on line {} is set to {}", line, text);
Expand All @@ -76,8 +95,4 @@ public boolean setLcdText(Integer line, String text) {
}
return false;
}

public DigitalState getButtonState() {
return button.state();
}
}

0 comments on commit b22309e

Please sign in to comment.