Skip to content

Commit 4d7e075

Browse files
authored
Merge pull request #804 from makermelissa/master
Added Stream Deck Message Panel project files
2 parents 710686a + e65535e commit 4d7e075

5 files changed

Lines changed: 244 additions & 1 deletion

File tree

Stream_Deck_Message_Panel/MessagePanel/.m4wifi.test

Whitespace-only changes.
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
// Message Panel
2+
// Reads an Adafruit IO Feed, then formats and displays the message
3+
// Author: Melissa LeBlanc-Williams
4+
5+
#include <RGBmatrixPanel.h>
6+
#include <SPI.h>
7+
8+
#define BASE_CHAR_WIDTH 6 // 5 pixels + 1 space
9+
#define BASE_CHAR_HEIGHT 8 // 7 pixels + 1 space
10+
11+
// Most of the signal pins are configurable, but the CLK pin has some
12+
// special constraints. On 8-bit AVR boards it must be on PORTB...
13+
// Pin 8 works on the Arduino Uno & compatibles (e.g. Adafruit Metro),
14+
// Pin 11 works on the Arduino Mega. On 32-bit SAMD boards it must be
15+
// on the same PORT as the RGB data pins (D2-D7)...
16+
// Pin 8 works on the Adafruit Metro M0 or Arduino Zero,
17+
// Pin A4 works on the Adafruit Metro M4 (if using the Adafruit RGB
18+
// Matrix Shield, cut trace between CLK pads and run a wire to A4).
19+
20+
//#define CLK 8 // USE THIS ON ADAFRUIT METRO M0 ir adapting to use Airlift, etc.
21+
#define CLK A4 // USE THIS ON METRO M4 (not M0)
22+
#define OE 9
23+
#define LAT 10
24+
#define A A0
25+
#define B A1
26+
#define C A2
27+
#define D A3
28+
29+
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);
30+
31+
#include "config.h"
32+
33+
// set up the 'counter' feed
34+
AdafruitIO_Feed *counter = io.feed("messagepanel");
35+
36+
void drawText(const char *text, bool resetPosition = true, uint16_t color = 0xffff, uint16_t textSize = 1) {
37+
matrix.setTextSize(textSize); // size 1 == 8 pixels high
38+
if (resetPosition) {
39+
matrix.setCursor(0, 0); // start at top left, with 8 pixel of spacing
40+
}
41+
matrix.setTextColor(color);
42+
matrix.print(text);
43+
}
44+
45+
// This function is called whenever a 'messagepanel' message
46+
// is received from Adafruit IO. it was attached to
47+
// the counter feed in the setup() function above.
48+
void handleMessage(AdafruitIO_Data *data) {
49+
String message = data->toString();
50+
String plainText = data->toString();
51+
uint16_t color = matrix.Color333(7, 7, 7);
52+
uint16_t textSize = 1;
53+
uint16_t colorStartIndex = 0, colorEndIndex = 0;
54+
uint16_t sizeStartIndex = 0, sizeEndIndex = 0;
55+
uint16_t strpos = 0;
56+
byte lineLengths[] = {0, 0, 0, 0};
57+
byte lineNum = 0;
58+
// Calculate line lengths
59+
boolean paramRead = false;
60+
boolean newLine = false;
61+
62+
matrix.setCursor(0, 0);
63+
matrix.fillScreen(matrix.Color333(0, 0, 0));
64+
65+
// Strip out all color data first
66+
while(strpos < plainText.length()) {
67+
colorStartIndex = plainText.indexOf('{');
68+
colorEndIndex = plainText.indexOf('}');
69+
plainText.remove(colorStartIndex, colorEndIndex - colorStartIndex + 1);
70+
strpos++;
71+
}
72+
73+
// Calculate the line lengths in pixels for fixed width text
74+
strpos = 0;
75+
while(strpos < plainText.length()) {
76+
sizeStartIndex = plainText.indexOf('<');
77+
sizeEndIndex = plainText.indexOf('>');
78+
79+
if (strpos == sizeStartIndex) {
80+
textSize = atoi(plainText.substring(sizeStartIndex + 1, sizeEndIndex).c_str());
81+
plainText.remove(sizeStartIndex, sizeEndIndex - sizeStartIndex + 1);
82+
}
83+
84+
if (plainText.charAt(strpos) != '\n') {
85+
lineLengths[lineNum] += textSize * BASE_CHAR_WIDTH;
86+
}
87+
88+
// We want to keep adding up the characters * textSize until we hit a newline character
89+
// or we reach the width of the message panel. Then we go down to the next line
90+
if (plainText.charAt(strpos) == '\n' || lineLengths[lineNum] >= matrix.width()) {
91+
lineNum++;
92+
}
93+
94+
strpos++;
95+
}
96+
97+
textSize = 1;
98+
lineNum = 0;
99+
for(uint16_t i=0; i<message.length(); i++) {
100+
if (message.charAt(i) == '{') {
101+
paramRead = true;
102+
colorStartIndex = i + 1;
103+
} else if (message.charAt(i) == '}') {
104+
paramRead = false;
105+
int wheelPos = atoi(message.substring(colorStartIndex, i).c_str());
106+
if (wheelPos < 25) {
107+
color = Wheel(wheelPos);
108+
} else {
109+
color = matrix.Color333(7, 7, 7);
110+
}
111+
} else if (message.charAt(i) == '<') {
112+
paramRead = true;
113+
sizeStartIndex = i + 1;
114+
} else if (message.charAt(i) == '>') {
115+
paramRead = false;
116+
textSize = atoi(message.substring(sizeStartIndex, i).c_str());
117+
} else {
118+
if (paramRead) continue;
119+
120+
if (matrix.getCursorX() == 0 && matrix.getCursorY() == 0) {
121+
matrix.setCursor(floor((matrix.width() / 2) - (lineLengths[lineNum] / 2)), 0);
122+
} else if (newLine) {
123+
matrix.setCursor(floor((matrix.width() / 2) - (lineLengths[++lineNum] / 2)), matrix.getCursorY());
124+
newLine = false;
125+
}
126+
drawText(message.substring(i, i+1).c_str(), false, color, textSize);
127+
if (message.charAt(i) == '\n' || matrix.getCursorX() >= matrix.width()) {
128+
newLine = true;
129+
}
130+
}
131+
}
132+
}
133+
134+
void setup() {
135+
matrix.begin();
136+
137+
// fill the screen with 'black'
138+
matrix.fillScreen(matrix.Color333(0, 0, 0));
139+
// draw some text!
140+
matrix.setTextWrap(true);
141+
drawText("Connecting...");
142+
Serial.begin(115200);
143+
io.connect();
144+
145+
counter->onMessage(handleMessage);
146+
147+
while(io.mqttStatus() < AIO_CONNECTED) {
148+
drawText(".");
149+
delay(500);
150+
}
151+
152+
counter->get();
153+
154+
Serial.println();
155+
Serial.println(io.statusText());
156+
}
157+
158+
void loop() {
159+
io.run();
160+
}
161+
162+
// Input a value 0 to 24 to get a color value.
163+
// The colours are a transition r - g - b - back to r.
164+
uint16_t Wheel(byte WheelPos) {
165+
if(WheelPos < 8) {
166+
return matrix.Color333(7 - WheelPos, WheelPos, 0);
167+
} else if(WheelPos < 16) {
168+
WheelPos -= 8;
169+
return matrix.Color333(0, 7-WheelPos, WheelPos);
170+
} else {
171+
WheelPos -= 16;
172+
return matrix.Color333(0, WheelPos, 7 - WheelPos);
173+
}
174+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/************************ Adafruit IO Config *******************************/
2+
3+
// visit io.adafruit.com if you need to create an account,
4+
// or if you need your Adafruit IO key.
5+
#define IO_USERNAME "your_username"
6+
#define IO_KEY "your_key"
7+
8+
/******************************* WIFI **************************************/
9+
10+
// the AdafruitIO_WiFi client will work with the following boards:
11+
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
12+
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
13+
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
14+
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
15+
// - Feather WICED -> https://www.adafruit.com/products/3056
16+
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
17+
// - Adafruit Metro M4 Express AirLift Lite -> https://www.adafruit.com/product/4000
18+
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
19+
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
20+
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
21+
22+
#define WIFI_SSID "your_ssid"
23+
#define WIFI_PASS "your_pass"
24+
25+
// uncomment the following line if you are using airlift
26+
// #define USE_AIRLIFT
27+
28+
// uncomment the following line if you are using winc1500
29+
// #define USE_WINC1500
30+
31+
// comment out the following lines if you are using fona or ethernet
32+
#include "AdafruitIO_WiFi.h"
33+
34+
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)
35+
// Configure the pins used for the ESP32 connection
36+
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
37+
// Don't change the names of these #define's! they match the variant ones
38+
#define SPIWIFI SPI
39+
#define SPIWIFI_SS 10 // Chip select pin
40+
#define NINA_ACK 9 // a.k.a BUSY or READY pin
41+
#define NINA_RESETN 6 // Reset pin
42+
#define NINA_GPIO0 -1 // Not connected
43+
#endif
44+
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
45+
#else
46+
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
47+
#endif
48+
/******************************* FONA **************************************/
49+
50+
// the AdafruitIO_FONA client will work with the following boards:
51+
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
52+
53+
// uncomment the following two lines for 32u4 FONA,
54+
// and comment out the AdafruitIO_WiFi client in the WIFI section
55+
// #include "AdafruitIO_FONA.h"
56+
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
57+
58+
/**************************** ETHERNET ************************************/
59+
60+
// the AdafruitIO_Ethernet client will work with the following boards:
61+
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
62+
63+
// uncomment the following two lines for ethernet,
64+
// and comment out the AdafruitIO_WiFi client in the WIFI section
65+
// #include "AdafruitIO_Ethernet.h"
66+
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
Binary file not shown.

arduino_libinstall

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,12 @@ echo "Installing libraries:"
153153
[ ! -d $HOME/Arduino/libraries/Adafruit_Zero_I2S_Library ] && arduino --install-library "Adafruit Zero I2S Library"
154154
[ ! -d $HOME/Arduino/libraries/Adafruit_Zero_PDM_Library ] && arduino --install-library "Adafruit Zero PDM Library"
155155
[ ! -d $HOME/Arduino/libraries/Adafruit_ZeroTimer_Library ] && arduino --install-library "Adafruit ZeroTimer Library"
156+
[ ! -d $HOME/Arduino/libraries/ArduinoHttpClient ] && arduino --install-library "ArduinoHttpClient"
157+
[ ! -d $HOME/Arduino/libraries/RGB_matrix_Panel ] && arduino --install-library "RGB matrix Panel"
158+
[ ! -d $HOME/Arduino/libraries/SdFat ] && arduino --install-library "SdFat"
156159
[ ! -d $HOME/Arduino/libraries/U8g2_for_Adafruit_GFX ] && arduino --install-library "U8g2_for_Adafruit_GFX"
157160
[ ! -d $HOME/Arduino/libraries/Wemos_Matrix_Adafruit_GFX ] && arduino --install-library "Wemos Matrix Adafruit GFX"
158161
[ ! -d $HOME/Arduino/libraries/WaveHC ] && arduino --install-library "WaveHC"
159-
[ ! -d $HOME/Arduino/libraries/SdFat ] && arduino --install-library "SdFat"
162+
[ ! -d $HOME/Arduino/libraries/WiFiNiNa ] && git clone https://github.com/adafruit/WiFiNiNa $HOME/Arduino/libraries/WiFiNiNa
160163

161164
exit 0

0 commit comments

Comments
 (0)