Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ build
target
.idea
*.iml

*.log
12 changes: 12 additions & 0 deletions blink1-java-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,17 @@

<build>
<finalName>blink1-java-examples</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>11</source>
<target>11</target>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
24 changes: 22 additions & 2 deletions blink1-library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,38 @@
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.6.0</version>
<version>5.14.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.6.0</version>
<version>5.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.20.0</version>
</dependency>
</dependencies>

<build>
<finalName>blink1-library</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>11</source>
<target>11</target>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
66 changes: 66 additions & 0 deletions blink1-library/src/main/java/com/thingm/blink1/Blink1.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down
10 changes: 10 additions & 0 deletions blink1-processing-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>11</source>
<target>11</target>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
Empty file modified mvnw
100755 → 100644
Empty file.
6 changes: 6 additions & 0 deletions run-example.bat
Original file line number Diff line number Diff line change
@@ -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
Empty file modified run-example.sh
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions scripts/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
remotePostEnabled=false
8 changes: 8 additions & 0 deletions scripts/run-set-color.bat
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions scripts/stat_available.bat
Original file line number Diff line number Diff line change
@@ -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.
)
19 changes: 19 additions & 0 deletions scripts/stat_busy.bat
Original file line number Diff line number Diff line change
@@ -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.
)
7 changes: 7 additions & 0 deletions scripts/stat_current.bat
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions scripts/stat_current_2.ps1
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions scripts/stat_dnd.bat
Original file line number Diff line number Diff line change
@@ -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.
)
20 changes: 20 additions & 0 deletions scripts/stat_gone.bat
Original file line number Diff line number Diff line change
@@ -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.
)
3 changes: 3 additions & 0 deletions scripts/status_available.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"status": "1"
}
3 changes: 3 additions & 0 deletions scripts/status_busy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"status": "2"
}
5 changes: 5 additions & 0 deletions scripts/status_current.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"message": "Benjamin Rodriguez",
"status": "2",
"color": "#0000ff"
}
3 changes: 3 additions & 0 deletions scripts/status_dnd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"status": "3", "message":"Benjamin Rodriguez"
}
3 changes: 3 additions & 0 deletions scripts/status_gone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"status": "0"
}