Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ make all
Now to run the binary, from the project's root
```
sudo nohup ./cc/text-example \
--api-url=[YOUR API URL] \
--led-rows=64 \
--led-cols=64 \
--led-chain=4 \
Expand Down
3 changes: 3 additions & 0 deletions cc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ CFLAGS=-Wall -O3 -g -Wextra -Wno-unused-parameter
CXXFLAGS=$(CFLAGS)
BINARIES=text-example

# Usage: ./text-example --api-url=<url> [matrix-options]
# Example: ./text-example --api-url=http://localhost:8000/ --led-rows=64 --led-cols=64

# Paths for the rpi-rgb-led-matrix submodule
RGB_LIB_DISTRIBUTION=./rpi-rgb-led-matrix
RGB_INCDIR=$(RGB_LIB_DISTRIBUTION)/include
Expand Down
Binary file modified cc/text-example
Binary file not shown.
30 changes: 24 additions & 6 deletions cc/text-example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,27 @@ int main(int argc, char * argv[]) {
}

//---------------------------------------------------------------------------
// 2. Load the font
// 2. Extract --api-url from remaining arguments
//---------------------------------------------------------------------------
std::string api_url;

for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg.find("--api-url=") == 0) {
api_url = arg.substr(strlen("--api-url="));
break;
}
}

if (api_url.empty()) {
fprintf(stderr, "Error: --api-url flag is required\n");
fprintf(stderr, "Usage: %s --api-url=<url> [matrix-options]\n", argv[0]);
fprintf(stderr, "Example: %s --api-url=http://localhost:8000/ --led-rows=64 --led-cols=64\n", argv[0]);
return 1;
}

//---------------------------------------------------------------------------
// 3. Load the font
//---------------------------------------------------------------------------
const char * bdf_font_file = "./5x7.bdf";
rgb_matrix::Font font;
Expand All @@ -177,7 +197,7 @@ int main(int argc, char * argv[]) {
}

//---------------------------------------------------------------------------
// 3. Create the matrix & set up signal handling
// 4. Create the matrix & set up signal handling
//---------------------------------------------------------------------------
RGBMatrix * canvas = CreateMatrixFromOptions(matrix_options, runtime_opt);
if (!canvas) {
Expand All @@ -188,10 +208,8 @@ int main(int argc, char * argv[]) {
signal(SIGTERM, InterruptHandler);

//---------------------------------------------------------------------------
// 4. Continuously fetch and display leaderboard
// 5. Continuously fetch and display leaderboard
//---------------------------------------------------------------------------
const std::string api_url = "http://localhost:8000/";

while (!interrupt_received) {
// Fetch JSON
std::string leaderboard_data = FetchLeaderboard(api_url);
Expand All @@ -205,7 +223,7 @@ int main(int argc, char * argv[]) {
}

//---------------------------------------------------------------------------
// 5. Cleanup
// 6. Cleanup
//---------------------------------------------------------------------------
canvas -> Clear();
delete canvas;
Expand Down