Skip to content
Snippets Groups Projects
Commit 1ef10a7a authored by ftomi's avatar ftomi
Browse files

SpiFrame convert done

parent ca1116fe
Branches
No related tags found
No related merge requests found
#include "animhandler.h"
void AnimHandler::start()
{
mode = START;
mode = RUN;
}
void AnimHandler::pause()
{
......@@ -26,21 +24,26 @@ void AnimHandler::run() {
{
switch (mode) {
case STOP: emit onStoped(); break;
case START: emit onStarted(); break;
case RUN: emit onStarted(); break;
case PAUSE: emit onPaused(); break;
}
}
lastmode = mode;
switch (mode) {
case STOP: break;
case START:
if (true) //TODO spiSender.isAvailable
case PAUSE: break;
case RUN:
if (anim.eof())
{
QString faszom = anim.nextFrame();
qDebug() << faszom;
mode = STOP;
break;
}
if (spisender.canSend())
{
SpiFrame spiframe(anim.nextFrame());
spisender.sendFrame(spiframe);
}
break;
case PAUSE: break;
}
progress++;
emit progressUpdate(progress);
......@@ -50,6 +53,10 @@ void AnimHandler::run() {
emit resultReady("ALMA");
}
AnimHandler::AnimHandler() : QThread(), spisender(26)
{
}
void AnimHandler::openFile(const QString filepath) {
anim.openFile(filepath);
}
......
......@@ -5,6 +5,7 @@
#include <QDebug>
#include <QFile>
#include "animation.h"
#include "spisender.h"
class AnimHandler: public QThread
{
......@@ -13,11 +14,14 @@ class AnimHandler: public QThread
private:
uint32_t progress = 0;
bool exitThread = false;
enum Mode {STOP=0, START, PAUSE} mode = STOP;
enum Mode {STOP=0, RUN, PAUSE};
enum Mode mode = STOP;
enum Mode lastmode = mode;
Animation anim;
SpiSender spisender;
public:
AnimHandler();
void openFile(const QString filepath);
public slots:
......
#include "spiframe.h"
bool SpiFrame::LedCoordToPixel(const MxFrame &mxframe, int bitpos,
int colorbit, enum Color color, int column)
{
int y = 2*bitpos;
int x = column;
if (column >= 32)
{
x = 63 - column;
y = bitpos + 1;
}
if (color == RED)
{
return mxframe.pixels[x][y].red() & (1 << colorbit);
}
else if (color == GREEN)
{
return mxframe.pixels[x][y].green() & (1 << colorbit);
}
else if (color == BLUE)
{
return mxframe.pixels[x][y].blue() & (1 << colorbit);
}
return false;
}
SpiFrame::SpiFrame()
{
......@@ -8,5 +35,22 @@ SpiFrame::SpiFrame()
SpiFrame::SpiFrame(const MxFrame& mxframe)
{
this->length = mxframe.length;
//TODO Convert
for (int i = 0; i < 64*24; i++) {
data[i] = 0;
}
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] |=
(LedCoordToPixel(mxframe, bitpos, colorbit, GREEN, column) ? 1 : 0) << bitpos;
data[column * 24 + colorbit + 16] |=
(LedCoordToPixel(mxframe, bitpos, colorbit, BLUE, column) ? 1 : 0) << bitpos;
}
}
}
}
......@@ -6,6 +6,11 @@
class SpiFrame
{
private:
enum Color {RED, GREEN, BLUE};
bool LedCoordToPixel(const MxFrame &mxframe, int bitpos, int colorbit, enum Color color, int column);
bool PixelToLedCoord(int x, int y, enum Color color);
public:
SpiFrame();
SpiFrame(const MxFrame& mxframe);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment