55import org .apache .commons .configuration2 .ex .ConfigurationException ;
66import org .json .JSONObject ;
77
8+ import java .io .File ;
89import java .io .FileReader ;
910import java .io .IOException ;
1011import java .net .URI ;
2324 * @author Michael Robbeloth
2425 */
2526public class VestaBoard {
27+ /**
28+ * Return whether VestaBoard object is representing a white on black Vestaboard or a black on white Vestaboard.
29+ * Default is white on black Vestaboard
30+ * @return
31+ */
32+ public BoardType getVestaBoardType () {
33+ return bt ;
34+ }
35+
36+ /**
37+ * Configure whether Vestaboard object is a white on black Vestaboard or a black on white Vestaboard
38+ * Default is white on black Vestaboard
39+ * @param bt
40+ */
41+ public void setVestaBoardType (BoardType bt ) {
42+ this .bt = bt ;
43+ }
2644
2745 /* VestaBoardcii
2846 * @see https://docs.vestaboard.com/characters */
@@ -37,7 +55,7 @@ public enum VestaChars{
3755 Ampersand (47 ), EqualsSign (48 ), Semicolon (49 ), Colon (50 ), SingleQuote (52 ),
3856 DoubleQuote (53 ), PercentSign (54 ), Comma (55 ), Period (56 ), Slash (59 ),
3957 QuestionMark (60 ), DegreeSign (62 ), PoppyRed (63 ), Orange (64 ), Yellow (65 ),
40- Green (66 ), ParisBlue (67 ), Violet (68 ), White (69 );
58+ Green (66 ), ParisBlue (67 ), Violet (68 ), White (69 ), Black ( 70 ), Filled ( 71 ) ;
4159
4260 private final int charValue ; // Internal Vestaboard encoding for the character
4361
@@ -57,6 +75,18 @@ public enum VestaChars{
5775 public int getCharValue () {return charValue ;}
5876 }
5977
78+ public enum BoardType {
79+ WHITE_ON_BLACK_VESTABOARD (1 ), BLACK_ON_WHITE_VESTABOARD (2 );
80+
81+ private final int charValue ;
82+
83+ BoardType (int i ) {
84+ charValue = i ;
85+ }
86+
87+ public int getCharValue () {return charValue ;}
88+ }
89+
6090 private final int ROWS =6 ; // number of rows in Vestaboard
6191 private final int COLS =22 ; // number of cols in Vestaboard
6292 private final int RETRIES =5 ; // number of attempts to send board to VestaBoard
@@ -73,16 +103,20 @@ public enum VestaChars{
73103
74104 private final VestaChars [][] board ; // Data Structure Representation of VestaBoard
75105
76- public static final char UNICODE_UTF16_RED = '\uDFE5' ;
77- public static final char UNICODE_UTF16_BLUE = '\uDFE6' ;
78- public static final char UNICODE_UTF16_ORANGE = '\uDFE7' ;
79- public static final char UNICODE_UTF16_YELLOW = '\uDFE8' ;
80- public static final char UNICODE_UTF16_GREEN = '\uDFE9' ;
81- public static final char UNICODE_UTF16_VIOLET = '\uDFEA' ;
82- public static final char UNICODE_UTF16_WHITE = '\u25A1' ;
106+ public static final char UNICODE_UTF16_RED = '\uDFE5' ; // {63} in VestaBoard char codes
107+ public static final char UNICODE_UTF16_BLUE = '\uDFE6' ; // {67} in VestaBoard char codes
108+ public static final char UNICODE_UTF16_ORANGE = '\uDFE7' ; // {64} in VestaBoard char codes
109+ public static final char UNICODE_UTF16_YELLOW = '\uDFE8' ; // {65} in VestaBoard char codes
110+ public static final char UNICODE_UTF16_GREEN = '\uDFE9' ; // {66} in VestaBoard char codes
111+ public static final char UNICODE_UTF16_VIOLET = '\uDFEA' ; // {68} in VestaBoard char codes
112+ public static final char UNICODE_UTF16_WHITE = '\u25A1' ; // {69} in VestaBoard char codes
113+ public static final char UNICODE_UTF16_BLACK = '\u2B24' ; // {70} in VestaBoard char codes
83114
115+ // BoardType
116+ private BoardType bt ; // Board type is white lettering on black or black lettering on white
84117
85118 /**
119+ * Create a Vestaboard object
86120 * Base constructor, will pass credentials-virtual.ini as config file to constructor taking a string filename
87121 * @throws ConfigurationException Any exception that occurs while initializing a Configuration object.
88122 * @throws IOException Signals that an I/O exception has occurred
@@ -91,6 +125,14 @@ public VestaBoard() throws ConfigurationException, IOException {
91125 this ("credentials-virtual.ini" );
92126 }
93127
128+ /**
129+ * Create a Vestaboard virtual object
130+ * @param f the full path and filename of credentials of the file to open
131+ */
132+ public VestaBoard (File f ) throws ConfigurationException , IOException {
133+ this (f .getAbsolutePath ());
134+ }
135+
94136 /**
95137 * Create a Vestaboard virtual object
96138 * @param filename credentials filename
@@ -117,6 +159,9 @@ public VestaBoard(String filename) throws IOException, ConfigurationException {
117159 api_secret = iniConfiguration .getString ("X-Vestaboard-Api-Secret" );
118160 api_rw_key = iniConfiguration .getString ("X-Vestaboard-Read-Write-Key" );
119161 }
162+
163+ // Set board type, by default use more popular white on black vestaboard
164+ bt = BoardType .WHITE_ON_BLACK_VESTABOARD ;
120165 }
121166
122167 /**
@@ -302,6 +347,7 @@ public int postMessage(String msg) throws IOException, InterruptedException {
302347 case UNICODE_UTF16_GREEN : board [row ][col ] = VestaChars .Green ; break ;
303348 case UNICODE_UTF16_VIOLET : board [row ][col ] = VestaChars .Violet ; break ;
304349 case UNICODE_UTF16_WHITE : board [row ][col ] = VestaChars .White ; break ;
350+ case UNICODE_UTF16_BLACK : board [row ][col ] = VestaChars .Black ; break ;
305351 case '\n' : col = 0 ; row ++; break ;
306352 default :
307353 board [row ][col ] = VestaChars .Blank ;
@@ -503,6 +549,6 @@ else if (value == VestaChars.Period.getCharValue())
503549 public static void main (String [] args ) throws ConfigurationException , IOException , InterruptedException {
504550 VestaBoard v = new VestaBoard ("credentials-virtual.ini" );
505551 System .out .println (v .readMessage ());
506- v .postMessage ("TEST1 " );
552+ v .postMessage ("TEST2 " );
507553 }
508554}
0 commit comments