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-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/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-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. */ 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/mvnw b/mvnw old mode 100755 new mode 100644 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 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/run-set-color.bat b/scripts/run-set-color.bat new file mode 100644 index 0000000..1134e05 --- /dev/null +++ b/scripts/run-set-color.bat @@ -0,0 +1,8 @@ +@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 ^ + 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..b9e24a4 --- /dev/null +++ b/scripts/stat_available.bat @@ -0,0 +1,20 @@ +@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 + +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 + + +:: 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 new file mode 100644 index 0000000..754632d --- /dev/null +++ b/scripts/stat_busy.bat @@ -0,0 +1,19 @@ +@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 + +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 + +:: 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..d6a0633 --- /dev/null +++ b/scripts/stat_current.bat @@ -0,0 +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_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 new file mode 100644 index 0000000..93b87b2 --- /dev/null +++ b/scripts/stat_dnd.bat @@ -0,0 +1,19 @@ +@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 + +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 + +:: 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 new file mode 100644 index 0000000..e1c1a4a --- /dev/null +++ b/scripts/stat_gone.bat @@ -0,0 +1,20 @@ +@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 + +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 + + +:: 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