Skip to content

Commit

Permalink
trafficlight v1.0.2
Browse files Browse the repository at this point in the history
updated reamed.md
cleanup polling task
adapted app.properties keys
  • Loading branch information
SBAS committed Nov 6, 2024
1 parent 8dfc5fd commit d0164f4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# trafficlight
This small app is used to pilot a traffic-light signal mounted on an Arduino board.

It periodically polls a URL where an HTML page is refreshed according to integration test results. This web page provides simple text. (e.g. `Green:Off, Yellow:On, Red:On`). The status values can be On, Off, or Blinking.
This application is designed to control a traffic light signal mounted on an Arduino board.

This text is then parsed to create a new traffic-light model that will replace the current one. The different views reflect the model state. One of these views is responsible for sending a command to the Arduino board using serial port communication. GUI is a helper while developing to interact manually with the model and reflect its state. Most of the time, the app is running minimized in the tray icon.
## Overview

Then, the Arduino firmware will decode the command to turn on/off/blink the LEDs. This project is in direct relation with RedLight(https://github.com/ssenegas/RedLight) project.
The application periodically sends a GET request to a specified URL that hosts an HTML page reflecting the results of integration tests. This page provides simple text status updates for the traffic lights, such as `Green:Off, Yellow:On, Red:On`, where each color's status can be `On`, `Off`, or `Blinking`.

The response data is parsed into a `TrafficLight` object, which updates the application's model with the current status. This model is reflected across various views, with one view dedicated to sending commands to the Arduino board through serial communication. The GUI primarily serves as a development tool, allowing manual interaction with the model and displaying its state, though the app typically runs minimized in the system tray.

The Arduino firmware interprets commands from the application to control the LEDs' states (on/off/blink).

## Related Projects

This project directly relates to [RedLight](https://github.com/ssenegas/RedLight), which contains additional code and resources necessary for full functionality.

![image](https://github.com/ssenegas/trafficlight/assets/9662172/ac1c9416-7c4d-4277-b4eb-d46e34ebe32e)
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ application {
}

group = 'org.senegas'
version = '1.0.1'
version = '1.0.2'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TrafficLightApp {
public static final String TITLE = "Traffic Light App";
//TODO
// // see https://stackoverflow.com/questions/33020069/how-to-get-version-attribute-from-a-gradle-build-to-be-included-in-runtime-swing
public static final String VERSION = "1.0.1";
public static final String VERSION = "1.0.2";

public static void main(String[] args) {
EventQueue.invokeLater(() -> new TrafficLightApp().create());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ private JSpinner addSpinner(Container c) {

private class PollingLightURLTask extends TimerTask {

@Override
private static final String INFO_URL_LIGHT_KEY = "info.url.light";
private static final String FOUR_LETTER_CODE_KEY = "4lc";
private static final String DEFAULT_URL = "https://info.swiss-as.com/light.txt";

@Override
public void run() {
pollURL();
}
Expand Down Expand Up @@ -186,9 +190,10 @@ private void synchronizeGUIToModel() {
}

private String getLightURL() {
String lightURL = TrafficLightController.this.appProps.getProperty("info.swiss-as.com.light");
if (TrafficLightController.this.appProps.getProperty("4lc") != null) {
lightURL = TrafficLightController.this.appProps.getProperty("info.swiss-as.com.light") + TrafficLightController.this.appProps.getProperty("4lc");
String lightURL = TrafficLightController.this.appProps.getProperty(INFO_URL_LIGHT_KEY, DEFAULT_URL);
String letterCode = TrafficLightController.this.appProps.getProperty(FOUR_LETTER_CODE_KEY);
if (letterCode != null) {
lightURL += "?user="+letterCode;
}
return lightURL;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/app.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
info.swiss-as.com.light=http://localhost:8080/examples/light.txt
4lc=
info.url.light=https://info.swiss-as.com/light.txt
4lc=sbas

0 comments on commit d0164f4

Please sign in to comment.