From 601eb00627c0bd22ba80347a11c26209ea6fa9b5 Mon Sep 17 00:00:00 2001 From: Benjamin Rodriguez Date: Thu, 11 Jan 2024 23:22:19 -0600 Subject: [PATCH 1/5] - Fix log4j vulnerability. - Add ability to run examples on Windows command line. - Ignore log files. --- .gitignore | 2 ++ blink1-java-examples/pom.xml | 12 ++++++++++++ blink1-library/pom.xml | 24 ++++++++++++++++++++++-- blink1-processing-examples/pom.xml | 10 ++++++++++ run-example.bat | 6 ++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 run-example.bat diff --git a/.gitignore b/.gitignore index d2f6220..b3af069 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ build target .idea *.iml + +*.log \ No newline at end of file diff --git a/blink1-java-examples/pom.xml b/blink1-java-examples/pom.xml index ef18240..46e54b5 100644 --- a/blink1-java-examples/pom.xml +++ b/blink1-java-examples/pom.xml @@ -32,5 +32,17 @@ blink1-java-examples + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 11 + 11 + 11 + + + \ No newline at end of file diff --git a/blink1-library/pom.xml b/blink1-library/pom.xml index 35affe7..f3aaaee 100644 --- a/blink1-library/pom.xml +++ b/blink1-library/pom.xml @@ -31,18 +31,38 @@ net.java.dev.jna jna - 5.6.0 + 5.14.0 net.java.dev.jna jna-platform - 5.6.0 + 5.14.0 + + + org.apache.logging.log4j + log4j-1.2-api + 2.20.0 + + + org.apache.logging.log4j + log4j-core + 2.20.0 blink1-library + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 11 + 11 + 11 + + org.apache.maven.plugins maven-assembly-plugin diff --git a/blink1-processing-examples/pom.xml b/blink1-processing-examples/pom.xml index 44d9771..0cdef48 100644 --- a/blink1-processing-examples/pom.xml +++ b/blink1-processing-examples/pom.xml @@ -59,6 +59,16 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 11 + 11 + 11 + + \ No newline at end of file diff --git a/run-example.bat b/run-example.bat new file mode 100644 index 0000000..b094d86 --- /dev/null +++ b/run-example.bat @@ -0,0 +1,6 @@ +@echo off + +java ^ + -Djava.awt.headless=true ^ + -cp blink1-library\target\blink1-library-jar-with-dependencies.jar;.\blink1-java-examples\target\blink1-java-examples.jar ^ + com.thingm.blink1.%1 %2 %3 %4 From e68c44954cc4db900f3900627ae73a4c1b71e812 Mon Sep 17 00:00:00 2001 From: Benjamin Rodriguez Date: Thu, 11 Jan 2024 23:28:10 -0600 Subject: [PATCH 2/5] Add ability to use hex codes for setting color. --- .../java/com/thingm/blink1/OnOffColor.java | 19 ++++++ .../main/java/com/thingm/blink1/Blink1.java | 66 +++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/blink1-java-examples/src/main/java/com/thingm/blink1/OnOffColor.java b/blink1-java-examples/src/main/java/com/thingm/blink1/OnOffColor.java index 4a08dc2..826d502 100644 --- a/blink1-java-examples/src/main/java/com/thingm/blink1/OnOffColor.java +++ b/blink1-java-examples/src/main/java/com/thingm/blink1/OnOffColor.java @@ -11,6 +11,8 @@ public static void main(String[] args) { if (args.length == 0) { outputMessage("Turning off blink1."); blink1.off(); + } else if (args.length == 1) { + setHex(blink1, args); } else { setColor(blink1, args); } @@ -37,6 +39,23 @@ private static void setColor(Blink1 blink1, String[] args) { } } + private static void setHex(Blink1 blink1, String[] args) { + if (args == null || args.length != 1) { + exitError("Pass in a hex color code. Ex: FF2333, #FF2333"); + } + + try { + String hexCode = args[0]; + outputMessage(String.format("Setting HEX(%s) on blink1", hexCode)); + blink1.setHex(hexCode); + } catch (NumberFormatException nfe) { + exitError(String.format( + "The hex value (%s) is invalid. %s", + args[0], nfe.getMessage() + )); + } + } + private static void outputMessage(String msg) { System.out.println(msg); } diff --git a/blink1-library/src/main/java/com/thingm/blink1/Blink1.java b/blink1-library/src/main/java/com/thingm/blink1/Blink1.java index b4e8069..cd5bcb6 100644 --- a/blink1-library/src/main/java/com/thingm/blink1/Blink1.java +++ b/blink1-library/src/main/java/com/thingm/blink1/Blink1.java @@ -80,6 +80,17 @@ public int setColor(Color c) { return this.setRGB( c.getRed(), c.getGreen(), c.getBlue() ); } + /** + * Set blink(1) color immediately. + * + * @param hexCode Color to set in hex + * @returns blink1_command response code, -1 == fail + */ + public int setHex(String hexCode) { + Color c = convertToRgb(hexCode); + return this.setRGB( c.getRed(), c.getGreen(), c.getBlue() ); + } + /** * Get last color sent (current color * @return The current color of the device as int, or <0 on error @@ -166,6 +177,32 @@ public int fadeToRGB(int fadeMillis, Color c, int ledn) { return fadeToRGB( fadeMillis, c.getRed(), c.getGreen(), c.getBlue(), ledn ); } + + /** + * Fade blink(1) to HEX color over fadeMillis milliseconds. + * + * @param fadeMillis milliseconds to take to get to color + * @param hexCode Color to set in hex + * @returns blink1_command response code, -1 == fail + */ + public int fadeToHex(int fadeMillis, String hexCode) { + Color c = convertToRgb(hexCode); + return fadeToRGB( fadeMillis, c.getRed(), c.getGreen(), c.getBlue() ); + } + + /** + * Fade blink(1) to HEX color over fadeMillis milliseconds. + * + * @param fadeMillis milliseconds to take to get to color + * @param hexCode Color to set in hex + * @param ledn which LED to address (0=all) + * @returns blink1_command response code, -1 == fail + */ + public int fadeToHex(int fadeMillis, String hexCode, int ledn) { + Color c = convertToRgb(hexCode); + return fadeToRGB( fadeMillis, c.getRed(), c.getGreen(), c.getBlue(), ledn ); + } + /** * Play internal color pattern * @param start pattern line to start from @@ -396,6 +433,35 @@ public int getPatternLineMaxCount() { // Utilty Class methods //------------------------------------------------------------------------- + /** + * Convert HTML/hex color code to RGB colors. Currently only supports 6 digit color codes. + */ + + public static Color convertToRgb(String hexCode) { + if (hexCode == null) { + throw new NumberFormatException("Missing hex color code"); + } + + if(hexCode.startsWith("#")){ + hexCode = hexCode.replace("#",""); + } + + if (hexCode.length() != 6) { + throw new NumberFormatException("Bad hex color code"); + } + + int red = Integer.valueOf(hexCode.substring(0, 2), 16); + int green = Integer.valueOf(hexCode.substring(2, 4), 16); + int blue = Integer.valueOf(hexCode.substring(4, 6), 16); + + if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) { + throw new NumberFormatException("Bad hex color code"); + } + + Color color = new Color(red,green,blue); + return color; + } + /** * one attempt at a degamma curve. */ From 7be22ad2f8471e085612307e573cfaade3adb54d Mon Sep 17 00:00:00 2001 From: Benjamin Rodriguez Date: Tue, 2 Apr 2024 13:19:22 -0500 Subject: [PATCH 3/5] Add scripts for changing color based on a status. - `stat_available.bat` set to color green. - `stat_busy.bat` set to color blue. - `stat_dnd.bat` set to color red. - `stat_gone.bat` turn color off. Add script for setting the color without specifying the OnOffColor class. --- scripts/run-set-color.bat | 6 ++++++ scripts/stat_available.bat | 6 ++++++ scripts/stat_busy.bat | 6 ++++++ scripts/stat_dnd.bat | 6 ++++++ scripts/stat_gone.bat | 6 ++++++ 5 files changed, 30 insertions(+) create mode 100644 scripts/run-set-color.bat create mode 100644 scripts/stat_available.bat create mode 100644 scripts/stat_busy.bat create mode 100644 scripts/stat_dnd.bat create mode 100644 scripts/stat_gone.bat diff --git a/scripts/run-set-color.bat b/scripts/run-set-color.bat new file mode 100644 index 0000000..943d2bf --- /dev/null +++ b/scripts/run-set-color.bat @@ -0,0 +1,6 @@ +@echo off + +java ^ + -Djava.awt.headless=true ^ + -cp ..\blink1-library\target\blink1-library-jar-with-dependencies.jar;..\blink1-java-examples\target\blink1-java-examples.jar ^ + com.thingm.blink1.OnOffColor %1 %2 %3 %4 diff --git a/scripts/stat_available.bat b/scripts/stat_available.bat new file mode 100644 index 0000000..ff10e00 --- /dev/null +++ b/scripts/stat_available.bat @@ -0,0 +1,6 @@ +@echo off + +java ^ + -Djava.awt.headless=true ^ + -cp ..\blink1-library\target\blink1-library-jar-with-dependencies.jar;..\blink1-java-examples\target\blink1-java-examples.jar ^ + com.thingm.blink1.OnOffColor 00ff00 \ No newline at end of file diff --git a/scripts/stat_busy.bat b/scripts/stat_busy.bat new file mode 100644 index 0000000..2d1f793 --- /dev/null +++ b/scripts/stat_busy.bat @@ -0,0 +1,6 @@ +@echo off + +java ^ + -Djava.awt.headless=true ^ + -cp ..\blink1-library\target\blink1-library-jar-with-dependencies.jar;..\blink1-java-examples\target\blink1-java-examples.jar ^ + com.thingm.blink1.OnOffColor 0000ff \ No newline at end of file diff --git a/scripts/stat_dnd.bat b/scripts/stat_dnd.bat new file mode 100644 index 0000000..da4a2e3 --- /dev/null +++ b/scripts/stat_dnd.bat @@ -0,0 +1,6 @@ +@echo off + +java ^ + -Djava.awt.headless=true ^ + -cp ..\blink1-library\target\blink1-library-jar-with-dependencies.jar;..\blink1-java-examples\target\blink1-java-examples.jar ^ + com.thingm.blink1.OnOffColor ff0000 \ No newline at end of file diff --git a/scripts/stat_gone.bat b/scripts/stat_gone.bat new file mode 100644 index 0000000..d4a81a9 --- /dev/null +++ b/scripts/stat_gone.bat @@ -0,0 +1,6 @@ +@echo off + +java ^ + -Djava.awt.headless=true ^ + -cp ..\blink1-library\target\blink1-library-jar-with-dependencies.jar;..\blink1-java-examples\target\blink1-java-examples.jar ^ + com.thingm.blink1.OnOffColor 000000 \ No newline at end of file From 32583e8d50bfbcb6dc88a7b840e9069f75c43833 Mon Sep 17 00:00:00 2001 From: Benjamin Rodriguez Date: Fri, 8 Nov 2024 12:59:14 -0600 Subject: [PATCH 4/5] - Update run scripts. - Add config file for run scripts. --- mvnw | 0 run-example.sh | 0 scripts/config.txt | 1 + scripts/stat_available.bat | 14 +++++++++++++- scripts/stat_busy.bat | 13 ++++++++++++- scripts/stat_current.bat | 5 +++++ scripts/stat_current_2.ps1 | 6 ++++++ scripts/stat_dnd.bat | 13 ++++++++++++- scripts/stat_gone.bat | 14 +++++++++++++- scripts/status_available.json | 3 +++ scripts/status_busy.json | 3 +++ scripts/status_current.json | 5 +++++ scripts/status_dnd.json | 3 +++ scripts/status_gone.json | 3 +++ 14 files changed, 79 insertions(+), 4 deletions(-) mode change 100755 => 100644 mvnw mode change 100755 => 100644 run-example.sh create mode 100644 scripts/config.txt create mode 100644 scripts/stat_current.bat create mode 100644 scripts/stat_current_2.ps1 create mode 100644 scripts/status_available.json create mode 100644 scripts/status_busy.json create mode 100644 scripts/status_current.json create mode 100644 scripts/status_dnd.json create mode 100644 scripts/status_gone.json diff --git a/mvnw b/mvnw old mode 100755 new mode 100644 diff --git a/run-example.sh b/run-example.sh old mode 100755 new mode 100644 diff --git a/scripts/config.txt b/scripts/config.txt new file mode 100644 index 0000000..e17cd89 --- /dev/null +++ b/scripts/config.txt @@ -0,0 +1 @@ +remotePostEnabled=false diff --git a/scripts/stat_available.bat b/scripts/stat_available.bat index ff10e00..dde6a73 100644 --- a/scripts/stat_available.bat +++ b/scripts/stat_available.bat @@ -1,6 +1,18 @@ @echo off +:: Read the config.txt file and set variables +for /f "tokens=1,2 delims== " %%A in (config.txt) do set %%A=%%B + java ^ -Djava.awt.headless=true ^ -cp ..\blink1-library\target\blink1-library-jar-with-dependencies.jar;..\blink1-java-examples\target\blink1-java-examples.jar ^ - com.thingm.blink1.OnOffColor 00ff00 \ No newline at end of file + com.thingm.blink1.OnOffColor 00ff00 + + +:: Use the variables in decisions +if "%remotePostEnabled%"=="true" ( + echo Remote post is enabled. + curl -X POST -H "Content-Type: application/json" -d @status_available.json -k https://servingnachos.com/status/stat.php +) else ( + echo Remote post is disabled. +) diff --git a/scripts/stat_busy.bat b/scripts/stat_busy.bat index 2d1f793..af3f692 100644 --- a/scripts/stat_busy.bat +++ b/scripts/stat_busy.bat @@ -1,6 +1,17 @@ @echo off +:: Read the config.txt file and set variables +for /f "tokens=1,2 delims== " %%A in (config.txt) do set %%A=%%B + java ^ -Djava.awt.headless=true ^ -cp ..\blink1-library\target\blink1-library-jar-with-dependencies.jar;..\blink1-java-examples\target\blink1-java-examples.jar ^ - com.thingm.blink1.OnOffColor 0000ff \ No newline at end of file + com.thingm.blink1.OnOffColor 0000ff + +:: Use the variables in decisions +if "%remotePostEnabled%"=="true" ( + echo Remote post is enabled. + curl -X POST -H "Content-Type: application/json" -d @status_busy.json -k https://servingnachos.com/status/stat.php +) else ( + echo Remote post is disabled. +) diff --git a/scripts/stat_current.bat b/scripts/stat_current.bat new file mode 100644 index 0000000..f187286 --- /dev/null +++ b/scripts/stat_current.bat @@ -0,0 +1,5 @@ +@@echo off + +curl -o status_current.json https://servingnachos.com/status/stat.php + +powershell.exe -file stat_current_2.ps1 \ No newline at end of file diff --git a/scripts/stat_current_2.ps1 b/scripts/stat_current_2.ps1 new file mode 100644 index 0000000..d60c56e --- /dev/null +++ b/scripts/stat_current_2.ps1 @@ -0,0 +1,6 @@ +$json = Get-Content -Path 'status_current.json' | ConvertFrom-Json +$json.color + +Write-Output $json.color + +Start-Process run-set-color.bat $json.color \ No newline at end of file diff --git a/scripts/stat_dnd.bat b/scripts/stat_dnd.bat index da4a2e3..5a5db04 100644 --- a/scripts/stat_dnd.bat +++ b/scripts/stat_dnd.bat @@ -1,6 +1,17 @@ @echo off +:: Read the config.txt file and set variables +for /f "tokens=1,2 delims== " %%A in (config.txt) do set %%A=%%B + java ^ -Djava.awt.headless=true ^ -cp ..\blink1-library\target\blink1-library-jar-with-dependencies.jar;..\blink1-java-examples\target\blink1-java-examples.jar ^ - com.thingm.blink1.OnOffColor ff0000 \ No newline at end of file + com.thingm.blink1.OnOffColor ff0000 + +:: Use the variables in decisions +if "%remotePostEnabled%"=="true" ( + echo Remote post is enabled. + curl -X POST -H "Content-Type: application/json" -d @status_dnd.json -k https://servingnachos.com/status/stat.php +) else ( + echo Remote post is disabled. +) diff --git a/scripts/stat_gone.bat b/scripts/stat_gone.bat index d4a81a9..9f9444a 100644 --- a/scripts/stat_gone.bat +++ b/scripts/stat_gone.bat @@ -1,6 +1,18 @@ @echo off +:: Read the config.txt file and set variables +for /f "tokens=1,2 delims== " %%A in (config.txt) do set %%A=%%B + java ^ -Djava.awt.headless=true ^ -cp ..\blink1-library\target\blink1-library-jar-with-dependencies.jar;..\blink1-java-examples\target\blink1-java-examples.jar ^ - com.thingm.blink1.OnOffColor 000000 \ No newline at end of file + com.thingm.blink1.OnOffColor 000000 + + +:: Use the variables in decisions +if "%remotePostEnabled%"=="true" ( + echo Remote post is enabled. + curl -X POST -H "Content-Type: application/json" -d @status_gone.json -k https://servingnachos.com/status/stat.php +) else ( + echo Remote post is disabled. +) diff --git a/scripts/status_available.json b/scripts/status_available.json new file mode 100644 index 0000000..6f2b5fd --- /dev/null +++ b/scripts/status_available.json @@ -0,0 +1,3 @@ +{ + "status": "1" +} \ No newline at end of file diff --git a/scripts/status_busy.json b/scripts/status_busy.json new file mode 100644 index 0000000..25443a1 --- /dev/null +++ b/scripts/status_busy.json @@ -0,0 +1,3 @@ +{ + "status": "2" +} \ No newline at end of file diff --git a/scripts/status_current.json b/scripts/status_current.json new file mode 100644 index 0000000..6ab269b --- /dev/null +++ b/scripts/status_current.json @@ -0,0 +1,5 @@ +{ + "message": "Benjamin Rodriguez", + "status": "2", + "color": "#0000ff" +} \ No newline at end of file diff --git a/scripts/status_dnd.json b/scripts/status_dnd.json new file mode 100644 index 0000000..987b40e --- /dev/null +++ b/scripts/status_dnd.json @@ -0,0 +1,3 @@ +{ + "status": "3", "message":"Benjamin Rodriguez" +} \ No newline at end of file diff --git a/scripts/status_gone.json b/scripts/status_gone.json new file mode 100644 index 0000000..8a69d6a --- /dev/null +++ b/scripts/status_gone.json @@ -0,0 +1,3 @@ +{ + "status": "0" +} \ No newline at end of file From 44634ac0c2716a4072a72e66d9f3d23995998517 Mon Sep 17 00:00:00 2001 From: Benjamin Rodriguez Date: Thu, 5 Dec 2024 09:45:22 -0600 Subject: [PATCH 5/5] Add capabilty to add the scripts directory to the path. This will allow the running of the scripts from any directory to change the status. --- scripts/run-set-color.bat | 2 ++ scripts/stat_available.bat | 2 ++ scripts/stat_busy.bat | 2 ++ scripts/stat_current.bat | 2 ++ scripts/stat_dnd.bat | 2 ++ scripts/stat_gone.bat | 2 ++ 6 files changed, 12 insertions(+) diff --git a/scripts/run-set-color.bat b/scripts/run-set-color.bat index 943d2bf..1134e05 100644 --- a/scripts/run-set-color.bat +++ b/scripts/run-set-color.bat @@ -1,5 +1,7 @@ @echo off +cd /D "%~dp0" + java ^ -Djava.awt.headless=true ^ -cp ..\blink1-library\target\blink1-library-jar-with-dependencies.jar;..\blink1-java-examples\target\blink1-java-examples.jar ^ diff --git a/scripts/stat_available.bat b/scripts/stat_available.bat index dde6a73..b9e24a4 100644 --- a/scripts/stat_available.bat +++ b/scripts/stat_available.bat @@ -1,5 +1,7 @@ @echo off +cd /D "%~dp0" + :: Read the config.txt file and set variables for /f "tokens=1,2 delims== " %%A in (config.txt) do set %%A=%%B diff --git a/scripts/stat_busy.bat b/scripts/stat_busy.bat index af3f692..754632d 100644 --- a/scripts/stat_busy.bat +++ b/scripts/stat_busy.bat @@ -1,5 +1,7 @@ @echo off +cd /D "%~dp0" + :: Read the config.txt file and set variables for /f "tokens=1,2 delims== " %%A in (config.txt) do set %%A=%%B diff --git a/scripts/stat_current.bat b/scripts/stat_current.bat index f187286..d6a0633 100644 --- a/scripts/stat_current.bat +++ b/scripts/stat_current.bat @@ -1,5 +1,7 @@ @@echo off +cd /D "%~dp0" + curl -o status_current.json https://servingnachos.com/status/stat.php powershell.exe -file stat_current_2.ps1 \ No newline at end of file diff --git a/scripts/stat_dnd.bat b/scripts/stat_dnd.bat index 5a5db04..93b87b2 100644 --- a/scripts/stat_dnd.bat +++ b/scripts/stat_dnd.bat @@ -1,5 +1,7 @@ @echo off +cd /D "%~dp0" + :: Read the config.txt file and set variables for /f "tokens=1,2 delims== " %%A in (config.txt) do set %%A=%%B diff --git a/scripts/stat_gone.bat b/scripts/stat_gone.bat index 9f9444a..e1c1a4a 100644 --- a/scripts/stat_gone.bat +++ b/scripts/stat_gone.bat @@ -1,5 +1,7 @@ @echo off +cd /D "%~dp0" + :: Read the config.txt file and set variables for /f "tokens=1,2 delims== " %%A in (config.txt) do set %%A=%%B