Skip to content

Commit

Permalink
clear screen if a client disconnects from server, added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner committed Mar 7, 2024
1 parent e2e6a1c commit de4487e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
10 changes: 5 additions & 5 deletions include/DMDUtil/DMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ class DMDUTILAPI DMD

enum class Mode
{
Unknown,
Data,
RGB24, // RGB888
RGB16, // RGB565
AlphaNumeric
Unknown, // int 0
Data, // int 1
RGB24, // int 2, RGB888
RGB16, // int 3, RGB565
AlphaNumeric // int 4
};

#pragma pack(push, 1) // Align to 1-byte boundaries, important for sending over socket.
Expand Down
17 changes: 15 additions & 2 deletions src/dmdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ void run(sockpp::tcp_socket sock, uint32_t threadId)
{
if (n == sizeof(DMDUtil::DMD::StreamHeader))
{
// At the moment the server only listens on localhost.
// Therefore, we don't have to take care about litte vs. big endian and can use memcpy.
memcpy(pHeader, buffer, n);
if (strcmp(pHeader->protocol, "DMDStream") == 0 && pHeader->version == 1)
{
Expand All @@ -48,6 +50,9 @@ void run(sockpp::tcp_socket sock, uint32_t threadId)
case DMDUtil::DMD::Mode::RGB16:
if ((n = sock.read_n(buffer, pHeader->length)) == pHeader->length && threadId == currentThreadId)
{
// At the moment the server only listens on localhost.
// Therefore, we don't have to take care about litte vs. big endian and can use the buffer as uint16_t as
// it is.
pDmd->UpdateRGB16Data((uint16_t*)buffer, pHeader->width, pHeader->height);
}
break;
Expand All @@ -59,12 +64,19 @@ void run(sockpp::tcp_socket sock, uint32_t threadId)
}
break;

default: break;
default:
// Other modes aren't supported via network.
break;
}
}
}
}

// Clear the DMD by sending a black screen.
// Fixed dimension of 128x32 should be OK for all devices.
memset(buffer, 0, sizeof(DMDUtil::DMD::Update));
pDmd->UpdateRGB24Data(buffer, 128, 32);

threads.erase(remove(threads.begin(), threads.end(), threadId), threads.end());
currentThreadId = threads.back();

Expand Down Expand Up @@ -114,5 +126,6 @@ int main(int argc, const char* argv[])
}
}

return 0;
cerr << "No DMD displays found." << endl;
return -1;
}

0 comments on commit de4487e

Please sign in to comment.