Skip to content

Commit

Permalink
Dmd console overwrite (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner authored Feb 19, 2024
1 parent f73c1ec commit 14cbb0f
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/libdmdutil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ jobs:
cp build/Release/dmdutil_static.lib tmp
cp build/Release/dmdutil_test_s.exe tmp
cp build/Release/dmdutil_test.exe tmp
cp -r test tmp/
else
ARTIFACT_PATH="libdmdutil-${{ needs.version.outputs.tag }}-${{ matrix.platform }}-${{ matrix.arch }}.tar.gz"
if [[ "${{ matrix.platform }}" == "macos" ]]; then
Expand All @@ -159,6 +160,7 @@ jobs:
cp build/libdmdutil.a tmp
cp build/libdmdutil.so tmp
fi
cp -r test tmp/
cd tmp
tar -czvf ../${ARTIFACT_PATH} *
fi
Expand All @@ -185,6 +187,7 @@ jobs:
- name: Combine macos architectures
run: |
mkdir tmp
cp -r libdmdutil-${{ needs.version.outputs.tag }}-macos-arm64/test tmp/
lipo -create -output tmp/libdmdutil-${{ needs.version.outputs.tag }}.dylib \
libdmdutil-${{ needs.version.outputs.tag }}-macos-arm64/libdmdutil.${{ needs.version.outputs.tag }}.dylib \
libdmdutil-${{ needs.version.outputs.tag }}-macos-x64/libdmdutil.${{ needs.version.outputs.tag }}.dylib
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/build/
/out/
/test/
/.vs/
/.vscode/
CMakeSettings.json
Expand Down
5 changes: 3 additions & 2 deletions include/DMDUtil/ConsoleDMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ namespace DMDUtil
class ConsoleDMD
{
public:
ConsoleDMD(FILE* f);
ConsoleDMD(bool overwrite, FILE* out);
~ConsoleDMD();

void Render(uint8_t* buffer, uint16_t width, uint16_t height, uint8_t bitDepth);

private:
FILE* out;
bool m_overwrite;
FILE* m_out;
};

} // namespace DMDUtil
2 changes: 1 addition & 1 deletion include/DMDUtil/DMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DMDUTILAPI DMD
bool DestroyLevelDMD(LevelDMD* pLevelDMD);
RGB24DMD* CreateRGB24DMD(uint16_t width, uint16_t height);
bool DestroyRGB24DMD(RGB24DMD* pRGB24DMD);
ConsoleDMD* CreateConsoleDMD(FILE* f = stdout);
ConsoleDMD* CreateConsoleDMD(bool overwrite, FILE* out = stdout);
bool DestroyConsoleDMD(ConsoleDMD* pConsoleDMD);
void UpdateData(const uint8_t* pData, int depth, uint16_t width, uint16_t height, uint8_t r, uint8_t g, uint8_t b,
const char* name = nullptr);
Expand Down
1 change: 1 addition & 0 deletions include/DMDUtil/DMDUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define DMDUTIL_MINOR_VERSION DMDUTIL_STR(DMDUTIL_VERSION_MAJOR) "." DMDUTIL_STR(DMDUTIL_VERSION_MINOR)

#include "Config.h"
#include "ConsoleDMD.h"
#include "DMD.h"
#include "LevelDMD.h"
#include "RGB24DMD.h"
1 change: 1 addition & 0 deletions platforms/android/arm64-v8a/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ platforms/android/arm64-v8a/external.sh
cmake -DPLATFORM=android -DARCH=arm64-v8a -DBUILD_SHARED=ON -DBUILD_STATIC=OFF -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -B build
cmake --build build -- -j${NUM_PROCS}
cp build/libzedmd.so ../../third-party/runtime-libs/android/arm64-v8a
cp -r test ../../
cd ..

#
Expand Down
1 change: 1 addition & 0 deletions platforms/ios/arm64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ platforms/ios/arm64/external.sh
cmake -DPLATFORM=ios -DARCH=arm64 -DBUILD_SHARED=OFF -DBUILD_STATIC=ON -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -B build
cmake --build build -- -j${NUM_PROCS}
cp build/libzedmd.a ../../third-party/build-libs/ios/arm64
cp -r test ../../
cd ..

#
Expand Down
1 change: 1 addition & 0 deletions platforms/linux/aarch64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cmake --build build -- -j${NUM_PROCS}
cp third-party/include/libserialport.h ../../third-party/include
cp third-party/runtime-libs/linux/aarch64/libserialport.so.0 ../../third-party/runtime-libs/linux/aarch64
cp build/libzedmd.so.0.5.0 ../../third-party/runtime-libs/linux/aarch64
cp -r test ../../
cd ..

#
Expand Down
1 change: 1 addition & 0 deletions platforms/linux/x64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cmake --build build -- -j${NUM_PROCS}
cp third-party/include/libserialport.h ../../third-party/include
cp third-party/runtime-libs/linux/x64/libserialport.so.0 ../../third-party/runtime-libs/linux/x64
cp build/libzedmd.so.0.5.0 ../../third-party/runtime-libs/linux/x64
cp -r test ../../
cd ..

#
Expand Down
1 change: 1 addition & 0 deletions platforms/macos/arm64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cmake --build build -- -j${NUM_PROCS}
cp third-party/include/libserialport.h ../../third-party/include
cp third-party/runtime-libs/macos/arm64/libserialport.dylib ../../third-party/runtime-libs/macos/arm64
cp build/libzedmd.0.5.0.dylib ../../third-party/runtime-libs/macos/arm64
cp -r test ../../
cd ..

#
Expand Down
1 change: 1 addition & 0 deletions platforms/macos/x64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cmake --build build -- -j${NUM_PROCS}
cp third-party/include/libserialport.h ../../third-party/include
cp third-party/runtime-libs/macos/x64/libserialport.dylib ../../third-party/runtime-libs/macos/x64
cp build/libzedmd.0.5.0.dylib ../../third-party/runtime-libs/macos/x64
cp -r test ../../
cd ..

#
Expand Down
1 change: 1 addition & 0 deletions platforms/tvos/arm64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ platforms/tvos/arm64/external.sh
cmake -DPLATFORM=tvos -DARCH=arm64 -DBUILD_SHARED=OFF -DBUILD_STATIC=ON -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -B build
cmake --build build -- -j${NUM_PROCS}
cp build/libzedmd.a ../../third-party/build-libs/tvos/arm64
cp -r test ../../
cd ..

#
Expand Down
1 change: 1 addition & 0 deletions platforms/win/x64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cp third-party/build-libs/win/x64/libserialport64.lib ../../third-party/build-li
cp third-party/runtime-libs/win/x64/libserialport64.dll ../../third-party/runtime-libs/win/x64
cp build/${BUILD_TYPE}/zedmd64.lib ../../third-party/build-libs/win/x64
cp build/${BUILD_TYPE}/zedmd64.dll ../../third-party/runtime-libs/win/x64
cp -r test ../../
cd ..

#
Expand Down
1 change: 1 addition & 0 deletions platforms/win/x86/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cp third-party/build-libs/win/x86/libserialport.lib ../../third-party/build-libs
cp third-party/runtime-libs/win/x86/libserialport.dll ../../third-party/runtime-libs/win/x86
cp build/${BUILD_TYPE}/zedmd.lib ../../third-party/build-libs/win/x86
cp build/${BUILD_TYPE}/zedmd.dll ../../third-party/runtime-libs/win/x86
cp -r test ../../
cd ..

#
Expand Down
20 changes: 13 additions & 7 deletions src/ConsoleDMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
namespace DMDUtil
{

ConsoleDMD::ConsoleDMD(FILE* f) { out = f; }
ConsoleDMD::ConsoleDMD(bool overwrite, FILE* out)
{
m_overwrite = overwrite;
m_out = out;
}

ConsoleDMD::~ConsoleDMD() {}

Expand All @@ -18,28 +22,30 @@ void ConsoleDMD::Render(uint8_t* buffer, uint16_t width, uint16_t height, uint8_
uint8_t value = buffer[y * width + x];
if (bitDepth > 2)
{
fprintf(out, "%2x", value);
fprintf(m_out, "%2x", value);
}
else
{
switch (value)
{
case 0:
fprintf(out, "\033[0;40m⚫\033[0m");
fprintf(m_out, "\033[0;40m⚫\033[0m");
break;
case 1:
fprintf(out, "\033[0;40m🟤\033[0m");
fprintf(m_out, "\033[0;40m🟤\033[0m");
break;
case 2:
fprintf(out, "\033[0;40m🟠\033[0m");
fprintf(m_out, "\033[0;40m🟠\033[0m");
break;
case 3:
fprintf(out, "\033[0;40m🟡\033[0m");
fprintf(m_out, "\033[0;40m🟡\033[0m");
break;
}
}
}
fprintf(out, "\n");
fprintf(m_out, "\n");
}

if (m_overwrite) fprintf(m_out, "\033[%dA", height);
}
} // namespace DMDUtil
4 changes: 2 additions & 2 deletions src/DMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ bool DMD::DestroyRGB24DMD(RGB24DMD* pRGB24DMD)
return false;
}

ConsoleDMD* DMD::CreateConsoleDMD(FILE* f)
ConsoleDMD* DMD::CreateConsoleDMD(bool overwrite, FILE* out)
{
ConsoleDMD* const pConsoleDMD = new ConsoleDMD(f);
ConsoleDMD* const pConsoleDMD = new ConsoleDMD(overwrite, out);
m_consoleDMDs.push_back(pConsoleDMD);
if (!m_pConsoleDMDThread) m_pConsoleDMDThread = new std::thread(&DMD::ConsoleDMDThread, this);
return pConsoleDMD;
Expand Down
9 changes: 3 additions & 6 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include <thread>

#include "DMDUtil/DMDUtil.h"
#include "DMDUtil/LevelDMD.h"
#include "DMDUtil/RGB24DMD.h"
#include "DMDUtil/ConsoleDMD.h"

void DMDUTILCALLBACK LogCallback(const char* format, va_list args)
{
Expand Down Expand Up @@ -95,7 +92,7 @@ int main(int argc, const char* argv[])
int ms = 200;
for (int i = 0; i < 4; i++)
{
if (i == 0) pConsoleDMD = pDmd->CreateConsoleDMD();
if (i == 0) pConsoleDMD = pDmd->CreateConsoleDMD(false);
if (i == 0) pLevelDMD128_2 = pDmd->CreateLevelDMD(128, 32, 2);
if (i == 1) pDmd->DestroyConsoleDMD(pConsoleDMD);
if (i == 1) pLevelDMD128_4 = pDmd->CreateLevelDMD(128, 32, 4);
Expand Down Expand Up @@ -172,11 +169,11 @@ int main(int argc, const char* argv[])
uint16_t size = width * height * 2;
uint8_t* buffer = (uint8_t*)malloc(size * sizeof(uint8_t));
uint16_t* rgb565 = (uint16_t*)malloc(size / 2 * sizeof(uint16_t));
char filename[128];
char filename[28];

for (int i = 1; i <= 100; i++)
{
snprintf(filename, 87, "external/libzedmd-7d2b0fc39475940b61b0126f3ff308dd193fe2a8/test/rgb565_%dx%d/%04d.raw",
snprintf(filename, 28, "test/rgb565_%dx%d/%04d.raw",
width, height, i);
printf("Render raw: %s\n", filename);
fileptr = fopen(filename, "rb");
Expand Down

0 comments on commit 14cbb0f

Please sign in to comment.