Skip to content

Commit

Permalink
Add uncrustify stlye (qt), and run across the project
Browse files Browse the repository at this point in the history
  • Loading branch information
cibomahto committed Dec 14, 2015
1 parent 6beaae3 commit 0eaacbb
Show file tree
Hide file tree
Showing 90 changed files with 4,530 additions and 2,993 deletions.
3 changes: 3 additions & 0 deletions PatternPaint/PatternPaint.pro
Expand Up @@ -193,3 +193,6 @@ win32 {
# Windows: Specify the icon to use
RC_ICONS += images/patternpaint.ico
}

DISTFILES += \
../uncrustify.cfg
16 changes: 8 additions & 8 deletions PatternPaint/aboutpatternpaint.cpp
Expand Up @@ -4,16 +4,15 @@
#include <QDebug>
#include <QtWidgetsDepends>


void fitTextToLabel(QLabel *label) {

// qDebug() << "Fiting text to label " << label->text();
void fitTextToLabel(QLabel *label)
{
// qDebug() << "Fiting text to label " << label->text();

// check the font size - need a better algorithm... this could take awhile
while (label->fontMetrics().width(label->text()) > label->rect().width()) {
// qDebug() << "Font size: " << label->fontMetrics().width(label->text())
// << " rect size: " << label->rect().width()
// << " point size: " << label->font().pointSize();
// qDebug() << "Font size: " << label->fontMetrics().width(label->text())
// << " rect size: " << label->rect().width()
// << " point size: " << label->font().pointSize();

int newsize = label->font().pointSize() - 1;
label->setFont(QFont(label->font().family(), newsize));
Expand Down Expand Up @@ -46,7 +45,8 @@ AboutPatternPaint::AboutPatternPaint(QWidget *parent) :
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
}

void AboutPatternPaint::mousePressEvent(QMouseEvent *event) {
void AboutPatternPaint::mousePressEvent(QMouseEvent *event)
{
Q_UNUSED(event);
close();
}
Expand Down
1 change: 0 additions & 1 deletion PatternPaint/addressprogrammer.h
Expand Up @@ -7,7 +7,6 @@ namespace Ui {
class AddressProgrammer;
}


/// Dialog to enable the address programmer feature for LightBuddy controllers (program WS2821/WS2822s LEDs)
class AddressProgrammer : public QDialog
{
Expand Down
5 changes: 2 additions & 3 deletions PatternPaint/appnap.h
Expand Up @@ -9,12 +9,11 @@
class CAppNapInhibitor
{
public:
CAppNapInhibitor(const char* strReason);
CAppNapInhibitor(const char *strReason);
~CAppNapInhibitor();
private:
class Private;
Private* d;
Private *d;
};

#endif // APPNAP_H

13 changes: 5 additions & 8 deletions PatternPaint/colorchooser.cpp
Expand Up @@ -31,7 +31,7 @@
#include <QColorDialog>
#include <QDebug>

ColorChooser::ColorChooser(const QColor& color, QWidget *parent) :
ColorChooser::ColorChooser(const QColor &color, QWidget *parent) :
QLabel(parent),
colorDialog(this)
{
Expand All @@ -49,7 +49,7 @@ ColorChooser::ColorChooser(const QColor& color, QWidget *parent) :
colorDialog.setOptions(QColorDialog::NoButtons);

connect(&colorDialog, SIGNAL(currentColorChanged(const QColor &)),
this, SLOT(setAndSendColor(const QColor &)));
this, SLOT(setAndSendColor(const QColor &)));
}

ColorChooser::~ColorChooser()
Expand All @@ -58,9 +58,8 @@ ColorChooser::~ColorChooser()

void ColorChooser::setColor(const QColor &color)
{
if(!color.isValid()) {
if (!color.isValid())
return;
}

currentColor = color;

Expand All @@ -71,18 +70,16 @@ void ColorChooser::setColor(const QColor &color)

void ColorChooser::setAndSendColor(const QColor &color)
{
if(!color.isValid()) {
if (!color.isValid())
return;
}

setColor(color);
emit(sendColor(color));
}

void ColorChooser::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
if (event->button() == Qt::LeftButton) {
// TODO: If the user closed the dialog, this won't toggle for some reason?
colorDialog.setVisible(!colorDialog.isVisible());
}
Expand Down
5 changes: 2 additions & 3 deletions PatternPaint/colorchooser.h
Expand Up @@ -44,9 +44,9 @@ class ColorChooser : public QLabel
/// Constructor
/// @param color Default color
/// @param parent Pointer for parent.
explicit ColorChooser(const QColor& color, QWidget *parent = 0);
explicit ColorChooser(const QColor &color, QWidget *parent = 0);
~ColorChooser();

private:
QColor currentColor;
QPixmap pixmap;
Expand All @@ -69,7 +69,6 @@ public slots:

protected:
void mousePressEvent(QMouseEvent *event);

};

#endif // COLORCHOOSER_H
1,011 changes: 506 additions & 505 deletions PatternPaint/controllers/PatternPlayer_Sketch.h

Large diffs are not rendered by default.

1,459 changes: 730 additions & 729 deletions PatternPaint/controllers/ProductionSketch.h

Large diffs are not rendered by default.

35 changes: 19 additions & 16 deletions PatternPaint/controllers/avrprogrammer.cpp
Expand Up @@ -10,18 +10,20 @@ AvrProgrammer::AvrProgrammer(QObject *parent) :
}

// Send the command to probe for the device signature, and register the expected response
void AvrProgrammer::checkDeviceSignature() {
queueCommand("checkDeviceSignature",QByteArray("s"), QByteArray("\x87\x95\x1E"));
void AvrProgrammer::checkDeviceSignature()
{
queueCommand("checkDeviceSignature", QByteArray("s"), QByteArray("\x87\x95\x1E"));
}

void AvrProgrammer::reset()
{
queueCommand("reset",QByteArray("E"), QByteArray("\r"));
queueCommand("reset", QByteArray("E"), QByteArray("\r"));
}

void AvrProgrammer::setAddress(int address) {
void AvrProgrammer::setAddress(int address)
{
// TODO: Test if address > supported
if(address & 0x01) {
if (address & 0x01) {
// TODO: report error
qCritical() << "Address out of bounds";
}
Expand All @@ -35,7 +37,8 @@ void AvrProgrammer::setAddress(int address) {
queueCommand("setAddress", command, QByteArray("\r"));
}

void AvrProgrammer::readFlash(int startAddress, int lengthBytes) {
void AvrProgrammer::readFlash(int startAddress, int lengthBytes)
{
// Set the address to read from
// TODO: avoid the bootloader?
setAddress(startAddress);
Expand All @@ -50,22 +53,23 @@ void AvrProgrammer::readFlash(int startAddress, int lengthBytes) {

// Note: only the length matters for the response, the response data
// will be ignored.
queueCommand("readFlash",command,QByteArray(lengthBytes + 1, '\r'));
queueCommand("readFlash", command, QByteArray(lengthBytes + 1, '\r'));
}

void AvrProgrammer::writeFlash(QByteArray& data, int startAddress) {
if(startAddress%PAGE_SIZE_BYTES) {
void AvrProgrammer::writeFlash(QByteArray &data, int startAddress)
{
if (startAddress%PAGE_SIZE_BYTES) {
qCritical() << "Bad start address, must align with page boundary";
return;
}

if(data.length() == 0) {
if (data.length() == 0) {
qCritical() << "No data to write";
return;
}

// Pad the data length to an even number, since we can only write word-sized chunks
if(data.length() % 2 == 1) {
if (data.length() % 2 == 1) {
qDebug() << "Data length falls on a byte boundary, padding to a word boundary";
data.append(0xff);
}
Expand All @@ -75,18 +79,17 @@ void AvrProgrammer::writeFlash(QByteArray& data, int startAddress) {
setAddress(startAddress);

// Write the data in page-sized chunks
for(int currentChunkPosition = 0;
currentChunkPosition < data.length();
currentChunkPosition += PAGE_SIZE_BYTES) {

for (int currentChunkPosition = 0;
currentChunkPosition < data.length();
currentChunkPosition += PAGE_SIZE_BYTES) {
int currentChunkSize = std::min(PAGE_SIZE_BYTES, data.length() - currentChunkPosition);

QByteArray command;
command.append('B'); // command: write memory
command.append((currentChunkSize >> 8) & 0xFF); // read size (high)
command.append((currentChunkSize) & 0xFF); // read size (low)
command.append('F'); // memory type: flash
command.append(data.mid(currentChunkPosition,currentChunkSize));
command.append(data.mid(currentChunkPosition, currentChunkSize));

queueCommand("writeFlash", command, QByteArray("\r"));
}
Expand Down
2 changes: 1 addition & 1 deletion PatternPaint/controllers/avrprogrammer.h
Expand Up @@ -21,7 +21,7 @@ class AvrProgrammer : public SerialCommandQueue
/// data at the end may be erased.
/// @param data QByteArray containing the data to write to the flash
/// @param startAddress Page-aligned address to begin writing to, in bytes
void writeFlash(QByteArray& data, int startAddress);
void writeFlash(QByteArray &data, int startAddress);

/// These functions are direct implementations of the bootloader interface

Expand Down
41 changes: 19 additions & 22 deletions PatternPaint/controllers/avruploaddata.cpp
Expand Up @@ -10,13 +10,13 @@
#define PATTERN_TABLE_HEADER_LENGTH 3
#define PATTERN_TABLE_ENTRY_LENGTH 7


#define FLASH_MEMORY_AVAILABLE 0x7000 // Amount of application space in the flash
#define FLASH_MEMORY_PAGE_SIZE 0x80 // Size of a page of memory in our flash
#define FLASH_MEMORY_SKETCH_ADDRESS 0x0000 // Location of sketch
#define FLASH_MEMORY_PATTERN_TABLE_ADDRESS (FLASH_MEMORY_AVAILABLE - FLASH_MEMORY_PAGE_SIZE) // Location of pattern table

bool avrUploadData::init(std::vector<PatternWriter> patterns) {
bool avrUploadData::init(std::vector<PatternWriter> patterns)
{
char buff[BUFF_LENGTH];
QString errorString;

Expand All @@ -27,20 +27,20 @@ bool avrUploadData::init(std::vector<PatternWriter> patterns) {
patternData = QByteArray(); // Pattern Data
patternTable = QByteArray(); // Pattern data header

sketch.append(reinterpret_cast<const char*>(PATTERNPLAYER_DATA), sizeof(PATTERNPLAYER_DATA));
sketch.append(reinterpret_cast<const char *>(PATTERNPLAYER_DATA), sizeof(PATTERNPLAYER_DATA));

// Expand sketch size to FLASH_MEMORY_PAGE_SIZE boundary
while(sketch.length() % FLASH_MEMORY_PAGE_SIZE != 0) {
while (sketch.length() % FLASH_MEMORY_PAGE_SIZE != 0)
sketch.append(static_cast<char>(0xFF));
}


// Test for the minimum/maximum patterns count
if(patterns.size() == 0) {
if (patterns.size() == 0) {
errorString = QString("No Patterns detected!");
return false;
}
if(patterns.size() >= ((FLASH_MEMORY_PAGE_SIZE - PATTERN_TABLE_HEADER_LENGTH) / PATTERN_TABLE_ENTRY_LENGTH)) {
if (patterns.size()
>= ((FLASH_MEMORY_PAGE_SIZE - PATTERN_TABLE_HEADER_LENGTH) / PATTERN_TABLE_ENTRY_LENGTH)) {
errorString = QString("Too many patterns, cannot fit in pattern table.");
return false;
}
Expand All @@ -51,18 +51,18 @@ bool avrUploadData::init(std::vector<PatternWriter> patterns) {
qDebug() << buff;

patternTable.append(static_cast<char>(patterns.size())); // Offset 0: Pattern count (1 byte)
patternTable.append(static_cast<char>((patterns[0].getLedCount() ) & 0xFF)); // Offset 1: Number of LEDs connected to the controller (2 bytes)
patternTable.append(static_cast<char>((patterns[0].getLedCount()) & 0xFF)); // Offset 1: Number of LEDs connected to the controller (2 bytes)
patternTable.append(static_cast<char>((patterns[0].getLedCount() >> 8) & 0xFF));
// TODO: make the LED count to a separate, explicit parameter?

int dataOffset = sketch.length();

// Now, for each pattern, append the image data to the sketch
for(std::vector<PatternWriter>::iterator pattern = patterns.begin();
pattern != patterns.end();
++pattern) {

snprintf(buff, BUFF_LENGTH, "Adding pattern. Encoding: %x, framecount: %i, frameDelay: %i, count: %iB, offset: %iB",
for (std::vector<PatternWriter>::iterator pattern = patterns.begin();
pattern != patterns.end();
++pattern) {
snprintf(buff, BUFF_LENGTH,
"Adding pattern. Encoding: %x, framecount: %i, frameDelay: %i, count: %iB, offset: %iB",
pattern->getEncoding(),
pattern->getFrameCount(),
pattern->getFrameDelay(),
Expand All @@ -72,34 +72,31 @@ bool avrUploadData::init(std::vector<PatternWriter> patterns) {

// Build the table entry for this pattern
patternTable.append(static_cast<char>((pattern->getEncoding()) & 0xFF)); // Offset 0: encoding (1 byte)
patternTable.append(static_cast<char>((dataOffset ) & 0xFF)); // Offset 1: memory location (2 bytes)
patternTable.append(static_cast<char>((dataOffset) & 0xFF)); // Offset 1: memory location (2 bytes)
patternTable.append(static_cast<char>((dataOffset >> 8) & 0xFF));
patternTable.append(static_cast<char>((pattern->getFrameCount() ) & 0xFF)); // Offset 3: frame count (2 bytes)
patternTable.append(static_cast<char>((pattern->getFrameCount() >> 8 ) & 0xFF));
patternTable.append(static_cast<char>((pattern->getFrameDelay() ) & 0xFF)); // Offset 5: frame delay (2 bytes)
patternTable.append(static_cast<char>((pattern->getFrameDelay() >> 8 ) & 0xFF));
patternTable.append(static_cast<char>((pattern->getFrameCount()) & 0xFF)); // Offset 3: frame count (2 bytes)
patternTable.append(static_cast<char>((pattern->getFrameCount() >> 8) & 0xFF));
patternTable.append(static_cast<char>((pattern->getFrameDelay()) & 0xFF)); // Offset 5: frame delay (2 bytes)
patternTable.append(static_cast<char>((pattern->getFrameDelay() >> 8) & 0xFF));

// and append the image data
patternData += pattern->getData();
dataOffset += pattern->getData().length();
}

// Pad pattern table to FLASH_MEMORY_PAGE_SIZE bytes.
while(patternTable.length() < FLASH_MEMORY_PAGE_SIZE) {
while (patternTable.length() < FLASH_MEMORY_PAGE_SIZE)
patternTable.append(static_cast<char>(0xFF));
}

snprintf(buff, BUFF_LENGTH, "Sketch size: %iB, pattern data size: %iB, pattern table size: %iB",
sketch.length(),
patternData.length(),
patternTable.length());
qDebug() << buff;


sketchAddress = FLASH_MEMORY_SKETCH_ADDRESS;
patternDataAddress = FLASH_MEMORY_SKETCH_ADDRESS + sketch.length();
patternTableAddress = FLASH_MEMORY_PATTERN_TABLE_ADDRESS;

return true;
}

4 changes: 2 additions & 2 deletions PatternPaint/controllers/avruploaddata.h
Expand Up @@ -6,7 +6,8 @@
#include "patternwriter.h"

/// Memory class to
class avrUploadData {
class avrUploadData
{
public:
bool init(std::vector<PatternWriter> patterns);

Expand All @@ -21,5 +22,4 @@ class avrUploadData {
QString errorString;
};


#endif // AVRUPLOADDATA_H

0 comments on commit 0eaacbb

Please sign in to comment.