Code reformatted.

Former-commit-id: 6f3688791602efb33389c3ba789e7a8a723ee290
This commit is contained in:
RickDB 2016-03-15 12:03:00 +01:00
parent dcc6a9b449
commit e5545eaac0
2 changed files with 187 additions and 186 deletions

View File

@ -15,7 +15,7 @@ AtmoOrbLight::AtmoOrbLight(unsigned int id) {
// Not implemented
}
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const std::string& output, bool switchOffOnBlack,
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const std::string &output, bool switchOffOnBlack,
int transitiontime, int port, int numLeds, std::vector<unsigned int> orbIds) :
multicastGroup(output.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(transitiontime),
multiCastGroupPort(port), numLeds(numLeds), orbIds(orbIds) {
@ -28,19 +28,17 @@ LedDeviceAtmoOrb::LedDeviceAtmoOrb(const std::string& output, bool switchOffOnBl
joinedMulticastgroup = udpSocket->joinMulticastGroup(groupAddress);
}
int LedDeviceAtmoOrb::write(const std::vector<ColorRgb> & ledValues) {
int LedDeviceAtmoOrb::write(const std::vector <ColorRgb> &ledValues) {
// If not in multicast group return
if (!joinedMulticastgroup)
{
if (!joinedMulticastgroup) {
return 0;
}
// Iterate through colors and set Orb color
// Start off with idx 1 as 0 is reserved for controlling all orbs at once
unsigned int idx = 1;
for (const ColorRgb& color : ledValues)
{
for (const ColorRgb &color : ledValues) {
// Options parameter:
//
// 1 = force off
@ -51,18 +49,15 @@ int LedDeviceAtmoOrb::write(const std::vector<ColorRgb> & ledValues) {
if (switchOffOnBlack && color.red == 0 && color.green == 0 && color.blue == 0) {
// Force to black
for (unsigned int i = 0; i < orbIds.size(); i++) {
if (orbIds[i] == idx)
{
if (orbIds[i] == idx) {
setColor(idx, color, 1);
}
}
}
else
{
else {
// Default send color
for (unsigned int i = 0; i < orbIds.size(); i++) {
if (orbIds[i] == idx)
{
if (orbIds[i] == idx) {
setColor(idx, color, 4);
}
}
@ -74,7 +69,7 @@ int LedDeviceAtmoOrb::write(const std::vector<ColorRgb> & ledValues) {
return 0;
}
void LedDeviceAtmoOrb::setColor(unsigned int orbId, const ColorRgb& color, int commandType) {
void LedDeviceAtmoOrb::setColor(unsigned int orbId, const ColorRgb &color, int commandType) {
QByteArray bytes;
bytes.resize(5 + numLeds * 3);
bytes.fill('\0');
@ -98,7 +93,7 @@ void LedDeviceAtmoOrb::setColor(unsigned int orbId, const ColorRgb& color, int c
sendCommand(bytes);
}
void LedDeviceAtmoOrb::sendCommand(const QByteArray & bytes) {
void LedDeviceAtmoOrb::sendCommand(const QByteArray &bytes) {
QByteArray datagram = bytes;
udpSocket->writeDatagram(datagram.data(), datagram.size(),
groupAddress, multiCastGroupPort);

View File

@ -58,8 +58,12 @@ public:
///
/// @param array containing orb ids
///
LedDeviceAtmoOrb(const std::string& output, bool switchOffOnBlack =
false, int transitiontime = 0, int port = 49692, int numLeds = 24, std::vector<unsigned int> orbIds = std::vector<unsigned int>());
LedDeviceAtmoOrb(const std::string &output, bool switchOffOnBlack =
false, int transitiontime = 0, int port = 49692, int numLeds = 24,
std::vector<unsigned int> orbIds = std::vector < unsigned int
>());
///
/// Destructor of this device
///
@ -72,11 +76,13 @@ public:
///
/// @return Zero on success else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues);
virtual int write(const std::vector <ColorRgb> &ledValues);
virtual int switchOff();
private:
/// QNetworkAccessManager object for sending requests.
QNetworkAccessManager* manager;
QNetworkAccessManager *manager;
/// String containing multicast group IP address
QString multicastGroup;
@ -112,12 +118,12 @@ private:
///
/// @param commandType which type of command to send (off / smoothing / etc..)
///
void setColor(unsigned int orbId, const ColorRgb& color, int commandType);
void setColor(unsigned int orbId, const ColorRgb &color, int commandType);
///
/// Send Orb command
///
/// @param bytes the byte array containing command to send over multicast
///
void sendCommand(const QByteArray & bytes);
void sendCommand(const QByteArray &bytes);
};