diff --git a/test_anim/.gitignore b/test_anim/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..03423d66296599d81a6439f7b5de112f4ad02270 --- /dev/null +++ b/test_anim/.gitignore @@ -0,0 +1,2 @@ +minimatrixrpi +*.o \ No newline at end of file diff --git a/test_anim/.vscode/c_cpp_properties.json b/test_anim/.vscode/c_cpp_properties.json index 33fc24db0f94d8220c3cc0b4f04ed21be3c1bf01..2c87b7e0a8f165d04b9d525132259b9b205a01b7 100644 --- a/test_anim/.vscode/c_cpp_properties.json +++ b/test_anim/.vscode/c_cpp_properties.json @@ -1,15 +1,23 @@ { "configurations": [ { - "name": "Linux", + "name": "MinGW", "includePath": [ - "${workspaceFolder}" + "${workspaceFolder}", + "c:\\MinGW\\include", + "d:\\_work\\SEM\\WiringPi\\wiringPi" ], - "defines": [], - "compilerPath": "/usr/bin/clang", + "browse": { + "path": [ + "${workspaceFolder}", + "c:\\MinGW\\include", + "d:\\_work\\SEM\\WiringPi\\wiringPi" + ] + }, + "defines": ["_POSIX_C_SOURCE"], + "compilerPath": "c:\\MinGW\\bin\\g++.exe", "cStandard": "c11", - "cppStandard": "c++17", - "intelliSenseMode": "clang-x64" + "cppStandard": "c++17" } ], "version": 4 diff --git a/test_anim/.vscode/launch.json b/test_anim/.vscode/launch.json new file mode 100644 index 0000000000000000000000000000000000000000..7532d9f31fa607006e7fb3e38681dc97a9aea56b --- /dev/null +++ b/test_anim/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C++ Launch", + "type": "cppdbg", + "request": "launch", + "cwd": "${workspaceFolder}", + "program": "${workspaceRoot}/minimatrixrpi", + "miDebuggerPath": "c:\\MinGW\\bin\\gdb.exe", + "miDebuggerServerAddress": "192.168.2.212:10000", + "MIMode": "gdb" + }, + { + "type": "gdb", + "request": "attach", + "name": "Attach to gdbserver", + "executable": "${workspaceRoot}/minimatrixrpi", + "target": "192.168.2.212:10000", + "remote": true, + "printCalls": true, + "cwd": "${workspaceRoot}", + "gdbpath": "c:\\MinGW\\bin\\gdb.exe", + "valuesFormatting": "parseText" + } + ] +} \ No newline at end of file diff --git a/test_anim/.vscode/sftp.json b/test_anim/.vscode/sftp.json new file mode 100644 index 0000000000000000000000000000000000000000..1dd67f01adeeb6c5f3b0102a1070ff4011828f43 --- /dev/null +++ b/test_anim/.vscode/sftp.json @@ -0,0 +1,10 @@ +{ + "name": "Pi Zero W", + "host": "192.168.2.212", + "protocol": "sftp", + "port": 22, + "username": "pi", + "password": "kiskutya", + "remotePath": "/home/pi/Documents/minimatrixrpi/test_anim", + "uploadOnSave": true +} diff --git a/test_anim/.vscode/tasks.json b/test_anim/.vscode/tasks.json new file mode 100644 index 0000000000000000000000000000000000000000..9a37d4324ad238fcfe4c2ac22b33e1795d4e4718 --- /dev/null +++ b/test_anim/.vscode/tasks.json @@ -0,0 +1,27 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++.exe build active file", + "command": "c:\\MinGW\\bin\\g++.exe", + "args": [ + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "c:\\MinGW\\bin" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/test_anim/animation.cpp b/test_anim/animation.cpp index 56b8856fc6cb766c1afeafdb29c6ebf6c4aba9d5..13386644538c219b8ccbb264dba5db113d8d7d0b 100644 --- a/test_anim/animation.cpp +++ b/test_anim/animation.cpp @@ -50,5 +50,4 @@ MxFrame Animation::nextFrame() else { return MxFrame(); } - } diff --git a/test_anim/color.hpp b/test_anim/color.hpp index 2f41e3433a5e0d6e60879ee306dbc23e013fe0e1..312fc440dcee2fdbfb4c5462bbeda81480f9c07c 100644 --- a/test_anim/color.hpp +++ b/test_anim/color.hpp @@ -1,3 +1,5 @@ +#ifndef COLOR_HPP +#define COLOR_HPP #include "stdint.h" struct Color @@ -8,8 +10,10 @@ struct Color Color() : r(0), g(0), b(0) {} - uint8_t r; - uint8_t g; - uint8_t b; - uint8_t a; -}; \ No newline at end of file + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; +}; + +#endif // COLOR_HPP \ No newline at end of file diff --git a/test_anim/main.cpp b/test_anim/main.cpp deleted file mode 100644 index ff1be97ecd589bc4026344a349d8ff48cddbadec..0000000000000000000000000000000000000000 --- a/test_anim/main.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "animation.h" - - -int main(int argc, char *argv[]) -{ - Animation anim; - anim.openFile("../asdasd.qp4"); - - - return 0; -} - - diff --git a/test_anim/minimatrixrpi.cpp b/test_anim/minimatrixrpi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f2e1ab9516a45622812ccd2f49562e4712a0ff2 --- /dev/null +++ b/test_anim/minimatrixrpi.cpp @@ -0,0 +1,27 @@ +#include "animation.h" +#include "mxframe.h" +#include "spiframe.h" +#include "spisender.h" +#include "color.hpp" + +int main(int argc, char *argv[]) +{ +// Animation anim; +// anim.openFile("../asdasd.qp4"); + MxFrame frame; + frame.length = 1000; + for (size_t i = 0; i < 26; i++) + { + for (size_t j = 0; j < 32; j++) + { + frame.pixels[i][j] = Color(0,0,0); + } + } + + //frame.pixels[0][0] = Color(0,128,0); + //frame.pixels[17][0] = Color(0,255,0); + SpiSender spisender; + spisender.sendFrame(SpiFrame(frame)); + + return 0; +} diff --git a/test_anim/spiframe.cpp b/test_anim/spiframe.cpp index 7f5c202255457324dc05221c7c3d4748ec9c806a..76250e17656bb5ac174029a75de038f270fa0d5d 100644 --- a/test_anim/spiframe.cpp +++ b/test_anim/spiframe.cpp @@ -1,28 +1,27 @@ #include "spiframe.h" bool SpiFrame::LedCoordToPixel(const MxFrame &mxframe, int bitpos, - int colorbit, enum eColor color, int column) + int colorbit, enum eColor color, int column) { int y = 2*bitpos; int x = column; if (column >= 32) { x = 63 - column; - y = bitpos + 1; + y = y + 1; } - if (color == RED) { - return mxframe.pixels[x][y].r & (1 << colorbit); + return mxframe.pixels[y][x].r & (1 << colorbit); } else if (color == GREEN) { - return mxframe.pixels[x][y].g & (1 << colorbit); + return mxframe.pixels[y][x].g & (1 << colorbit); } else if (color == BLUE) { - return mxframe.pixels[x][y].b & (1 << colorbit); + return mxframe.pixels[y][x].b & (1 << colorbit); } return false; } @@ -41,16 +40,15 @@ SpiFrame::SpiFrame(const MxFrame& mxframe) for (int column = 0; column < 64; column++) { for (int bitpos = 0; bitpos < 13; bitpos++) { for (int colorbit = 0; colorbit < 8; colorbit++) { - data[column * 24 + colorbit] |= - (LedCoordToPixel(mxframe, bitpos, colorbit, RED, column) ? 1 : 0) << bitpos; - data[column * 24 + colorbit + 8] |= + data[column * 24 + (7-colorbit)] |= (LedCoordToPixel(mxframe, bitpos, colorbit, GREEN, column) ? 1 : 0) << bitpos; - data[column * 24 + colorbit + 16] |= + data[column * 24 + (7-colorbit) + 8] |= + (LedCoordToPixel(mxframe, bitpos, colorbit, RED, column) ? 1 : 0) << bitpos; + data[column * 24 + (7-colorbit) + 16] |= (LedCoordToPixel(mxframe, bitpos, colorbit, BLUE, column) ? 1 : 0) << bitpos; } } } - } diff --git a/test_anim/spisender.cpp b/test_anim/spisender.cpp index 76e9e455793859e8118a969f02a0a9062c1a626e..578b03cddbd505fdd6dfadc1e4cf2f8d8c4de81c 100644 --- a/test_anim/spisender.cpp +++ b/test_anim/spisender.cpp @@ -1,23 +1,40 @@ #include "spisender.h" +#include "wiringPi.h" +#include "wiringPiSPI.h" +#include <unistd.h> +#include <stdint.h> -SpiSender::SpiSender(int readyPin): readyPin(readyPin) +SpiSender::SpiSender() { + wiringPiSetup(); + pinMode(readyPin, INPUT); + pinMode(resetPin, OUTPUT); + pullUpDnControl(readyPin, PUD_DOWN); + digitalWrite(resetPin, LOW); + usleep(100000); + digitalWrite(resetPin, HIGH); + usleep(100000); + fd = wiringPiSPISetup(SPI_CHANNEL, SPI_SPEED); + uint8_t dummy = 0; + wiringPiSPIDataRW(SPI_CHANNEL, &dummy, 1); } -int SpiSender::getReadyPin() const +SpiSender::~SpiSender() { - return readyPin; + close(fd); } bool SpiSender::sendFrame(const SpiFrame &frame) const { - //TODO - return canSend(); + //while (!canSend()); + uint8_t dummy = 0; + wiringPiSPIDataRW(SPI_CHANNEL, (uint8_t*)frame.data, 64*24*2); + wiringPiSPIDataRW(SPI_CHANNEL, &dummy, 1); + return true; } bool SpiSender::canSend() const { - //TODO - return true; + return digitalRead(readyPin); } diff --git a/test_anim/spisender.h b/test_anim/spisender.h index ea68193c66704d88afd07c2b7812672bdaf2ac57..4b3d74dda50dfdbdff3a0e1adf3e34bee950c415 100644 --- a/test_anim/spisender.h +++ b/test_anim/spisender.h @@ -6,11 +6,16 @@ class SpiSender { private: - int readyPin; + const int readyPin = 6; // WiringPi PIN. (22 on header) + const int resetPin = 5; // WiringPi PIN. (18 on header) + const int SPI_SPEED = 1000000; + const int SPI_CHANNEL = 0; + int fd = 0; + bool firstFrame = true; public: - SpiSender(int readyPin); - int getReadyPin() const; + SpiSender(); + ~SpiSender(); bool sendFrame(const SpiFrame& frame) const; bool canSend() const; };