From 7551a06cf4b800b51b284bbf42afbbc92d9015fd Mon Sep 17 00:00:00 2001 From: tociek Date: Thu, 12 Nov 2015 00:22:11 +0100 Subject: [PATCH 01/26] Corrected APA102 USB (adalight) led device I have removed the 'hack' that allowed to use APA102 with original version of adalight. I have modified adalight code and placed it into dependencies folder. This change is not backward compatible, so it won't work with original adalight code. The reason for the change is that last leds were not acting as they should (last led red). Additionally with this change and new arduino code, performance is lot better and lights change much smoother. I have also changed switchOff method that requires different data sent to apa102 to turn all leds off. Enjoy :) Jacek Former-commit-id: 624fe6c429aee896b150d23289f0be19e040474d --- dependencies/LightberryHDUSBAPA1021.1.zip | Bin 0 -> 4443 bytes libsrc/leddevice/LedDeviceAdalightApa102.cpp | 35 ++++++++++++++----- libsrc/leddevice/LedDeviceAdalightApa102.h | 8 +++-- 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 dependencies/LightberryHDUSBAPA1021.1.zip diff --git a/dependencies/LightberryHDUSBAPA1021.1.zip b/dependencies/LightberryHDUSBAPA1021.1.zip new file mode 100644 index 0000000000000000000000000000000000000000..13c743a080b77d837e04beb6a62e7e210ae984bc GIT binary patch literal 4443 zcmaJ_XH*l)x}^)DiS&>|Gjs%lp>vQH2)zWPNtYHtKoF@4(mRAEy%Uh$dx>-e6b(&! zGgLA3qWI1^_uTc~TkD=Xvu5_p`eyI_&EKu3Nld~(@aGT@bW!{3@b||02WmMxI(ggL zKYQi}S202;De5Ug?u$W0AfkGI)5!m#^#?AtjM5Si(DMBu^WSLyq$lG1)V21P02Ad^eTMXMCa_=TC$U!3J}TGL2F3p&uQtGeRzWAnkl)-E zx4pBov1ixZE9&q3W=D!ncEd0d(R}wc*wD6W-=M-|{Ei(&%<9RbQl+873kUCuc}28% zx@tH#7U5=ZNSwP?+0)h`#Z3A05lj_p6!3+qTTkbcmU%rqM zzV)znKsF~*(OL}SFE_E(oq#S-b?Hk0sl^=9k9xl~;4Zc!rhv8S-oe@WeJs=%xYMs) z==$+#@as4(oG<`p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RC$^S<^O;WNy PdnNi~9{quczdrXr;VLB$ literal 0 HcmV?d00001 diff --git a/libsrc/leddevice/LedDeviceAdalightApa102.cpp b/libsrc/leddevice/LedDeviceAdalightApa102.cpp index 07732080..5f5cc42e 100644 --- a/libsrc/leddevice/LedDeviceAdalightApa102.cpp +++ b/libsrc/leddevice/LedDeviceAdalightApa102.cpp @@ -3,7 +3,6 @@ #include #include #include -#include // Linux includes #include @@ -18,24 +17,23 @@ LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice _timer() { } -//comparing to ws2801 adalight, the following changes were needed: -// 1- differnt data frame (4 bytes instead of 3) -// 2 - in order to accomodate point 1 above, number of leds sent to adalight is increased by 1/3rd +// see dependencies folder for arduino sketch for APA102 int LedDeviceAdalightApa102::write(const std::vector & ledValues) { + ledCount = ledValues.size(); const unsigned int startFrameSize = 4; const unsigned int endFrameSize = std::max(((ledValues.size() + 15) / 16), 4); const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize; - if(_ledBuffer.size() != mLedCount){ - _ledBuffer.resize(mLedCount, 0xFF); + if(_ledBuffer.size() != mLedCount+6){ + _ledBuffer.resize(mLedCount+6, 0x00); _ledBuffer[0] = 'A'; _ledBuffer[1] = 'd'; _ledBuffer[2] = 'a'; - _ledBuffer[3] = (((unsigned int)(ledValues.size() * 1.33) - 1) >> 8) & 0xFF; // LED count high byte - _ledBuffer[4] = ((unsigned int)(ledValues.size() * 1.33) - 1) & 0xFF; // LED count low byte + _ledBuffer[3] = (((unsigned int)(ledValues.size())) >> 8) & 0xFF; // LED count high byte + _ledBuffer[4] = ((unsigned int)(ledValues.size())) & 0xFF; // LED count low byte _ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum } - + for (unsigned iLed=1; iLed<=ledValues.size(); iLed++) { const ColorRgb& rgb = ledValues[iLed-1]; _ledBuffer[iLed*4+6] = 0xFF; @@ -51,4 +49,23 @@ int LedDeviceAdalightApa102::write(const std::vector & ledValues) return writeBytes(_ledBuffer.size(), _ledBuffer.data()); } +int LedDeviceAdalightApa102::switchOff() +{ + for (unsigned iLed=1; iLed<=ledCount; iLed++) { + _ledBuffer[iLed*4+6] = 0xFF; + _ledBuffer[iLed*4+1+6] = 0x00; + _ledBuffer[iLed*4+2+6] = 0x00; + _ledBuffer[iLed*4+3+6] = 0x00; + } + // restart the timer + _timer.start(); + + // write data + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} + +void LedDeviceAdalightApa102::rewriteLeds() +{ + writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} diff --git a/libsrc/leddevice/LedDeviceAdalightApa102.h b/libsrc/leddevice/LedDeviceAdalightApa102.h index a0a7c89c..0c4b502a 100644 --- a/libsrc/leddevice/LedDeviceAdalightApa102.h +++ b/libsrc/leddevice/LedDeviceAdalightApa102.h @@ -32,13 +32,17 @@ public: /// @return Zero on succes else negative /// virtual int write(const std::vector & ledValues); + virtual int switchOff(); - +private slots: + /// Write the last data to the leds again + void rewriteLeds(); + private: /// The buffer containing the packed RGB values std::vector _ledBuffer; - + unsigned int ledCount; /// Timer object which makes sure that led data is written at a minimum rate /// The Adalight device will switch off when it does not receive data at least /// every 15 seconds From fa0b8db1314dd8edd5513d88cee9b5f4b928b5ec Mon Sep 17 00:00:00 2001 From: tociek Date: Mon, 23 Nov 2015 21:47:04 +0100 Subject: [PATCH 02/26] Fix to the adalightapa102 firmware Fix to the firmware when converter would require reconnect after 15 seconds of hyperion inactivity Former-commit-id: 1952eaad1ddbea3ce23252bb1d9c96ba29d72184 --- dependencies/LightberryHDUSBAPA1021.1.zip | Bin 4443 -> 4555 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/dependencies/LightberryHDUSBAPA1021.1.zip b/dependencies/LightberryHDUSBAPA1021.1.zip index 13c743a080b77d837e04beb6a62e7e210ae984bc..45d92c04034381b43ff720b959060fccd2bb4217 100644 GIT binary patch delta 4348 zcmV@6aWAK004KPc99J<4tJq;M_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08c3A<^BRAYD*w0! z7vW{6)GZM|6WyO(XQa4Md8aeaELZ1-x-6Q6|4Lck$0>V<=u?HE=xkD`e^eyCGFr-& z5ib!6IMJKao3%x>qK?iHt8&S9Iegg*Ci|I3YE!REfitQnT1vwqw{KZ_zPz zWxH>5E~U1-$x|r<*xzU<)M319o#}M}xH1K$RAGvG3=?{rQo2bgWlN+Ilmo9aD3^TS1>vYE^&ixiN@LMvq}e zJ0v$437b;cHlC!3Dg;|cm;Q<3JS%$ ze$c1Pkh8KF@e^HfBw{3d2i@&jB}nEOsc4nCYD2u>wn4+)-GzAzkmphA4v2d+w!MGj zxgv%uy6QfkQ{1ObFU)@)B&8?TS!auy>IFWxojTrC_E+ovO*=jXmOXilEI34 zoVbfLPAXa~H|C?Rp;*uT>)ErXqNR&^-$22nU8hPmqEeL|DVx&U(!A}}uu z=Hjn0XdzeBWRVZlu_qh^G52>FoUKwDoZmNAPA{T0UVze{3DvU&KjB3JNaL>;{JN*h zfulnXvfEl&TSzgdq*JNeszqC|V7;$)O4%~O`q80iZIBfoW3t#-81FXzqS^dddm3R~ zqpbM59BRjs`*?p?ai!5Z&s$8F43`||VWV_g5oReDbAExyMt*ncn%u)HT~n0a>5! Date: Thu, 26 Nov 2015 18:04:43 +0100 Subject: [PATCH 03/26] added the LightberryHDUSBAPA102.1.ino as a source file Former-commit-id: 4923f654cefc5a08df5424e6a2553111e6914b10 --- .../LightberryHDUSBAPA1021.1.ino | 271 ++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100644 dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino diff --git a/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino b/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino new file mode 100644 index 00000000..e4eca0a4 --- /dev/null +++ b/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino @@ -0,0 +1,271 @@ +// Arduino "bridge" code between host computer and WS2801-based digital +// RGB LED pixels (e.g. Adafruit product ID #322). Intended for use +// with USB-native boards such as Teensy or Adafruit 32u4 Breakout; +// works on normal serial Arduinos, but throughput is severely limited. +// LED data is streamed, not buffered, making this suitable for larger +// installations (e.g. video wall, etc.) than could otherwise be held +// in the Arduino's limited RAM. + +// Some effort is put into avoiding buffer underruns (where the output +// side becomes starved of data). The WS2801 latch protocol, being +// delay-based, could be inadvertently triggered if the USB bus or CPU +// is swamped with other tasks. This code buffers incoming serial data +// and introduces intentional pauses if there's a threat of the buffer +// draining prematurely. The cost of this complexity is somewhat +// reduced throughput, the gain is that most visual glitches are +// avoided (though ultimately a function of the load on the USB bus and +// host CPU, and out of our control). + +// LED data and clock lines are connected to the Arduino's SPI output. +// On traditional Arduino boards, SPI data out is digital pin 11 and +// clock is digital pin 13. On both Teensy and the 32u4 Breakout, +// data out is pin B2, clock is B1. LEDs should be externally +// powered -- trying to run any more than just a few off the Arduino's +// 5V line is generally a Bad Idea. LED ground should also be +// connected to Arduino ground. + +// -------------------------------------------------------------------- +// This file is part of Adalight. + +// Adalight is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. + +// Adalight is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. + +// You should have received a copy of the GNU Lesser General Public +// License along with Adalight. If not, see +// . +// -------------------------------------------------------------------- + +#include + +// LED pin for Adafruit 32u4 Breakout Board: +//#define LED_DDR DDRE +//#define LED_PORT PORTE +//#define LED_PIN _BV(PORTE6) +// LED pin for Teensy: +//#define LED_DDR DDRD +//#define LED_PORT PORTD +//#define LED_PIN _BV(PORTD6) +// LED pin for Arduino: +#define LED_DDR DDRB +#define LED_PORT PORTB +#define LED_PIN _BV(PORTB5) + +// A 'magic word' (along with LED count & checksum) precedes each block +// of LED data; this assists the microcontroller in syncing up with the +// host-side software and properly issuing the latch (host I/O is +// likely buffered, making usleep() unreliable for latch). You may see +// an initial glitchy frame or two until the two come into alignment. +// The magic word can be whatever sequence you like, but each character +// should be unique, and frequent pixel values like 0 and 255 are +// avoided -- fewer false positives. The host software will need to +// generate a compatible header: immediately following the magic word +// are three bytes: a 16-bit count of the number of LEDs (high byte +// first) followed by a simple checksum value (high byte XOR low byte +// XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B, +// where 0 = off and 255 = max brightness. + +static const uint8_t magic[] = {'A','d','a'}; +#define MAGICSIZE sizeof(magic) +#define HEADERSIZE (MAGICSIZE + 3) + +#define MODE_HEADER 0 +#define MODE_HOLD 1 +#define MODE_DATA 2 + +#define DATA_LED A5 +#define SPI_LED A3 + +// If no serial data is received for a while, the LEDs are shut off +// automatically. This avoids the annoying "stuck pixel" look when +// quitting LED display programs on the host computer. +static const unsigned long serialTimeout = 15000; // 15 seconds + +void setup() +{ + // Dirty trick: the circular buffer for serial data is 256 bytes, + // and the "in" and "out" indices are unsigned 8-bit types -- this + // much simplifies the cases where in/out need to "wrap around" the + // beginning/end of the buffer. Otherwise there'd be a ton of bit- + // masking and/or conditional code every time one of these indices + // needs to change, slowing things down tremendously. + uint8_t + buffer[256], + indexIn = 0, + indexOut = 0, + mode = MODE_HEADER, + hi, lo, chk, i, spiFlag; + int16_t + bytesBuffered = 0, + hold = 0, + c; + int32_t + bytesRemaining; + unsigned long + startTime, + lastByteTime, + lastAckTime, + t; + bool + data_in_led = false, + spi_out_led = false; + + LED_DDR |= LED_PIN; // Enable output for LED + LED_PORT &= ~LED_PIN; // LED off + pinMode(DATA_LED, OUTPUT); //data in led + pinMode(SPI_LED, OUTPUT); //data out led + + Serial.begin(115200); // Teensy/32u4 disregards baud rate; is OK! + + SPI.begin(); + SPI.setBitOrder(MSBFIRST); + SPI.setDataMode(SPI_MODE0); + SPI.setClockDivider(SPI_CLOCK_DIV16); // 1 MHz max, else flicker + + // Issue test pattern to LEDs on startup. This helps verify that + // wiring between the Arduino and LEDs is correct. Not knowing the + // actual number of LEDs connected, this sets all of them (well, up + // to the first 25,000, so as not to be TOO time consuming) to red, + // green, blue, then off. Once you're confident everything is working + // end-to-end, it's OK to comment this out and reprogram the Arduino. + uint8_t testcolor[] = { 0, 0, 0, 255, 0, 0 }; + for(int i=0; i<5; i++){ + for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); + } + for(char n=3; n>=0; n--) { + for(c=0; c<25000; c++) { + for(i=0; i<3; i++) { + for(SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); + } + for(i=0; i<1; i++) { + for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); + } + } + for(int i=0; i<16; i++){ + for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); + } + delay(1); // One millisecond pause = latch + digitalWrite(SPI_LED, spi_out_led = !spi_out_led); + } + + Serial.print("Ada\n"); // Send ACK string to host + + startTime = micros(); + lastByteTime = lastAckTime = millis(); + + // loop() is avoided as even that small bit of function overhead + // has a measurable impact on this code's overall throughput. + + for(;;) { + digitalWrite(DATA_LED, LOW); + digitalWrite(SPI_LED, LOW); + // Implementation is a simple finite-state machine. + // Regardless of mode, check for serial input each time: + t = millis(); + if((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) { + buffer[indexIn++] = c; + bytesBuffered++; + lastByteTime = lastAckTime = t; // Reset timeout counters + } else { + // No data received. If this persists, send an ACK packet + // to host once every second to alert it to our presence. + if((t - lastAckTime) > 1000) { + Serial.print("Ada\n"); // Send ACK string to host + lastAckTime = t; // Reset counter + } + // If no data received for an extended time, turn off all LEDs. + if((t - lastByteTime) > serialTimeout) { + for(c=0; c<25000; c++) { + for(i=0; i<3; i++) { + for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); + } + for(i=0; i<1; i++) { + for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); + } + } + delay(1); // One millisecond pause = latch + lastByteTime = t; // Reset counter + } + } + + switch(mode) { + + case MODE_HEADER: + + // In header-seeking mode. Is there enough data to check? + if(bytesBuffered >= HEADERSIZE) { + // Indeed. Check for a 'magic word' match. + for(i=0; (i 0) and multiply by 3 for R,G,B. + bytesRemaining = 4L * (256L * (long)hi + (long)lo) +4L + (256L *(long)hi + (long)lo +15)/16; + bytesBuffered -= 3; + spiFlag = 0; // No data out yet + mode = MODE_HOLD; // Proceed to latch wait mode + digitalWrite(DATA_LED, data_in_led = !data_in_led); + } else { + // Checksum didn't match; search resumes after magic word. + indexOut -= 3; // Rewind + } + } // else no header match. Resume at first mismatched byte. + bytesBuffered -= i; + } + break; + + case MODE_HOLD: + + // Ostensibly "waiting for the latch from the prior frame + // to complete" mode, but may also revert to this mode when + // underrun prevention necessitates a delay. + + if((micros() - startTime) < hold) break; // Still holding; keep buffering + + // Latch/delay complete. Advance to data-issuing mode... + LED_PORT &= ~LED_PIN; // LED off + mode = MODE_DATA; // ...and fall through (no break): + + case MODE_DATA: + digitalWrite(SPI_LED, spi_out_led = !spi_out_led); + while(spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte + if(bytesRemaining > 0) { + if(bytesBuffered > 0) { + SPDR = buffer[indexOut++]; // Issue next byte + bytesBuffered--; + bytesRemaining--; + spiFlag = 1; + } + // If serial buffer is threatening to underrun, start + // introducing progressively longer pauses to allow more + // data to arrive (up to a point). + // if((bytesBuffered < 32) && (bytesRemaining > bytesBuffered)) { + // startTime = micros(); + // hold = 100 + (32 - bytesBuffered) * 10; + // mode = MODE_HOLD; +//} + } else { + // End of data -- issue latch: + startTime = micros(); + hold = 1000; // Latch duration = 1000 uS + LED_PORT |= LED_PIN; // LED on + mode = MODE_HEADER; // Begin next header search + } + } // end switch + } // end for(;;) +} + +void loop() +{ + // Not used. See note in setup() function. +} From cf359e51821ecba664b7cf43e66b2b10288c9955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6ck=2C=20Florian?= Date: Thu, 26 Nov 2015 18:21:20 +0100 Subject: [PATCH 04/26] corrected the source to exactly match the protocol of the APA 102 LED's Former-commit-id: 10d097ff4bbcfa3c717c72138ea0cb1d9e629565 --- dependencies/LightberryHDUSBAPA1021.1.zip | Bin 4555 -> 4567 bytes .../LightberryHDUSBAPA1021.1.ino | 30 ++++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/dependencies/LightberryHDUSBAPA1021.1.zip b/dependencies/LightberryHDUSBAPA1021.1.zip index 45d92c04034381b43ff720b959060fccd2bb4217..7a9e6cb1202ba4dc6c24628541a91c3284ab6cb6 100644 GIT binary patch delta 4368 zcmY+I^-~m%_J-*$>0EM2rIBS>Qc{pcmu`d=0ci=B?(Xi8PAO?nx>uHPX;yjx5kbQH zxp(G%=_(iUpDcEz$90+;#TQLlhGh#h^*H9bo|vydU_S7_JvT3D`}v=L68z#)wija zTgsw!dGA|*8B5c~N|v%=RtNcgN@aq2*PS%!cxO&0vm*M<)fqwE0MY-b!hR zh2Ah@moP%mQG**mg0W7R*mA^^8(197A%@_&OVHC$d1vp-bY}Vf4t~@x@+}aXX`J*O z8UEgDOENJ_4=J{(XV`U-!~)y4;_f_ewn)Ymr)@<;%CJ)+l(%o}Ll@y^wL{V);N*-? zc*0d46X|6A?*0wRUx?FKQ%#DVGKzdN*yp2p>45|CkTKpit6B*SheH#9g}Qo7`JAz z^b8D+0`5GT3hs>%d7t1Y5~}LDrWG>hS8ATnHiXIM&N4%nOy^NWe5!JH1i8*0?+s+U zV%0Ue&8fMWk)~=6M@L3phnMe{h*iQ*Du=zi1cq{3^oYc^?3<4H6Ov(BkKDGUtTpjB-6xT);!hO0wJ!ue)9|qK{?Y zaUJFF8^}gR1riP(?wP6zIc+~C@qQa82)X+raQ6L#7^FE`%=SR35T7RK;zII-!ceCL zZ^SHnTvElM?LBX%w`p3(PLoP#{^G>T^y<{bbw7lxAA?>9H=>0?cyihg$PZ2E;W-Um z{PCgSi`zPC@e}+CfLT}Zowtw@)K)|CJ{yn{U>BqBIj&+ZF&ke(y3BCohVl8NG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for(i=0; i<1; i++) { - for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); + for(SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); //BGR } } - for(int i=0; i<16; i++){ - for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); + for(int i=0; i<4; i++){ //Stop Frame + for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); } delay(1); // One millisecond pause = latch digitalWrite(SPI_LED, spi_out_led = !spi_out_led); @@ -181,14 +179,18 @@ void setup() } // If no data received for an extended time, turn off all LEDs. if((t - lastByteTime) > serialTimeout) { - for(c=0; c<25000; c++) { - for(i=0; i<3; i++) { - for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); - } - for(i=0; i<1; i++) { - for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); - } + for(i=0;i<4;i++) { //Start Frame + for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); + } + for(c=0; c<25000; c++) { + for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness Byte + for(i=0; i<3; i++) { + for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); //BGR } + } + for(i=0;i<4;i++) { //Stop Frame + for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); + } delay(1); // One millisecond pause = latch lastByteTime = t; // Reset counter } From e7c9d9decd9b77a9e9ffdfc168ae9501814ff128 Mon Sep 17 00:00:00 2001 From: tociek Date: Sat, 28 Nov 2015 22:58:58 +0100 Subject: [PATCH 05/26] Performance fixes for adalightapa102 Adalightapa102 now inherits from RS232Device. Due to bad initialization, previous CPU usage on RPI1 could reach 60%. ON RPi2 20%. Now its about 3% with grabber in use. Former-commit-id: 7ebb72f503ad74a7768deedf648b9e84c0a7cf3c --- libsrc/leddevice/LedDeviceAdalightApa102.cpp | 21 +++++++++++++++----- libsrc/leddevice/LedDeviceAdalightApa102.h | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/libsrc/leddevice/LedDeviceAdalightApa102.cpp b/libsrc/leddevice/LedDeviceAdalightApa102.cpp index 5f5cc42e..9cbd3603 100644 --- a/libsrc/leddevice/LedDeviceAdalightApa102.cpp +++ b/libsrc/leddevice/LedDeviceAdalightApa102.cpp @@ -12,18 +12,27 @@ #include "LedDeviceAdalightApa102.h" LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) : - LedDeviceAdalight(outputDevice, baudrate, delayAfterConnect_ms), + LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms), _ledBuffer(0), _timer() { + // setup the timer + _timer.setSingleShot(false); + _timer.setInterval(5000); + connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds())); + + // start the timer + _timer.start(); } -// see dependencies folder for arduino sketch for APA102 +//comparing to ws2801 adalight, the following changes were needed: +// 1- differnt data frame (4 bytes instead of 3) +// 2 - in order to accomodate point 1 above, number of leds sent to adalight is increased by 1/3rd int LedDeviceAdalightApa102::write(const std::vector & ledValues) { ledCount = ledValues.size(); const unsigned int startFrameSize = 4; - const unsigned int endFrameSize = std::max(((ledValues.size() + 15) / 16), 4); - const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize; + const unsigned int endFrameSize = std::max(((ledCount + 15) / 16), 4); + const unsigned int mLedCount = (ledCount * 4) + startFrameSize + endFrameSize; if(_ledBuffer.size() != mLedCount+6){ _ledBuffer.resize(mLedCount+6, 0x00); _ledBuffer[0] = 'A'; @@ -34,7 +43,7 @@ int LedDeviceAdalightApa102::write(const std::vector & ledValues) _ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum } - for (unsigned iLed=1; iLed<=ledValues.size(); iLed++) { + for (unsigned iLed=1; iLed<=ledCount; iLed++) { const ColorRgb& rgb = ledValues[iLed-1]; _ledBuffer[iLed*4+6] = 0xFF; _ledBuffer[iLed*4+1+6] = rgb.red; @@ -57,11 +66,13 @@ int LedDeviceAdalightApa102::switchOff() _ledBuffer[iLed*4+2+6] = 0x00; _ledBuffer[iLed*4+3+6] = 0x00; } + // restart the timer _timer.start(); // write data return writeBytes(_ledBuffer.size(), _ledBuffer.data()); + } void LedDeviceAdalightApa102::rewriteLeds() diff --git a/libsrc/leddevice/LedDeviceAdalightApa102.h b/libsrc/leddevice/LedDeviceAdalightApa102.h index 0c4b502a..eef37662 100644 --- a/libsrc/leddevice/LedDeviceAdalightApa102.h +++ b/libsrc/leddevice/LedDeviceAdalightApa102.h @@ -7,12 +7,12 @@ #include // hyperion incluse -#include "LedDeviceAdalight.h" +#include "LedRs232Device.h" /// /// Implementation of the LedDevice interface for writing to an Adalight led device for APA102. /// -class LedDeviceAdalightApa102 : public LedDeviceAdalight +class LedDeviceAdalightApa102 : public LedRs232Device { Q_OBJECT From f910c717bbf022458049df92ec10da09429dc2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6ck=2C=20Florian?= Date: Sun, 29 Nov 2015 19:24:01 +0100 Subject: [PATCH 06/26] reformated code (Arduino IDE auto-reformat) Former-commit-id: 8f94b2bb865337ba7b0538617857432ea0376aea --- .../LightberryHDUSBAPA1021.1.ino | 208 +++++++++--------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino b/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino index 5d67cedf..7df0e0d9 100644 --- a/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino +++ b/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino @@ -71,7 +71,7 @@ // XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B, // where 0 = off and 255 = max brightness. -static const uint8_t magic[] = {'A','d','a'}; +static const uint8_t magic[] = {'A', 'd', 'a'}; #define MAGICSIZE sizeof(magic) #define HEADERSIZE (MAGICSIZE + 3) @@ -96,31 +96,31 @@ void setup() // masking and/or conditional code every time one of these indices // needs to change, slowing things down tremendously. uint8_t - buffer[256], - indexIn = 0, - indexOut = 0, - mode = MODE_HEADER, - hi, lo, chk, i, spiFlag; + buffer[256], + indexIn = 0, + indexOut = 0, + mode = MODE_HEADER, + hi, lo, chk, i, spiFlag; int16_t - bytesBuffered = 0, - hold = 0, - c; + bytesBuffered = 0, + hold = 0, + c; int32_t - bytesRemaining; + bytesRemaining; unsigned long - startTime, - lastByteTime, - lastAckTime, - t; - bool - data_in_led = false, - spi_out_led = false; - + startTime, + lastByteTime, + lastAckTime, + t; + bool + data_in_led = false, + spi_out_led = false; + LED_DDR |= LED_PIN; // Enable output for LED LED_PORT &= ~LED_PIN; // LED off pinMode(DATA_LED, OUTPUT); //data in led pinMode(SPI_LED, OUTPUT); //data out led - + Serial.begin(115200); // Teensy/32u4 disregards baud rate; is OK! SPI.begin(); @@ -135,18 +135,18 @@ void setup() // green, blue, then off. Once you're confident everything is working // end-to-end, it's OK to comment this out and reprogram the Arduino. uint8_t testcolor[] = { 0, 0, 0, 255, 0, 0 }; - for(int i=0; i<4; i++){ //Start Frame - for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); + for (int i = 0; i < 4; i++) { //Start Frame + for (SPDR = 0x00; !(SPSR & _BV(SPIF)); ); } - for(char n=3; n>=0; n--) { - for(c=0; c<25000; c++) { - for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness byte - for(i=0; i<3; i++) { - for(SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); //BGR + for (char n = 3; n >= 0; n--) { + for (c = 0; c < 25000; c++) { + for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness byte + for (i = 0; i < 3; i++) { + for (SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); //BGR } } - for(int i=0; i<4; i++){ //Stop Frame - for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); + for (int i = 0; i < 4; i++) { //Stop Frame + for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); } delay(1); // One millisecond pause = latch digitalWrite(SPI_LED, spi_out_led = !spi_out_led); @@ -160,109 +160,109 @@ void setup() // loop() is avoided as even that small bit of function overhead // has a measurable impact on this code's overall throughput. - for(;;) { + for (;;) { digitalWrite(DATA_LED, LOW); digitalWrite(SPI_LED, LOW); // Implementation is a simple finite-state machine. // Regardless of mode, check for serial input each time: t = millis(); - if((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) { + if ((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) { buffer[indexIn++] = c; bytesBuffered++; lastByteTime = lastAckTime = t; // Reset timeout counters } else { // No data received. If this persists, send an ACK packet // to host once every second to alert it to our presence. - if((t - lastAckTime) > 1000) { + if ((t - lastAckTime) > 1000) { Serial.print("Ada\n"); // Send ACK string to host lastAckTime = t; // Reset counter } // If no data received for an extended time, turn off all LEDs. - if((t - lastByteTime) > serialTimeout) { - for(i=0;i<4;i++) { //Start Frame - for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); + if ((t - lastByteTime) > serialTimeout) { + for (i = 0; i < 4; i++) { //Start Frame + for (SPDR = 0x00; !(SPSR & _BV(SPIF)); ); } - for(c=0; c<25000; c++) { - for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness Byte - for(i=0; i<3; i++) { - for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); //BGR + for (c = 0; c < 25000; c++) { + for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness Byte + for (i = 0; i < 3; i++) { + for (SPDR = 0x00; !(SPSR & _BV(SPIF)); ); //BGR } } - for(i=0;i<4;i++) { //Stop Frame - for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); + for (i = 0; i < 4; i++) { //Stop Frame + for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); } delay(1); // One millisecond pause = latch lastByteTime = t; // Reset counter } } - switch(mode) { + switch (mode) { - case MODE_HEADER: + case MODE_HEADER: - // In header-seeking mode. Is there enough data to check? - if(bytesBuffered >= HEADERSIZE) { - // Indeed. Check for a 'magic word' match. - for(i=0; (i 0) and multiply by 3 for R,G,B. - bytesRemaining = 4L * (256L * (long)hi + (long)lo) +4L + (256L *(long)hi + (long)lo +15)/16; - bytesBuffered -= 3; - spiFlag = 0; // No data out yet - mode = MODE_HOLD; // Proceed to latch wait mode - digitalWrite(DATA_LED, data_in_led = !data_in_led); - } else { - // Checksum didn't match; search resumes after magic word. - indexOut -= 3; // Rewind - } - } // else no header match. Resume at first mismatched byte. - bytesBuffered -= i; - } - break; - - case MODE_HOLD: - - // Ostensibly "waiting for the latch from the prior frame - // to complete" mode, but may also revert to this mode when - // underrun prevention necessitates a delay. - - if((micros() - startTime) < hold) break; // Still holding; keep buffering - - // Latch/delay complete. Advance to data-issuing mode... - LED_PORT &= ~LED_PIN; // LED off - mode = MODE_DATA; // ...and fall through (no break): - - case MODE_DATA: - digitalWrite(SPI_LED, spi_out_led = !spi_out_led); - while(spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte - if(bytesRemaining > 0) { - if(bytesBuffered > 0) { - SPDR = buffer[indexOut++]; // Issue next byte - bytesBuffered--; - bytesRemaining--; - spiFlag = 1; + // In header-seeking mode. Is there enough data to check? + if (bytesBuffered >= HEADERSIZE) { + // Indeed. Check for a 'magic word' match. + for (i = 0; (i < MAGICSIZE) && (buffer[indexOut++] == magic[i++]);); + if (i == MAGICSIZE) { + // Magic word matches. Now how about the checksum? + hi = buffer[indexOut++]; + lo = buffer[indexOut++]; + chk = buffer[indexOut++]; + if (chk == (hi ^ lo ^ 0x55)) { + // Checksum looks valid. Get 16-bit LED count, add 1 + // (# LEDs is always > 0) and multiply by 3 for R,G,B. + bytesRemaining = 4L * (256L * (long)hi + (long)lo) + 4L + (256L * (long)hi + (long)lo + 15) / 16; + bytesBuffered -= 3; + spiFlag = 0; // No data out yet + mode = MODE_HOLD; // Proceed to latch wait mode + digitalWrite(DATA_LED, data_in_led = !data_in_led); + } else { + // Checksum didn't match; search resumes after magic word. + indexOut -= 3; // Rewind + } + } // else no header match. Resume at first mismatched byte. + bytesBuffered -= i; + } + break; + + case MODE_HOLD: + + // Ostensibly "waiting for the latch from the prior frame + // to complete" mode, but may also revert to this mode when + // underrun prevention necessitates a delay. + + if ((micros() - startTime) < hold) break; // Still holding; keep buffering + + // Latch/delay complete. Advance to data-issuing mode... + LED_PORT &= ~LED_PIN; // LED off + mode = MODE_DATA; // ...and fall through (no break): + + case MODE_DATA: + digitalWrite(SPI_LED, spi_out_led = !spi_out_led); + while (spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte + if (bytesRemaining > 0) { + if (bytesBuffered > 0) { + SPDR = buffer[indexOut++]; // Issue next byte + bytesBuffered--; + bytesRemaining--; + spiFlag = 1; + } + // If serial buffer is threatening to underrun, start + // introducing progressively longer pauses to allow more + // data to arrive (up to a point). + // if((bytesBuffered < 32) && (bytesRemaining > bytesBuffered)) { + // startTime = micros(); + // hold = 100 + (32 - bytesBuffered) * 10; + // mode = MODE_HOLD; + //} + } else { + // End of data -- issue latch: + startTime = micros(); + hold = 1000; // Latch duration = 1000 uS + LED_PORT |= LED_PIN; // LED on + mode = MODE_HEADER; // Begin next header search } - // If serial buffer is threatening to underrun, start - // introducing progressively longer pauses to allow more - // data to arrive (up to a point). - // if((bytesBuffered < 32) && (bytesRemaining > bytesBuffered)) { - // startTime = micros(); - // hold = 100 + (32 - bytesBuffered) * 10; - // mode = MODE_HOLD; -//} - } else { - // End of data -- issue latch: - startTime = micros(); - hold = 1000; // Latch duration = 1000 uS - LED_PORT |= LED_PIN; // LED on - mode = MODE_HEADER; // Begin next header search - } } // end switch } // end for(;;) } From 4cdba8cdb689cf158074b179136c3f5a75d98f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6ck=2C=20Florian?= Date: Sun, 29 Nov 2015 19:31:51 +0100 Subject: [PATCH 07/26] fixed boot animation Former-commit-id: 418ed83a4bd4ddaae79bf41de7fd9fb0794f8239 --- .../LightberryHDUSBAPA1021.1.ino | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino b/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino index 7df0e0d9..e10c8c3b 100644 --- a/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino +++ b/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino @@ -135,10 +135,10 @@ void setup() // green, blue, then off. Once you're confident everything is working // end-to-end, it's OK to comment this out and reprogram the Arduino. uint8_t testcolor[] = { 0, 0, 0, 255, 0, 0 }; - for (int i = 0; i < 4; i++) { //Start Frame - for (SPDR = 0x00; !(SPSR & _BV(SPIF)); ); - } for (char n = 3; n >= 0; n--) { + for (int i = 0; i < 4; i++) { //Start Frame + for (SPDR = 0x00; !(SPSR & _BV(SPIF)); ); + } for (c = 0; c < 25000; c++) { for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness byte for (i = 0; i < 3; i++) { @@ -148,9 +148,10 @@ void setup() for (int i = 0; i < 4; i++) { //Stop Frame for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); } + delay(1); // One millisecond pause = latch - digitalWrite(SPI_LED, spi_out_led = !spi_out_led); } + digitalWrite(SPI_LED, spi_out_led = !spi_out_led); Serial.print("Ada\n"); // Send ACK string to host From f950ec7df6dbd5627bd6870616736f725a2dbb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6ck=2C=20Florian?= Date: Sun, 29 Nov 2015 19:35:26 +0100 Subject: [PATCH 08/26] changed the SPI frequency to 2 Mhz. APA102 can handle MUCH higher frequencies than WS2801, so 2Mhz is no big deal for them Former-commit-id: 814faa648e4f39d7105710ff872bde00aaeaada9 --- .../LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino b/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino index e10c8c3b..4a02d71a 100644 --- a/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino +++ b/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino @@ -126,7 +126,7 @@ void setup() SPI.begin(); SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); - SPI.setClockDivider(SPI_CLOCK_DIV16); // 1 MHz max, else flicker + SPI.setClockDivider(SPI_CLOCK_DIV8); // 2Mhz // Issue test pattern to LEDs on startup. This helps verify that // wiring between the Arduino and LEDs is correct. Not knowing the From 8d52466acdaa180651db17eb818c77606075e3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6ck=2C=20Florian?= Date: Sun, 29 Nov 2015 19:38:40 +0100 Subject: [PATCH 09/26] re-added buffer underrun handling should not be necessary because the number of LED's in a usual Lightberry setup is to low, but it's nice to have implemented. Former-commit-id: def3c46687670439be572e6b9c2dd1de5be2f1b5 --- .../LightberryHDUSBAPA1021.1.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino b/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino index 4a02d71a..603599c9 100644 --- a/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino +++ b/dependencies/LightberryHDUSBAPA1021.1/LightberryHDUSBAPA1021.1.ino @@ -252,11 +252,11 @@ void setup() // If serial buffer is threatening to underrun, start // introducing progressively longer pauses to allow more // data to arrive (up to a point). - // if((bytesBuffered < 32) && (bytesRemaining > bytesBuffered)) { - // startTime = micros(); - // hold = 100 + (32 - bytesBuffered) * 10; - // mode = MODE_HOLD; - //} + if ((bytesBuffered < 32) && (bytesRemaining > bytesBuffered)) { + startTime = micros(); + hold = 100 + (32 - bytesBuffered) * 10; + mode = MODE_HOLD; + } } else { // End of data -- issue latch: startTime = micros(); From b898f25f980f804df4fff6aa555f3c386b456d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6ck=2C=20Florian?= Date: Sun, 29 Nov 2015 19:56:33 +0100 Subject: [PATCH 10/26] updated zip to match newest source Former-commit-id: 2e54f40d48a993a66f07f5b655965847a9bf7d14 --- dependencies/LightberryHDUSBAPA1021.1.zip | Bin 4567 -> 4548 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/dependencies/LightberryHDUSBAPA1021.1.zip b/dependencies/LightberryHDUSBAPA1021.1.zip index 7a9e6cb1202ba4dc6c24628541a91c3284ab6cb6..af1527aecae1ce355ffcfb87ef4cbd813a79f5fa 100644 GIT binary patch delta 4318 zcmV<45Fzi^Bg7*OP)h>@6aWAK004-beUS|`4Tzk5M-fmxQZf(#0Pc}aK7Va*A~z8J z&aarJQWI1Hd1;Igc#?G2%CzrD}QdV!>O?U&w%JmiETZq*J{|iA^<)by#Vg)6DvSmBq3M+L6jr`hIxw=IHovth`Ps zHB%E*Rs+u9U59S2yR!|RWK~^Tr=waA7%vCT?FvBXBdh$gwBjsrXll+>j+XA1S6kkxsX*IV+xDX8M=ALX$ zxpfPbk=M@PSG=ch(6|T`X3iGV8LmafL*z+2ovkS|3lntO1dd!LRewQ=K!ApYP8$FX z0GLd) zmt2h(^H2b*VM2_!m<$}rTDU?oP_r0J;AlW(sgQU+n&342s(&~&v`O+WqD>5BA4$vmt6rIscQCegBLjXID=mf zwzHqIdb74$0e>QuWHy;2?efwb7R_}M_&WAgZVvBzF{7lA`mn*N)I^_0xmeo`krpjh zim~DpTEZ#E$I;}d{`K~0lNf%C)QIH3@@&paVrT$jSBaeNoHVwuont`Z!idM8h?5Pr%qmahGEXW6DP9Hsm`@y zc*u7UtX`^BX$4K4MWI%UC09lQ&uz!7R$2bZO0vKACx6gv`Z}7G^y1O0@>1}^NZMts{M!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jsr`Zj0T?K3KlyazGJe@@K)9`JeoaMXO{t*OVW%3+7dwhqX*6@`Vd zQ#%dF(D*aS2ukt&+m1vQLjUf>Nu*4!$lEI3hLPz3#G}&Q9`t(2edv8mcKzUvaErs( zd^(%`O|%Z7+DaJ=QTC+}&Xv{P*x%_yEl3#}5Ox*zLt zZDXEmft5w4uIq@5E)6fN);>xq4f?qU`JNH#YGUKaWBreYQ2Q?*@!uzPi3%jf1GV>e z;-AC*PvYTKS^vBLFGz&-|HMVA!XsnhGL@S$*Z)KPht}1^C;0bwoPYM>pPczebzour E3nIf=oB#j- From 8a6414b2509877202abdaa32c12ae2b68f21807b Mon Sep 17 00:00:00 2001 From: snoerenberg Date: Wed, 9 Dec 2015 16:08:26 +0100 Subject: [PATCH 11/26] New X-Mas Effect added Former-commit-id: d34644b1cab491b4f5c326d77098d9ee198f0b11 --- effects/x-mas.json | 8 ++++++++ effects/x-mas.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 effects/x-mas.json create mode 100644 effects/x-mas.py diff --git a/effects/x-mas.json b/effects/x-mas.json new file mode 100644 index 00000000..99bece03 --- /dev/null +++ b/effects/x-mas.json @@ -0,0 +1,8 @@ +{ + "name" : "X-Mas", + "script" : "x-mas.py", + "args" : + { + "frequency" : 50.0 + } +} diff --git a/effects/x-mas.py b/effects/x-mas.py new file mode 100644 index 00000000..bdeda2e7 --- /dev/null +++ b/effects/x-mas.py @@ -0,0 +1,34 @@ +import hyperion +import time +import colorsys + +# Get the parameters +frequency = float(hyperion.args.get('frequency', 10.0)) + +# Check parameters +frequency = min(100.0, frequency) + +# Compute the strobe interval +sleepTime = 1.0 / frequency + +# Initialize the led data +ledDataOdd = bytearray() +for i in range(hyperion.ledCount): + if i%2 == 0: + ledDataOdd += bytearray((int(255), int(0), int(0))) + else: + ledDataOdd += bytearray((int(255), int(255), int(255))) + +ledDataEven = bytearray() +for i in range(hyperion.ledCount): + if i%2 == 0: + ledDataEven += bytearray((int(255), int(255), int(255))) + else: + ledDataEven += bytearray((int(255), int(0), int(0))) + +# Start the write data loop +while not hyperion.abort(): + hyperion.setColor(ledDataOdd) + time.sleep(0.75) + hyperion.setColor(ledDataEven) + time.sleep(0.75) \ No newline at end of file From d3b3ce7630d524e82ff212cf658e99f1a6ea3064 Mon Sep 17 00:00:00 2001 From: snoerenberg Date: Wed, 9 Dec 2015 16:18:08 +0100 Subject: [PATCH 12/26] New X-Mas Effect added Former-commit-id: b5fb724f5b07f1cd55fef620c02f285522680cf6 --- effects/x-mas.json | 2 +- effects/x-mas.py | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/effects/x-mas.json b/effects/x-mas.json index 99bece03..72892a52 100644 --- a/effects/x-mas.json +++ b/effects/x-mas.json @@ -3,6 +3,6 @@ "script" : "x-mas.py", "args" : { - "frequency" : 50.0 + "sleepTime" : 0.75 } } diff --git a/effects/x-mas.py b/effects/x-mas.py index bdeda2e7..697d6f71 100644 --- a/effects/x-mas.py +++ b/effects/x-mas.py @@ -3,13 +3,7 @@ import time import colorsys # Get the parameters -frequency = float(hyperion.args.get('frequency', 10.0)) - -# Check parameters -frequency = min(100.0, frequency) - -# Compute the strobe interval -sleepTime = 1.0 / frequency +sleepTime = float(hyperion.args.get('sleepTime', 1.0)) # Initialize the led data ledDataOdd = bytearray() @@ -29,6 +23,6 @@ for i in range(hyperion.ledCount): # Start the write data loop while not hyperion.abort(): hyperion.setColor(ledDataOdd) - time.sleep(0.75) + time.sleep(sleepTime) hyperion.setColor(ledDataEven) - time.sleep(0.75) \ No newline at end of file + time.sleep(sleepTime) \ No newline at end of file From 45d3572df166da712825e6d3fbe430b92fd78da7 Mon Sep 17 00:00:00 2001 From: guddimon- Date: Mon, 14 Dec 2015 00:15:15 +0100 Subject: [PATCH 13/26] always work with trimmed messages Former-commit-id: a2b3236d22cd935c03a13dfe579c411c648c7dfd --- libsrc/boblightserver/BoblightClientConnection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/boblightserver/BoblightClientConnection.cpp b/libsrc/boblightserver/BoblightClientConnection.cpp index f78d6784..7599220a 100644 --- a/libsrc/boblightserver/BoblightClientConnection.cpp +++ b/libsrc/boblightserver/BoblightClientConnection.cpp @@ -64,8 +64,8 @@ void BoblightClientConnection::readData() // remove message data from buffer _receiveBuffer = _receiveBuffer.mid(bytes); - // handle message - handleMessage(message); + // handle trimmed message + handleMessage(message.trimmed()); // drop messages if the buffer is too full if (_receiveBuffer.size() > 100*1024) From 87f2883f565d5e5287fe44feba90f7fd54a14e15 Mon Sep 17 00:00:00 2001 From: guddimon- Date: Mon, 14 Dec 2015 00:23:53 +0100 Subject: [PATCH 14/26] replace decimal comma with decimal point Former-commit-id: ec4b3c264fb06143b2e4d635358f259fb7099ed9 --- libsrc/boblightserver/BoblightClientConnection.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libsrc/boblightserver/BoblightClientConnection.cpp b/libsrc/boblightserver/BoblightClientConnection.cpp index 7599220a..e70a8f17 100644 --- a/libsrc/boblightserver/BoblightClientConnection.cpp +++ b/libsrc/boblightserver/BoblightClientConnection.cpp @@ -132,9 +132,15 @@ void BoblightClientConnection::handleMessage(const QString & message) { if (messageParts[3] == "rgb" && messageParts.size() == 7) { + // replace decimal comma with decimal point + messageParts[4].replace(',', '.'); + messageParts[5].replace(',', '.'); + messageParts[6].replace(',', '.'); + bool rc1, rc2, rc3; uint8_t red = qMax(0, qMin(255, int(255 * messageParts[4].toFloat(&rc1)))); + // check for correct locale should not be needed anymore - please check! if (!rc1) { // maybe a locale issue. switch to a locale with a comma instead of a dot as decimal seperator (or vice versa) From 469ea42f49dc986d0bc507c5d6b1fa4adca0156d Mon Sep 17 00:00:00 2001 From: wisc Date: Sat, 2 Jan 2016 02:31:13 +0100 Subject: [PATCH 15/26] check for black pixel at center x/y Former-commit-id: d91f422f55638418d2517d91b1c925880d7ca448 --- include/blackborder/BlackBorderDetector.h | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/include/blackborder/BlackBorderDetector.h b/include/blackborder/BlackBorderDetector.h index c5ee91e7..3f190c5c 100644 --- a/include/blackborder/BlackBorderDetector.h +++ b/include/blackborder/BlackBorderDetector.h @@ -61,11 +61,51 @@ namespace hyperion template BlackBorder process(const Image & image) { + + // only test the topleft third of the image + int width = image.width() / 3; + int height = image.height() / 3; + int xCenter = image.width() / 2; + int yCenter = image.height() / 2; +// int maxSize = std::max(width, height); + + + + int firstNonBlackXPixelIndex = -1; + int firstNonBlackYPixelIndex = -1; + + // find first X pixel of the image + for (int x = 0; x < width; ++x) + { + const Pixel_T & color = image(x, yCenter); + if (!isBlack(color)) + { + firstNonBlackXPixelIndex = x; + break; + } + } + + // find first Y pixel of the image + for (int y = 0; y < height; ++y) + { + const Pixel_T & color = image(xCenter, y); + if (!isBlack(color)) + { + firstNonBlackYPixelIndex = y; + break; + } + } + + + +/* // only test the topleft third of the image int width = image.width() /3; int height = image.height() / 3; int maxSize = std::max(width, height); + + int firstNonBlackXPixelIndex = -1; int firstNonBlackYPixelIndex = -1; @@ -103,6 +143,7 @@ namespace hyperion break; } } +*/ // Construct result BlackBorder detectedBorder; From 633985930b8ba55e001656d06f81b0034613e37c Mon Sep 17 00:00:00 2001 From: wisc Date: Mon, 4 Jan 2016 00:20:47 +0100 Subject: [PATCH 16/26] 3line detection Former-commit-id: a63c03bc276ef218981213fbb9743a3d6d12d8b6 --- include/blackborder/BlackBorderDetector.h | 14 ++++++++++---- libsrc/blackborder/BlackBorderProcessor.cpp | 21 +++++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/include/blackborder/BlackBorderDetector.h b/include/blackborder/BlackBorderDetector.h index 3f190c5c..cd955b8a 100644 --- a/include/blackborder/BlackBorderDetector.h +++ b/include/blackborder/BlackBorderDetector.h @@ -65,6 +65,8 @@ namespace hyperion // only test the topleft third of the image int width = image.width() / 3; int height = image.height() / 3; + int width2 = width * 2; + int height2 = height * 2; int xCenter = image.width() / 2; int yCenter = image.height() / 2; // int maxSize = std::max(width, height); @@ -77,8 +79,10 @@ namespace hyperion // find first X pixel of the image for (int x = 0; x < width; ++x) { - const Pixel_T & color = image(x, yCenter); - if (!isBlack(color)) + const Pixel_T & color1 = image(x, yCenter); + const Pixel_T & color2 = image(x, height); + const Pixel_T & color3 = image(x, height2); + if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3)) { firstNonBlackXPixelIndex = x; break; @@ -88,8 +92,10 @@ namespace hyperion // find first Y pixel of the image for (int y = 0; y < height; ++y) { - const Pixel_T & color = image(xCenter, y); - if (!isBlack(color)) + const Pixel_T & color1 = image(xCenter, y); + const Pixel_T & color2 = image(width, y); + const Pixel_T & color3 = image(width2, y); + if (!isBlack(color1) || !isBlack(color2) || !isBlack(color3)) { firstNonBlackYPixelIndex = y; break; diff --git a/libsrc/blackborder/BlackBorderProcessor.cpp b/libsrc/blackborder/BlackBorderProcessor.cpp index ee78efb9..b9c21eea 100644 --- a/libsrc/blackborder/BlackBorderProcessor.cpp +++ b/libsrc/blackborder/BlackBorderProcessor.cpp @@ -1,4 +1,4 @@ - +//#include // Blackborder includes #include @@ -29,7 +29,10 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) // set the consistency counter if (newDetectedBorder == _previousDetectedBorder) { - ++_consistentCnt; + if (_consistentCnt < 100000) + { + ++_consistentCnt; + } } else { @@ -37,6 +40,8 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) _consistentCnt = 0; } +// std::cout << "new: " << newDetectedBorder.verticalSize << " " << newDetectedBorder.horizontalSize << " cur: " << _currentBorder.verticalSize << " " << _currentBorder.horizontalSize << " cc " << _consistentCnt << std::endl; + // check if there is a change if (_currentBorder == newDetectedBorder) { @@ -48,7 +53,8 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) if (newDetectedBorder.unknown) { // apply the unknown border if we consistently can't determine a border - if (_consistentCnt == _unknownSwitchCnt) +// if (_consistentCnt == _unknownSwitchCnt) + if (_consistentCnt >= _unknownSwitchCnt) { _currentBorder = newDetectedBorder; borderChanged = true; @@ -57,7 +63,8 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) else { // apply the detected border if it has been detected consistently - if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt) +// if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt) + if (_currentBorder.unknown || _consistentCnt >= _borderSwitchCnt) { _currentBorder = newDetectedBorder; borderChanged = true; @@ -65,13 +72,15 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) else { // apply smaller borders immediately - if (newDetectedBorder.verticalSize < _currentBorder.verticalSize) +// if (newDetectedBorder.verticalSize < _currentBorder.verticalSize) + if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (_consistentCnt >= 1) )// almost immediatly - avoid switching for "abnormal" frames { _currentBorder.verticalSize = newDetectedBorder.verticalSize; borderChanged = true; } - if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) +// if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) + if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (_consistentCnt >= 1) ) { _currentBorder.horizontalSize = newDetectedBorder.horizontalSize; borderChanged = true; From 0dcacede815f8dc31adfc87496f17a806cdc5bd7 Mon Sep 17 00:00:00 2001 From: redpanther Date: Mon, 4 Jan 2016 12:06:56 +0100 Subject: [PATCH 17/26] add fadecandy led device Former-commit-id: 4076e6ec2860ceaa53fdd07c47c40e45f2329de9 --- libsrc/leddevice/LedDeviceFadeCandy.cpp | 89 +++++++++++++++++++++++++ libsrc/leddevice/LedDeviceFadeCandy.h | 55 +++++++++++++++ 2 files changed, 144 insertions(+) create mode 100755 libsrc/leddevice/LedDeviceFadeCandy.cpp create mode 100755 libsrc/leddevice/LedDeviceFadeCandy.h diff --git a/libsrc/leddevice/LedDeviceFadeCandy.cpp b/libsrc/leddevice/LedDeviceFadeCandy.cpp new file mode 100755 index 00000000..ec6da6a2 --- /dev/null +++ b/libsrc/leddevice/LedDeviceFadeCandy.cpp @@ -0,0 +1,89 @@ + +// Local-Hyperion includes +#include "LedDeviceFadeCandy.h" +#include +#include +#include + +static const unsigned MAX_NUM_LEDS = 512; + +/* OPC broadcast channel */ +static const unsigned OPC_BROADCAST = 0; + +/* OPC command codes */ +static const unsigned OPC_SET_PIXELS = 0; + +LedDeviceFadeCandy::LedDeviceFadeCandy(const std::string& host, const uint16_t port) + : _host(host), _port(port) +{ + _opc_data.resize(4); + _opc_data[0] = OPC_BROADCAST; + _opc_data[1] = OPC_SET_PIXELS; + _opc_data[2] = 0; + _opc_data[3] = 0; + + qDebug("connect to %s %i",_host.c_str(),_port); +} + +LedDeviceFadeCandy::~LedDeviceFadeCandy() +{ + _client.close(); +} + +bool LedDeviceFadeCandy::isConnected() +{ + return _client.state() == QAbstractSocket::ConnectedState; +} + +bool LedDeviceFadeCandy::tryConnect() +{ + if ( _client.state() == QAbstractSocket::UnconnectedState ) { + qDebug("connecting"); + QHostAddress addr(_host.c_str()); + _client.connectToHost(addr, _port); + if (_client.waitForConnected(1000)) + qDebug("connected"); + } + + return isConnected(); +} + + +int LedDeviceFadeCandy::write(const std::vector & ledValues) +{ + ssize_t nrLedValues = ledValues.size(); + ssize_t led_data_size = nrLedValues*3; // 3 color bytes + ssize_t opc_data_size = led_data_size +4; // + 4 byte header + + if (nrLedValues > MAX_NUM_LEDS) + { + std::cerr << "Invalid attempt to write led values. Not more than " << MAX_NUM_LEDS << " leds are allowed." << std::endl; + return -1; + } + + if ( opc_data_size != _opc_data.size()) + _opc_data.resize(opc_data_size); + + _opc_data[2] = led_data_size >> 8; + _opc_data[3] = led_data_size & 0xff; + + if ( isConnected() || tryConnect() ) { + u_int16_t idx = 4; + for (const ColorRgb& color : ledValues) + { + _opc_data[idx] = unsigned(color.red); + _opc_data[idx+1] = unsigned(color.green); + _opc_data[idx+2] = unsigned(color.blue); + idx += 3; + } + _client.write(_opc_data, opc_data_size); + } + + return 0; +} + + +int LedDeviceFadeCandy::switchOff() +{ + return 0; +} diff --git a/libsrc/leddevice/LedDeviceFadeCandy.h b/libsrc/leddevice/LedDeviceFadeCandy.h new file mode 100755 index 00000000..0973368b --- /dev/null +++ b/libsrc/leddevice/LedDeviceFadeCandy.h @@ -0,0 +1,55 @@ +#pragma once + +// STL includes0 +#include +#include +#include +#include +#include +#include + +// Leddevice includes +#include + + +/// +/// Implementation of the LedDevice that write the led-colors to an +/// ASCII-textfile('/home/pi/LedDevice.out') +/// +class LedDeviceFadeCandy : public QObject,public LedDevice +{ + Q_OBJECT +public: + /// + /// Constructs the test-device, which opens an output stream to the file + /// + LedDeviceFadeCandy(const std::string& host, const uint16_t port); + + /// + /// Destructor of this test-device + /// + virtual ~LedDeviceFadeCandy(); + + /// + /// Writes the given led-color values to the output stream + /// + /// @param ledValues The color-value per led + /// + /// @return Zero on success else negative + /// + virtual int write(const std::vector & ledValues); + + /// Switch the leds off + virtual int switchOff(); + + bool tryConnect(); + bool isConnected(); + +//public slots: + +private: + QTcpSocket _client; + const std::string _host; + const uint16_t _port; + QByteArray _opc_data; +}; From 13715202d8e25d2fca75dbe0b721dcdae6917bc8 Mon Sep 17 00:00:00 2001 From: redpanther Date: Mon, 4 Jan 2016 12:16:44 +0100 Subject: [PATCH 18/26] add fadecandy led device Former-commit-id: 490fd3ee66041b35b95d2c7ec110cc70e4c01d8d --- libsrc/leddevice/CMakeLists.txt | 6 +++++- libsrc/leddevice/LedDeviceFactory.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index d6d4682c..3f4fb983 100755 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -20,6 +20,8 @@ SET(Leddevice_QT_HEADERS ${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.h ${CURRENT_SOURCE_DIR}/LedHIDDevice.h ${CURRENT_SOURCE_DIR}/LedDeviceRawHID.h + ${CURRENT_SOURCE_DIR}/LedDeviceTest.h + ${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h ) SET(Leddevice_HEADERS @@ -32,6 +34,7 @@ SET(Leddevice_HEADERS ${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.h ${CURRENT_SOURCE_DIR}/LedDeviceSedu.h ${CURRENT_SOURCE_DIR}/LedDeviceTest.h + ${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h ${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h ${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h ${CURRENT_SOURCE_DIR}/LedDeviceAtmo.h @@ -53,6 +56,7 @@ SET(Leddevice_SOURCES ${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.cpp ${CURRENT_SOURCE_DIR}/LedDeviceSedu.cpp ${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp + ${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.cpp ${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp ${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp ${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp @@ -114,7 +118,7 @@ add_library(leddevice target_link_libraries(leddevice hyperion-utils - serialport + serialport ${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev ${CMAKE_THREAD_LIBS_INIT} ${QT_LIBRARIES} diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index 85f665a5..f6f3acf3 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -30,6 +30,7 @@ #include "LedDevicePiBlaster.h" #include "LedDeviceSedu.h" #include "LedDeviceTest.h" +#include "LedDeviceFadeCandy.h" #include "LedDeviceHyperionUsbasp.h" #include "LedDevicePhilipsHue.h" #include "LedDeviceTpm2.h" @@ -243,6 +244,12 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) const std::string output = deviceConfig["output"].asString(); device = new LedDeviceTest(output); } + else if (type == "fadecandy") + { + const std::string host = deviceConfig.get("output", "127.0.0.1").asString(); + const uint16_t port = deviceConfig.get("port", 8080).asInt(); + device = new LedDeviceFadeCandy(host,port); + } else if (type == "tpm2") { const std::string output = deviceConfig["output"].asString(); From 7f5a664864f3c402c97027f6290fef5b0dfbef25 Mon Sep 17 00:00:00 2001 From: redpanther Date: Mon, 4 Jan 2016 12:26:06 +0100 Subject: [PATCH 19/26] set fadecandy default port to original fcserver port number tune debug output of fadecandy device Former-commit-id: 651459e5294ce5721ebe3bb2a6acdc1d096d9cfb --- libsrc/leddevice/LedDeviceFactory.cpp | 2 +- libsrc/leddevice/LedDeviceFadeCandy.cpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index f6f3acf3..b0fd064f 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -247,7 +247,7 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) else if (type == "fadecandy") { const std::string host = deviceConfig.get("output", "127.0.0.1").asString(); - const uint16_t port = deviceConfig.get("port", 8080).asInt(); + const uint16_t port = deviceConfig.get("port", 7890).asInt(); device = new LedDeviceFadeCandy(host,port); } else if (type == "tpm2") diff --git a/libsrc/leddevice/LedDeviceFadeCandy.cpp b/libsrc/leddevice/LedDeviceFadeCandy.cpp index ec6da6a2..a0d2e32d 100755 --- a/libsrc/leddevice/LedDeviceFadeCandy.cpp +++ b/libsrc/leddevice/LedDeviceFadeCandy.cpp @@ -21,8 +21,6 @@ LedDeviceFadeCandy::LedDeviceFadeCandy(const std::string& host, const uint16_t p _opc_data[1] = OPC_SET_PIXELS; _opc_data[2] = 0; _opc_data[3] = 0; - - qDebug("connect to %s %i",_host.c_str(),_port); } LedDeviceFadeCandy::~LedDeviceFadeCandy() @@ -38,7 +36,7 @@ bool LedDeviceFadeCandy::isConnected() bool LedDeviceFadeCandy::tryConnect() { if ( _client.state() == QAbstractSocket::UnconnectedState ) { - qDebug("connecting"); + qDebug("connecting to %s %i",_host.c_str(),_port); QHostAddress addr(_host.c_str()); _client.connectToHost(addr, _port); if (_client.waitForConnected(1000)) From 9182dd5af706cb748b53061e04189b32f9613067 Mon Sep 17 00:00:00 2001 From: redpanther Date: Mon, 4 Jan 2016 14:29:47 +0100 Subject: [PATCH 20/26] fadecandy led device: implement switchOff methode tidy up code and add doxy comments Former-commit-id: a162e2aae756f8b74b8e65f08740c00f3c820e50 --- libsrc/leddevice/LedDeviceFadeCandy.cpp | 114 +++++++++++++----------- libsrc/leddevice/LedDeviceFadeCandy.h | 59 +++++++----- 2 files changed, 97 insertions(+), 76 deletions(-) diff --git a/libsrc/leddevice/LedDeviceFadeCandy.cpp b/libsrc/leddevice/LedDeviceFadeCandy.cpp index a0d2e32d..e8c178d1 100755 --- a/libsrc/leddevice/LedDeviceFadeCandy.cpp +++ b/libsrc/leddevice/LedDeviceFadeCandy.cpp @@ -1,87 +1,93 @@ - -// Local-Hyperion includes #include "LedDeviceFadeCandy.h" -#include -#include -#include -static const unsigned MAX_NUM_LEDS = 512; +static const unsigned MAX_NUM_LEDS = 512; +static const unsigned OPC_BROADCAST = 0; // OPC broadcast channel +static const unsigned OPC_SET_PIXELS = 0; // OPC command codes +static const unsigned OPC_HEADER_SIZE = 4; // OPC header size -/* OPC broadcast channel */ -static const unsigned OPC_BROADCAST = 0; -/* OPC command codes */ -static const unsigned OPC_SET_PIXELS = 0; - -LedDeviceFadeCandy::LedDeviceFadeCandy(const std::string& host, const uint16_t port) - : _host(host), _port(port) +LedDeviceFadeCandy::LedDeviceFadeCandy(const std::string& host, const uint16_t port) : + _host(host), _port(port) { - _opc_data.resize(4); - _opc_data[0] = OPC_BROADCAST; - _opc_data[1] = OPC_SET_PIXELS; - _opc_data[2] = 0; - _opc_data[3] = 0; + _opc_data.resize( OPC_HEADER_SIZE ); + _opc_data[0] = OPC_BROADCAST; + _opc_data[1] = OPC_SET_PIXELS; + _opc_data[2] = 0; + _opc_data[3] = 0; } + LedDeviceFadeCandy::~LedDeviceFadeCandy() { - _client.close(); + _client.close(); } + bool LedDeviceFadeCandy::isConnected() { - return _client.state() == QAbstractSocket::ConnectedState; + return _client.state() == QAbstractSocket::ConnectedState; } + bool LedDeviceFadeCandy::tryConnect() { - if ( _client.state() == QAbstractSocket::UnconnectedState ) { - qDebug("connecting to %s %i",_host.c_str(),_port); - QHostAddress addr(_host.c_str()); - _client.connectToHost(addr, _port); - if (_client.waitForConnected(1000)) - qDebug("connected"); - } + if ( _client.state() == QAbstractSocket::UnconnectedState ) { + qDebug("connecting to %s %i",_host.c_str(),_port); - return isConnected(); + _client.connectToHost( _host.c_str(), _port); + if ( _client.waitForConnected(1000) ) + qDebug("connected"); + } + + return isConnected(); } -int LedDeviceFadeCandy::write(const std::vector & ledValues) +int LedDeviceFadeCandy::write( const std::vector & ledValues ) { - ssize_t nrLedValues = ledValues.size(); - ssize_t led_data_size = nrLedValues*3; // 3 color bytes - ssize_t opc_data_size = led_data_size +4; // + 4 byte header + ssize_t nrLedValues = ledValues.size(); + ssize_t led_data_size = nrLedValues * 3; // 3 color bytes + ssize_t opc_data_size = led_data_size + OPC_HEADER_SIZE; - if (nrLedValues > MAX_NUM_LEDS) - { - std::cerr << "Invalid attempt to write led values. Not more than " << MAX_NUM_LEDS << " leds are allowed." << std::endl; - return -1; - } + if (nrLedValues > MAX_NUM_LEDS) + { + std::cerr << "Invalid attempt to write led values. Not more than " << MAX_NUM_LEDS << " leds are allowed." << std::endl; + return -1; + } - if ( opc_data_size != _opc_data.size()) - _opc_data.resize(opc_data_size); + if ( opc_data_size != _opc_data.size() ) + _opc_data.resize( opc_data_size ); - _opc_data[2] = led_data_size >> 8; - _opc_data[3] = led_data_size & 0xff; + _opc_data[2] = led_data_size >> 8; + _opc_data[3] = led_data_size & 0xff; - if ( isConnected() || tryConnect() ) { - u_int16_t idx = 4; - for (const ColorRgb& color : ledValues) - { - _opc_data[idx] = unsigned(color.red); - _opc_data[idx+1] = unsigned(color.green); - _opc_data[idx+2] = unsigned(color.blue); - idx += 3; - } - _client.write(_opc_data, opc_data_size); - } + uint idx = OPC_HEADER_SIZE; + for (const ColorRgb& color : ledValues) + { + _opc_data[idx ] = unsigned( color.red ); + _opc_data[idx+1] = unsigned( color.green ); + _opc_data[idx+2] = unsigned( color.blue ); + idx += 3; + } - return 0; + return ( transferData()<0 ? -1 : 0 ); +} + + +int LedDeviceFadeCandy::transferData() +{ + if ( isConnected() || tryConnect() ) + return _client.write( _opc_data, _opc_data.size() ); + + return -2; } int LedDeviceFadeCandy::switchOff() { - return 0; + for ( int idx=OPC_HEADER_SIZE; idx < _opc_data.size(); idx++ ) + _opc_data[idx] = 0; + + return ( transferData()<0 ? -1 : 0 ); } + diff --git a/libsrc/leddevice/LedDeviceFadeCandy.h b/libsrc/leddevice/LedDeviceFadeCandy.h index 0973368b..0b894e88 100755 --- a/libsrc/leddevice/LedDeviceFadeCandy.h +++ b/libsrc/leddevice/LedDeviceFadeCandy.h @@ -1,55 +1,70 @@ #pragma once -// STL includes0 +// STL/Qt includes #include #include -#include -#include -#include #include // Leddevice includes #include - /// -/// Implementation of the LedDevice that write the led-colors to an -/// ASCII-textfile('/home/pi/LedDevice.out') +/// Implementation of the LedDevice interface for sending to +/// fadecandy/opc-server via network by using the 'open pixel control' protocol. /// -class LedDeviceFadeCandy : public QObject,public LedDevice +class LedDeviceFadeCandy : public QObject, public LedDevice { - Q_OBJECT + Q_OBJECT + public: /// - /// Constructs the test-device, which opens an output stream to the file + /// Constructs the LedDevice for fadecandy/opc server + /// + /// @param host The ip address/host name of fadecandy/opc server + /// @param port The port to use (fadecandy default is 7890) /// LedDeviceFadeCandy(const std::string& host, const uint16_t port); /// - /// Destructor of this test-device + /// Destructor of the LedDevice; closes the tcp client /// virtual ~LedDeviceFadeCandy(); /// - /// Writes the given led-color values to the output stream + /// Writes the led color values to the led-device /// /// @param ledValues The color-value per led - /// - /// @return Zero on success else negative + /// @return Zero on succes else negative /// virtual int write(const std::vector & ledValues); /// Switch the leds off virtual int switchOff(); - bool tryConnect(); - bool isConnected(); - -//public slots: private: - QTcpSocket _client; - const std::string _host; - const uint16_t _port; - QByteArray _opc_data; + QTcpSocket _client; + const std::string _host; + const uint16_t _port; + QByteArray _opc_data; + + /// try to establish connection to opc server, if not connected yet + /// + /// @return true if connection is established + /// + bool tryConnect(); + + /// return the conenction state + /// + /// @return True if connection established + /// + bool isConnected(); + + + /// transfer current opc_data buffer to opc server + /// + /// @return amount of transfered bytes. -1 error while transfering, -2 error while connecting + /// + int transferData(); + }; From defe217c899a0258eda2ef9672ff3c8f83dc0038 Mon Sep 17 00:00:00 2001 From: frostworx Date: Wed, 6 Jan 2016 17:31:23 +0100 Subject: [PATCH 21/26] added optional QT5 support - LedDevicePhilipsHue needs proper fixes Former-commit-id: 7f0971ccda221933da4be836628532e7cfc7c085 --- CMakeLists.txt | 27 ++++++++++++++++- .../BoblightClientConnection.cpp | 5 +++- libsrc/boblightserver/CMakeLists.txt | 8 +++++ libsrc/effectengine/CMakeLists.txt | 10 ++++++- libsrc/effectengine/EffectEngine.cpp | 8 +++++ libsrc/grabber/amlogic/CMakeLists.txt | 4 +++ libsrc/grabber/dispmanx/CMakeLists.txt | 4 +++ libsrc/grabber/framebuffer/CMakeLists.txt | 4 +++ libsrc/grabber/osx/CMakeLists.txt | 4 +++ libsrc/grabber/v4l2/CMakeLists.txt | 8 +++++ libsrc/grabber/x11/CMakeLists.txt | 4 +++ libsrc/hyperion/CMakeLists.txt | 10 ++++++- libsrc/jsonserver/CMakeLists.txt | 11 +++++-- libsrc/leddevice/CMakeLists.txt | 10 ++++++- libsrc/leddevice/LedDevicePhilipsHue.cpp | 29 +++++++++++++++++++ libsrc/leddevice/LedDevicePhilipsHue.h | 10 ++++++- libsrc/protoserver/CMakeLists.txt | 7 +++++ libsrc/xbmcvideochecker/CMakeLists.txt | 8 +++++ src/hyperion-aml/CMakeLists.txt | 4 +++ src/hyperion-remote/CMakeLists.txt | 10 +++++++ src/hyperion-remote/hyperion-remote.cpp | 5 ++++ src/hyperion-v4l2/CMakeLists.txt | 12 +++++++- src/hyperion-x11/CMakeLists.txt | 12 ++++++++ test/CMakeLists.txt | 5 ++++ 24 files changed, 210 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b89af70..81479cb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,9 @@ message(STATUS "ENABLE_WS2812BPWM = " ${ENABLE_WS2812BPWM}) option(ENABLE_X11 "Enable the X11 grabber" OFF) message(STATUS "ENABLE_X11 = " ${ENABLE_X11}) +option(ENABLE_QT5 "Enable QT5" OFF) +message(STATUS "ENABLE_QT5 = " ${ENABLE_QT5}) + if(ENABLE_V4L2 AND NOT ENABLE_PROTOBUF) message(FATAL_ERROR "V4L2 grabber requires PROTOBUF. Disable V4L2 or enable PROTOBUF") endif(ENABLE_V4L2 AND NOT ENABLE_PROTOBUF) @@ -53,6 +56,10 @@ if(ENABLE_OSX AND ENABLE_DISPMANX) message(FATAL_ERROR "dispmanx grabber and osx grabber cannot be used at the same time") endif(ENABLE_OSX AND ENABLE_DISPMANX) +#if(ENABLE_QT5) +# TODO vs ENABLE_QT4? +#endif(ENABLE_QT5) + # Createt the configuration file # configure a header file to pass some of the CMake settings # to the source code @@ -61,8 +68,14 @@ include_directories("${PROJECT_BINARY_DIR}") # Add project specific cmake modules (find, etc) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +if(ENABLE_QT5) +ADD_DEFINITIONS ( -DENABLE_QT5 ) +#find_package(Qt5Widgets) +else(ENABLE_QT5) # Add specific cmake modules to find qt4 (default version finds first available QT which might not be qt4) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/qt4) +endif(ENABLE_QT5) # Define the global output path of binaries SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) @@ -85,15 +98,27 @@ set(CMAKE_BUILD_TYPE "Debug") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -std=c++11 -Wall") +if(ENABLE_QT5) +#find_package(Qt5Core REQUIRED) +find_package(Qt5 COMPONENTS Core Gui Widgets Network REQUIRED) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") +# set(CMAKE_CXX_FLAGS "-fPIC") +else(ENABLE_QT5) # Configure the use of QT4 find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED QUIET) +endif(ENABLE_QT5) #add libusb and pthreads find_package(libusb-1.0 REQUIRED) find_package(Threads REQUIRED) - +if(ENABLE_QT5) +#include(${QT_USE_FILE}) +add_definitions(${QT_DEFINITIONS}) +else(ENABLE_QT5) include(${QT_USE_FILE}) add_definitions(${QT_DEFINITIONS}) +endif(ENABLE_QT5) + # TODO[TvdZ]: This linking directory should only be added if we are cross compiling if(NOT APPLE) link_directories(${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf) diff --git a/libsrc/boblightserver/BoblightClientConnection.cpp b/libsrc/boblightserver/BoblightClientConnection.cpp index f78d6784..105b8d1a 100644 --- a/libsrc/boblightserver/BoblightClientConnection.cpp +++ b/libsrc/boblightserver/BoblightClientConnection.cpp @@ -59,8 +59,11 @@ void BoblightClientConnection::readData() while(bytes > 0) { // create message string (strip the newline) +#ifdef ENABLE_QT5 + QString message = QString::fromLatin1(_receiveBuffer.data(), bytes-1); +#else QString message = QString::fromAscii(_receiveBuffer.data(), bytes-1); - +#endif // remove message data from buffer _receiveBuffer = _receiveBuffer.mid(bytes); diff --git a/libsrc/boblightserver/CMakeLists.txt b/libsrc/boblightserver/CMakeLists.txt index 1bb30cdb..33be4d17 100644 --- a/libsrc/boblightserver/CMakeLists.txt +++ b/libsrc/boblightserver/CMakeLists.txt @@ -17,7 +17,11 @@ set(BoblightServer_SOURCES ${CURRENT_SOURCE_DIR}/BoblightClientConnection.cpp ) +if(ENABLE_QT5) +qt5_wrap_cpp(BoblightServer_HEADERS_MOC ${BoblightServer_QT_HEADERS}) +else(ENABLE_QT5) qt4_wrap_cpp(BoblightServer_HEADERS_MOC ${BoblightServer_QT_HEADERS}) +endif(ENABLE_QT5) add_library(boblightserver ${BoblightServer_HEADERS} @@ -26,6 +30,10 @@ add_library(boblightserver ${BoblightServer_HEADERS_MOC} ) +if(ENABLE_QT5) +qt5_use_modules(boblightserver Widgets) +endif(ENABLE_QT5) + target_link_libraries(boblightserver hyperion hyperion-utils diff --git a/libsrc/effectengine/CMakeLists.txt b/libsrc/effectengine/CMakeLists.txt index c7c77236..619b691d 100644 --- a/libsrc/effectengine/CMakeLists.txt +++ b/libsrc/effectengine/CMakeLists.txt @@ -27,9 +27,13 @@ SET(EffectEngineSOURCES set(EffectEngine_RESOURCES ${CURRENT_SOURCE_DIR}/EffectEngine.qrc) +if(ENABLE_QT5) +QT5_WRAP_CPP(EffectEngineHEADERS_MOC ${EffectEngineQT_HEADERS}) +qt5_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} OPTIONS "-no-compress") +else(ENABLE_QT5) QT4_WRAP_CPP(EffectEngineHEADERS_MOC ${EffectEngineQT_HEADERS}) - qt4_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} OPTIONS "-no-compress") +endif(ENABLE_QT5) add_library(effectengine ${EffectEngineHEADERS} @@ -39,6 +43,10 @@ add_library(effectengine ${EffectEngineSOURCES} ) +if(ENABLE_QT5) +qt5_use_modules(effectengine Widgets) +endif(ENABLE_QT5) + target_link_libraries(effectengine hyperion jsoncpp diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index f7057e21..b9379fad 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -75,7 +75,11 @@ const std::list &EffectEngine::getEffects() const bool EffectEngine::loadEffectDefinition(const std::string &path, const std::string &effectConfigFile, EffectDefinition & effectDefinition) { +#ifdef ENABLE_QT5 + std::string fileName = path + QDir::separator().toLatin1() + effectConfigFile; +#else std::string fileName = path + QDir::separator().toAscii() + effectConfigFile; +#endif std::ifstream file(fileName.c_str()); if (!file.is_open()) @@ -110,7 +114,11 @@ bool EffectEngine::loadEffectDefinition(const std::string &path, const std::stri // setup the definition effectDefinition.name = config["name"].asString(); +#ifdef ENABLE_QT5 + effectDefinition.script = path + QDir::separator().toLatin1() + config["script"].asString(); +#else effectDefinition.script = path + QDir::separator().toAscii() + config["script"].asString(); +#endif effectDefinition.args = config["args"]; // return succes diff --git a/libsrc/grabber/amlogic/CMakeLists.txt b/libsrc/grabber/amlogic/CMakeLists.txt index 447a873d..be6cb97d 100644 --- a/libsrc/grabber/amlogic/CMakeLists.txt +++ b/libsrc/grabber/amlogic/CMakeLists.txt @@ -15,7 +15,11 @@ SET(AmlogicSOURCES ${CURRENT_SOURCE_DIR}/AmlogicGrabber.cpp ) +if(ENABLE_QT5) +QT5_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS}) +endif(ENABLE_QT5) add_library(amlogic-grabber ${AmlogicHEADERS} diff --git a/libsrc/grabber/dispmanx/CMakeLists.txt b/libsrc/grabber/dispmanx/CMakeLists.txt index 20714dba..d4d64b72 100644 --- a/libsrc/grabber/dispmanx/CMakeLists.txt +++ b/libsrc/grabber/dispmanx/CMakeLists.txt @@ -21,7 +21,11 @@ SET(DispmanxGrabberSOURCES ${CURRENT_SOURCE_DIR}/DispmanxFrameGrabber.cpp ) +if(ENABLE_QT5) +QT5_WRAP_CPP(DispmanxGrabberHEADERS_MOC ${DispmanxGrabberQT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(DispmanxGrabberHEADERS_MOC ${DispmanxGrabberQT_HEADERS}) +endif(ENABLE_QT5) add_library(dispmanx-grabber ${DispmanxGrabberHEADERS} diff --git a/libsrc/grabber/framebuffer/CMakeLists.txt b/libsrc/grabber/framebuffer/CMakeLists.txt index 9a6a12be..dc585f42 100644 --- a/libsrc/grabber/framebuffer/CMakeLists.txt +++ b/libsrc/grabber/framebuffer/CMakeLists.txt @@ -21,7 +21,11 @@ SET(FramebufferGrabberSOURCES ${CURRENT_SOURCE_DIR}/FramebufferFrameGrabber.cpp ) +if(ENABLE_QT5) +QT5_WRAP_CPP(FramebufferGrabberHEADERS_MOC ${FramebufferGrabberQT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(FramebufferGrabberHEADERS_MOC ${FramebufferGrabberQT_HEADERS}) +endif(ENABLE_QT5) add_library(framebuffer-grabber ${FramebufferGrabberHEADERS} diff --git a/libsrc/grabber/osx/CMakeLists.txt b/libsrc/grabber/osx/CMakeLists.txt index 05c67b3b..03868eeb 100644 --- a/libsrc/grabber/osx/CMakeLists.txt +++ b/libsrc/grabber/osx/CMakeLists.txt @@ -16,7 +16,11 @@ SET(OsxGrabberSOURCES ${CURRENT_SOURCE_DIR}/OsxFrameGrabber.cpp ) +if(ENABLE_QT5) +QT5_WRAP_CPP(OsxGrabberHEADERS_MOC ${OsxGrabberQT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(OsxGrabberHEADERS_MOC ${OsxGrabberQT_HEADERS}) +endif(ENABLE_QT5) add_library(osx-grabber ${OsxGrabberHEADERS} diff --git a/libsrc/grabber/v4l2/CMakeLists.txt b/libsrc/grabber/v4l2/CMakeLists.txt index 5c7844e0..71de7806 100644 --- a/libsrc/grabber/v4l2/CMakeLists.txt +++ b/libsrc/grabber/v4l2/CMakeLists.txt @@ -16,7 +16,11 @@ SET(V4L2_SOURCES ${CURRENT_SOURCE_DIR}/V4L2Wrapper.cpp ) +if(ENABLE_QT5) +QT5_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS}) +endif(ENABLE_QT5) add_library(v4l2-grabber ${V4L2_HEADERS} @@ -25,6 +29,10 @@ add_library(v4l2-grabber ${V4L2_HEADERS_MOC} ) +if(ENABLE_QT5) +qt5_use_modules(v4l2-grabber Widgets) +endif(ENABLE_QT5) + target_link_libraries(v4l2-grabber hyperion ${QT_LIBRARIES} diff --git a/libsrc/grabber/x11/CMakeLists.txt b/libsrc/grabber/x11/CMakeLists.txt index 869fb4bf..4d8ead6d 100644 --- a/libsrc/grabber/x11/CMakeLists.txt +++ b/libsrc/grabber/x11/CMakeLists.txt @@ -22,7 +22,11 @@ SET(X11_SOURCES ${CURRENT_SOURCE_DIR}/X11Grabber.cpp ) +if(ENABLE_QT5) +QT5_WRAP_CPP(X11_HEADERS_MOC ${X11_QT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(X11_HEADERS_MOC ${X11_QT_HEADERS}) +endif(ENABLE_QT5) add_library(x11-grabber ${X11_HEADERS} diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index 8f6a227d..1434f105 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -36,9 +36,13 @@ set(Hyperion_RESOURCES ${CURRENT_SOURCE_DIR}/resource.qrc ) +if(ENABLE_QT5) +QT5_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS}) +QT5_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress") +else(ENABLE_QT5) QT4_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS}) - QT4_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress") +endif(ENABLE_QT5) add_library(hyperion ${Hyperion_HEADERS} @@ -48,6 +52,10 @@ add_library(hyperion ${Hyperion_RESOURCES_RCC} ) +if(ENABLE_QT5) +qt5_use_modules(hyperion Widgets) +endif(ENABLE_QT5) + target_link_libraries(hyperion blackborder hyperion-utils diff --git a/libsrc/jsonserver/CMakeLists.txt b/libsrc/jsonserver/CMakeLists.txt index 208c1ed9..d03ed1ea 100644 --- a/libsrc/jsonserver/CMakeLists.txt +++ b/libsrc/jsonserver/CMakeLists.txt @@ -20,10 +20,13 @@ set(JsonServer_SOURCES set(JsonServer_RESOURCES ${CURRENT_SOURCE_DIR}/JsonSchemas.qrc ) - +if(ENABLE_QT5) +qt5_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS}) +qt5_add_resources(JsonServer_RESOURCES_RCC ${JsonServer_RESOURCES} OPTIONS "-no-compress") +else(ENABLE_QT5) qt4_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS}) - qt4_add_resources(JsonServer_RESOURCES_RCC ${JsonServer_RESOURCES} OPTIONS "-no-compress") +endif(ENABLE_QT5) add_library(jsonserver ${JsonServer_HEADERS} @@ -34,6 +37,10 @@ add_library(jsonserver ${JsonServer_RESOURCES_RCC} ) +if(ENABLE_QT5) +qt5_use_modules(jsonserver Widgets Network) +endif(ENABLE_QT5) + target_link_libraries(jsonserver hyperion hyperion-utils diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index d6d4682c..ddb8a0de 100755 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -102,8 +102,12 @@ if(ENABLE_TINKERFORGE) ) endif(ENABLE_TINKERFORGE) - +if(ENABLE_QT5) +QT5_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS}) +endif(ENABLE_QT5) + add_library(leddevice ${Leddevice_HEADERS} @@ -112,6 +116,10 @@ add_library(leddevice ${Leddevice_SOURCES} ) +if(ENABLE_QT5) +qt5_use_modules(leddevice Widgets Network) +endif(ENABLE_QT5) + target_link_libraries(leddevice hyperion-utils serialport diff --git a/libsrc/leddevice/LedDevicePhilipsHue.cpp b/libsrc/leddevice/LedDevicePhilipsHue.cpp index 056e9ead..449f8307 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.cpp +++ b/libsrc/leddevice/LedDevicePhilipsHue.cpp @@ -7,7 +7,12 @@ // qt includes #include #include +#ifdef ENABLE_QT5 + +#else #include +#endif + #include #include @@ -144,14 +149,22 @@ LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::s int transitiontime, std::vector lightIds) : host(output.c_str()), username(username.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime( transitiontime), lightIds(lightIds) { +#ifdef ENABLE_QT5 + +#else http = new QHttp(host); timer.setInterval(3000); timer.setSingleShot(true); connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates())); +#endif } LedDevicePhilipsHue::~LedDevicePhilipsHue() { +#ifdef ENABLE_QT5 + +#else delete http; +#endif } int LedDevicePhilipsHue::write(const std::vector & ledValues) { @@ -201,21 +214,32 @@ int LedDevicePhilipsHue::write(const std::vector & ledValues) { // Next light id. idx++; } +#ifdef ENABLE_QT5 + +#else timer.start(); +#endif return 0; } int LedDevicePhilipsHue::switchOff() { +#ifdef ENABLE_QT5 + +#else timer.stop(); // If light states have been saved before, ... if (areStatesSaved()) { // ... restore them. restoreStates(); } +#endif return 0; } void LedDevicePhilipsHue::put(QString route, QString content) { +#ifdef ENABLE_QT5 + +#else QString url = QString("/api/%1/%2").arg(username).arg(route); QHttpRequestHeader header("PUT", url); header.setValue("Host", host); @@ -229,9 +253,13 @@ void LedDevicePhilipsHue::put(QString route, QString content) { http->request(header, content.toAscii()); // Go into the loop until the request is finished. loop.exec(); +#endif } QByteArray LedDevicePhilipsHue::get(QString route) { +#ifdef ENABLE_QT5 + return 0; +#else QString url = QString("/api/%1/%2").arg(username).arg(route); // Event loop to block until request finished. QEventLoop loop; @@ -243,6 +271,7 @@ QByteArray LedDevicePhilipsHue::get(QString route) { loop.exec(); // Read all data of the response. return http->readAll(); +#endif } QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId) { diff --git a/libsrc/leddevice/LedDevicePhilipsHue.h b/libsrc/leddevice/LedDevicePhilipsHue.h index 59c0383d..65c5a3b6 100755 --- a/libsrc/leddevice/LedDevicePhilipsHue.h +++ b/libsrc/leddevice/LedDevicePhilipsHue.h @@ -4,11 +4,14 @@ #include // Qt includes +#ifdef ENABLE_QT5 +#include +#else #include #include #include #include - +#endif // Leddevice includes #include @@ -165,9 +168,14 @@ private: /// User name for the API ("newdeveloper") QString username; /// Qhttp object for sending requests. +#ifdef ENABLE_QT5 +// TODO QNetworkAcessManager stuff +#else QHttp* http; + /// Use timer to reset lights when we got into "GRABBINGMODE_OFF". QTimer timer; +#endif /// bool switchOffOnBlack; /// Transition time in multiples of 100 ms. diff --git a/libsrc/protoserver/CMakeLists.txt b/libsrc/protoserver/CMakeLists.txt index 6a9b6d1e..769cc807 100644 --- a/libsrc/protoserver/CMakeLists.txt +++ b/libsrc/protoserver/CMakeLists.txt @@ -34,7 +34,11 @@ protobuf_generate_cpp(ProtoServer_PROTO_SRCS ProtoServer_PROTO_HDRS ${ProtoServer_PROTOS} ) +if(ENABLE_QT5) +qt5_wrap_cpp(ProtoServer_HEADERS_MOC ${ProtoServer_QT_HEADERS}) +else(ENABLE_QT5) qt4_wrap_cpp(ProtoServer_HEADERS_MOC ${ProtoServer_QT_HEADERS}) +endif(ENABLE_QT5) add_library(protoserver ${ProtoServer_HEADERS} @@ -45,6 +49,9 @@ add_library(protoserver ${ProtoServer_PROTO_SRCS} ${ProtoServer_PROTO_HDRS} ) +if(ENABLE_QT5) +qt5_use_modules(protoserver Widgets) +endif(ENABLE_QT5) target_link_libraries(protoserver hyperion diff --git a/libsrc/xbmcvideochecker/CMakeLists.txt b/libsrc/xbmcvideochecker/CMakeLists.txt index 77ee2f34..f6e71b00 100644 --- a/libsrc/xbmcvideochecker/CMakeLists.txt +++ b/libsrc/xbmcvideochecker/CMakeLists.txt @@ -15,7 +15,11 @@ SET(XBMCVideoChecker_SOURCES ${CURRENT_SOURCE_DIR}/XBMCVideoChecker.cpp ) +if(ENABLE_QT5) +QT5_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS}) +endif(ENABLE_QT5) add_library(xbmcvideochecker ${XBMCVideoChecker_HEADERS} @@ -24,6 +28,10 @@ add_library(xbmcvideochecker ${XBMCVideoChecker_SOURCES} ) +if(ENABLE_QT5) +qt5_use_modules(xbmcvideochecker Widgets) +endif(ENABLE_QT5) + target_link_libraries(xbmcvideochecker hyperion ${QT_LIBRARIES}) diff --git a/src/hyperion-aml/CMakeLists.txt b/src/hyperion-aml/CMakeLists.txt index d6f88a90..5d45222a 100644 --- a/src/hyperion-aml/CMakeLists.txt +++ b/src/hyperion-aml/CMakeLists.txt @@ -23,7 +23,11 @@ set(Hyperion_AML_SOURCES hyperion-aml.cpp ) +if(ENABLE_QT5) +QT5_WRAP_CPP(Hyperion_AML_HEADERS_MOC ${Hyperion_AML_QT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(Hyperion_AML_HEADERS_MOC ${Hyperion_AML_QT_HEADERS}) +endif(ENABLE_QT5) add_executable(hyperion-amlogic ${Hyperion_AML_HEADERS} diff --git a/src/hyperion-remote/CMakeLists.txt b/src/hyperion-remote/CMakeLists.txt index c934be21..b8c73a59 100644 --- a/src/hyperion-remote/CMakeLists.txt +++ b/src/hyperion-remote/CMakeLists.txt @@ -3,7 +3,13 @@ cmake_minimum_required(VERSION 2.8) project(hyperion-remote) # find Qt4 +if(ENABLE_QT5) +find_package(Qt5 COMPONENTS Core Gui Widgets Network REQUIRED) +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") +# set(CMAKE_CXX_FLAGS "-fPIC") +else(ENABLE_QT5) find_package(Qt4 REQUIRED QtCore QtGui QtNetwork) +endif(ENABLE_QT5) # The following I do not undrstand completely... # libQtCore.so uses some hardcoded library path inside which are incorrect after copying the file RPi file system @@ -25,6 +31,10 @@ add_executable(hyperion-remote ${hyperion-remote_HEADERS} ${hyperion-remote_SOURCES}) +if(ENABLE_QT5) +qt5_use_modules(hyperion-remote Widgets Network) +endif(ENABLE_QT5) + target_link_libraries(hyperion-remote jsoncpp getoptPlusPlus diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index da9d4b00..3636721f 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -43,8 +43,13 @@ int main(int argc, char * argv[]) // create the option parser and initialize all parameters OptionsParser optionParser("Simple application to send a command to hyperion using the Json interface"); ParameterSet & parameters = optionParser.getParameters(); +#ifdef ENABLE_QT5 + StringParameter & argAddress = parameters.add ('a', "address" , QString("Set the address of the hyperion server [default: %1]").arg(defaultServerAddress).toLatin1().constData()); + IntParameter & argPriority = parameters.add ('p', "priority" , QString("Use to the provided priority channel (the lower the number, the higher the priority) [default: %1]").arg(defaultPriority).toLatin1().constData()); +#else StringParameter & argAddress = parameters.add ('a', "address" , QString("Set the address of the hyperion server [default: %1]").arg(defaultServerAddress).toAscii().constData()); IntParameter & argPriority = parameters.add ('p', "priority" , QString("Use to the provided priority channel (the lower the number, the higher the priority) [default: %1]").arg(defaultPriority).toAscii().constData()); +#endif IntParameter & argDuration = parameters.add ('d', "duration" , "Specify how long the leds should be switched on in millseconds [default: infinity]"); ColorParameter & argColor = parameters.add ('c', "color" , "Set all leds to a constant color (either RRGGBB hex value or a color name. The color may be repeated multiple time like: RRGGBBRRGGBB)"); ImageParameter & argImage = parameters.add ('i', "image" , "Set the leds to the colors according to the given image file"); diff --git a/src/hyperion-v4l2/CMakeLists.txt b/src/hyperion-v4l2/CMakeLists.txt index 6607c04f..ef051e2d 100644 --- a/src/hyperion-v4l2/CMakeLists.txt +++ b/src/hyperion-v4l2/CMakeLists.txt @@ -3,7 +3,14 @@ cmake_minimum_required(VERSION 2.8) project(hyperion-v4l2) # find Qt4 +if(ENABLE_QT5) +find_package(Qt5Widgets REQUIRED) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") +# set(CMAKE_CXX_FLAGS "-fPIC") +else(ENABLE_QT5) find_package(Qt4 REQUIRED QtCore QtGui QtNetwork) +endif(ENABLE_QT5) + include_directories( ${CMAKE_CURRENT_BINARY_DIR}/../../libsrc/protoserver @@ -24,8 +31,11 @@ set(Hyperion_V4L2_SOURCES hyperion-v4l2.cpp ScreenshotHandler.cpp ) - +if(ENABLE_QT5) +QT5_WRAP_CPP(Hyperion_V4L2_MOC_SOURCES ${Hyperion_V4L2_QT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(Hyperion_V4L2_MOC_SOURCES ${Hyperion_V4L2_QT_HEADERS}) +endif(ENABLE_QT5) add_executable(hyperion-v4l2 ${Hyperion_V4L2_HEADERS} diff --git a/src/hyperion-x11/CMakeLists.txt b/src/hyperion-x11/CMakeLists.txt index 89912f66..626781f9 100644 --- a/src/hyperion-x11/CMakeLists.txt +++ b/src/hyperion-x11/CMakeLists.txt @@ -4,8 +4,12 @@ cmake_minimum_required(VERSION 2.8) # Set the project name project(hyperion-x11) +if(ENABLE_QT5) +find_package(Qt5Widgets REQUIRED) +else(ENABLE_QT5) # find Qt4 find_package(Qt4 REQUIRED QtCore QtGui QtNetwork) +endif(ENABLE_QT5) # Find X11 find_package(X11 REQUIRED) @@ -28,7 +32,11 @@ set(Hyperion_X11_SOURCES X11Wrapper.cpp ) +if(ENABLE_QT5) +QT5_WRAP_CPP(Hyperion_X11_HEADERS_MOC ${Hyperion_X11_QT_HEADERS}) +else(ENABLE_QT5) QT4_WRAP_CPP(Hyperion_X11_HEADERS_MOC ${Hyperion_X11_QT_HEADERS}) +endif(ENABLE_QT5) add_executable(hyperion-x11 ${Hyperion_X11_HEADERS} @@ -46,7 +54,11 @@ target_link_libraries(hyperion-x11 pthread ) +if(ENABLE_QT5) +qt5_use_modules(hyperion-x11 Widgets Core Gui Network) +else(ENABLE_QT5) qt4_use_modules(hyperion-x11 Core Gui Network) +endif(ENABLE_QT5) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bf40cebb..482d066a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -53,6 +53,11 @@ add_executable(test_qtscreenshot TestQtScreenshot.cpp) target_link_libraries(test_qtscreenshot ${QT_LIBRARIES}) +if(ENABLE_QT5) +qt5_use_modules(test_qregexp Widgets) +qt5_use_modules(test_qtscreenshot Widgets) +endif(ENABLE_QT5) + if(ENABLE_X11) # Find X11 find_package(X11 REQUIRED) From 5a69b4e6a2d82074e8d78ad3a0fcd48ce49ee2d8 Mon Sep 17 00:00:00 2001 From: frostworx Date: Wed, 6 Jan 2016 18:13:44 +0100 Subject: [PATCH 22/26] added QT5 X11 check Former-commit-id: ff7ff4f353381409efbdfcf346b6a4817f7dc7e1 --- test/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 482d066a..76cbb5dc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -64,4 +64,8 @@ if(ENABLE_X11) add_executable(test_x11performance TestX11Performance.cpp) target_link_libraries(test_x11performance ${X11_LIBRARIES} ${QT_LIBRARIES}) +if(ENABLE_QT5) +qt5_use_modules(test_x11performance Widgets) +endif(ENABLE_QT5) + endif(ENABLE_X11) From 544ae68429cf8e7eb026d912a508e6905d76e404 Mon Sep 17 00:00:00 2001 From: wisc Date: Sun, 10 Jan 2016 14:41:47 +0100 Subject: [PATCH 23/26] test old v1+ vs new v2 Former-commit-id: 5217ac135cd0c7a6907be0097df72506ca7f2d71 --- include/blackborder/BlackBorderProcessor.h | 8 ++ libsrc/blackborder/BlackBorderProcessor.cpp | 107 ++++++++++++++++++-- 2 files changed, 105 insertions(+), 10 deletions(-) diff --git a/include/blackborder/BlackBorderProcessor.h b/include/blackborder/BlackBorderProcessor.h index 4d0c4fca..19f90d3d 100644 --- a/include/blackborder/BlackBorderProcessor.h +++ b/include/blackborder/BlackBorderProcessor.h @@ -73,6 +73,8 @@ namespace hyperion /// @return True if the current border changed else false /// bool updateBorder(const BlackBorder & newDetectedBorder); + bool updateBorder1(const BlackBorder & newDetectedBorder); + bool updateBorder2(const BlackBorder & newDetectedBorder); /// The number of unknown-borders detected before it becomes the current border const unsigned _unknownSwitchCnt; @@ -87,12 +89,18 @@ namespace hyperion BlackBorderDetector _detector; /// The current detected border + BlackBorder _currentBorder1; BlackBorder _currentBorder; /// The border detected in the previous frame + BlackBorder _previousDetectedBorder1; BlackBorder _previousDetectedBorder; /// The number of frame the previous detected border matched the incomming border + unsigned _consistentCnt1; unsigned _consistentCnt; + /// The number of frame the previous detected border NOT matched the incomming border + unsigned _inconsistentCnt1; + unsigned _inconsistentCnt; }; } // end namespace hyperion diff --git a/libsrc/blackborder/BlackBorderProcessor.cpp b/libsrc/blackborder/BlackBorderProcessor.cpp index b9c21eea..b3f1824f 100644 --- a/libsrc/blackborder/BlackBorderProcessor.cpp +++ b/libsrc/blackborder/BlackBorderProcessor.cpp @@ -1,4 +1,4 @@ -//#include +#include // Blackborder includes #include @@ -12,9 +12,14 @@ BlackBorderProcessor::BlackBorderProcessor(const unsigned unknownFrameCnt, _borderSwitchCnt(borderFrameCnt), _blurRemoveCnt(blurRemoveCnt), _detector(blackborderThreshold), + _currentBorder1({true, -1, -1}), _currentBorder({true, -1, -1}), + _previousDetectedBorder1({true, -1, -1}), _previousDetectedBorder({true, -1, -1}), - _consistentCnt(0) + _consistentCnt1(0), + _consistentCnt(0), + _inconsistentCnt1(0), + _inconsistentCnt(0) { // empty } @@ -24,23 +29,102 @@ BlackBorder BlackBorderProcessor::getCurrentBorder() const return _currentBorder; } + bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) +{ +bool result1 = updateBorder1(newDetectedBorder); +if (result1) +{ + std::cout << "border change v1 " << _currentBorder1.horizontalSize << ":" << _currentBorder1.verticalSize << std::endl; +} + +bool result2 = updateBorder2(newDetectedBorder); +if (result2) +{ + std::cout << "border change v2 " << _currentBorder.horizontalSize << ":" << _currentBorder.verticalSize << std::endl; +} + +return result2; +} + + +bool BlackBorderProcessor::updateBorder1(const BlackBorder & newDetectedBorder) +{ + // set the consistency counter + if (newDetectedBorder == _previousDetectedBorder1) + { + ++_consistentCnt1; + } + else + { + _previousDetectedBorder1 = newDetectedBorder; + _consistentCnt1 = 0; + } + +// std::cout << "cur: " << _currentBorder1.verticalSize << " " << _currentBorder1.horizontalSize << " new: " << newDetectedBorder.verticalSize << " " << newDetectedBorder.horizontalSize << " c:i " << _consistentCnt1 << ":" << _inconsistentCnt1 << std::endl; + + // check if there is a change + if (_currentBorder1 == newDetectedBorder) + { + // No change required + return false; + } + + bool borderChanged = false; + if (newDetectedBorder.unknown) + { + // apply the unknown border if we consistently can't determine a border + if (_consistentCnt1 == _unknownSwitchCnt) + { + _currentBorder1 = newDetectedBorder; + borderChanged = true; + } + } + else + { + // apply the detected border if it has been detected consistently + if (_currentBorder1.unknown || _consistentCnt1 == _borderSwitchCnt) + { + _currentBorder1 = newDetectedBorder; + borderChanged = true; + } + else + { + bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 ); + // apply smaller borders immediately + if ((newDetectedBorder.verticalSize < _currentBorder1.verticalSize) && (stable)) + { + _currentBorder1.verticalSize = newDetectedBorder.verticalSize; + borderChanged = true; + } + + if ((newDetectedBorder.horizontalSize < _currentBorder1.horizontalSize) && (stable)) + { + _currentBorder1.horizontalSize = newDetectedBorder.horizontalSize; + borderChanged = true; + } + } + } + + return borderChanged; +} + +bool BlackBorderProcessor::updateBorder2(const BlackBorder & newDetectedBorder) { // set the consistency counter if (newDetectedBorder == _previousDetectedBorder) { - if (_consistentCnt < 100000) - { - ++_consistentCnt; - } + ++_consistentCnt; + _inconsistentCnt = 0; } else { _previousDetectedBorder = newDetectedBorder; _consistentCnt = 0; + ++_inconsistentCnt; } -// std::cout << "new: " << newDetectedBorder.verticalSize << " " << newDetectedBorder.horizontalSize << " cur: " << _currentBorder.verticalSize << " " << _currentBorder.horizontalSize << " cc " << _consistentCnt << std::endl; +// std::cout << "cur: " << _currentBorder.verticalSize << " " << _currentBorder.horizontalSize << " new: " << newDetectedBorder.verticalSize << " " << newDetectedBorder.horizontalSize << " c:i " << _consistentCnt << ":" << _inconsistentCnt << std::endl; // check if there is a change if (_currentBorder == newDetectedBorder) @@ -71,16 +155,19 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) } else { + bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 ); + //more then A consistent seems like a new size not only a short flicker + //more then B inconsistent seems like the image is changing a lot and we need to set smaller border // apply smaller borders immediately // if (newDetectedBorder.verticalSize < _currentBorder.verticalSize) - if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (_consistentCnt >= 1) )// almost immediatly - avoid switching for "abnormal" frames + if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (stable) )// almost immediatly - avoid switching for "abnormal" frames { _currentBorder.verticalSize = newDetectedBorder.verticalSize; borderChanged = true; } // if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) - if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (_consistentCnt >= 1) ) + if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (stable) ) { _currentBorder.horizontalSize = newDetectedBorder.horizontalSize; borderChanged = true; @@ -89,4 +176,4 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) } return borderChanged; -} +} \ No newline at end of file From ac86a779b076ff7f7b37a055b1ad2e7650f76ec2 Mon Sep 17 00:00:00 2001 From: wisc Date: Sun, 10 Jan 2016 14:55:23 +0100 Subject: [PATCH 24/26] cleanup Former-commit-id: 39cb3f76379990085407791ec391732c986790e6 --- include/blackborder/BlackBorderProcessor.h | 4 - libsrc/blackborder/BlackBorderProcessor.cpp | 88 +-------------------- 2 files changed, 1 insertion(+), 91 deletions(-) diff --git a/include/blackborder/BlackBorderProcessor.h b/include/blackborder/BlackBorderProcessor.h index 19f90d3d..ad8c7b83 100644 --- a/include/blackborder/BlackBorderProcessor.h +++ b/include/blackborder/BlackBorderProcessor.h @@ -89,18 +89,14 @@ namespace hyperion BlackBorderDetector _detector; /// The current detected border - BlackBorder _currentBorder1; BlackBorder _currentBorder; /// The border detected in the previous frame - BlackBorder _previousDetectedBorder1; BlackBorder _previousDetectedBorder; /// The number of frame the previous detected border matched the incomming border - unsigned _consistentCnt1; unsigned _consistentCnt; /// The number of frame the previous detected border NOT matched the incomming border - unsigned _inconsistentCnt1; unsigned _inconsistentCnt; }; } // end namespace hyperion diff --git a/libsrc/blackborder/BlackBorderProcessor.cpp b/libsrc/blackborder/BlackBorderProcessor.cpp index b3f1824f..28262229 100644 --- a/libsrc/blackborder/BlackBorderProcessor.cpp +++ b/libsrc/blackborder/BlackBorderProcessor.cpp @@ -1,4 +1,4 @@ -#include + // Blackborder includes #include @@ -12,13 +12,9 @@ BlackBorderProcessor::BlackBorderProcessor(const unsigned unknownFrameCnt, _borderSwitchCnt(borderFrameCnt), _blurRemoveCnt(blurRemoveCnt), _detector(blackborderThreshold), - _currentBorder1({true, -1, -1}), _currentBorder({true, -1, -1}), - _previousDetectedBorder1({true, -1, -1}), _previousDetectedBorder({true, -1, -1}), - _consistentCnt1(0), _consistentCnt(0), - _inconsistentCnt1(0), _inconsistentCnt(0) { // empty @@ -29,87 +25,7 @@ BlackBorder BlackBorderProcessor::getCurrentBorder() const return _currentBorder; } - bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) -{ -bool result1 = updateBorder1(newDetectedBorder); -if (result1) -{ - std::cout << "border change v1 " << _currentBorder1.horizontalSize << ":" << _currentBorder1.verticalSize << std::endl; -} - -bool result2 = updateBorder2(newDetectedBorder); -if (result2) -{ - std::cout << "border change v2 " << _currentBorder.horizontalSize << ":" << _currentBorder.verticalSize << std::endl; -} - -return result2; -} - - -bool BlackBorderProcessor::updateBorder1(const BlackBorder & newDetectedBorder) -{ - // set the consistency counter - if (newDetectedBorder == _previousDetectedBorder1) - { - ++_consistentCnt1; - } - else - { - _previousDetectedBorder1 = newDetectedBorder; - _consistentCnt1 = 0; - } - -// std::cout << "cur: " << _currentBorder1.verticalSize << " " << _currentBorder1.horizontalSize << " new: " << newDetectedBorder.verticalSize << " " << newDetectedBorder.horizontalSize << " c:i " << _consistentCnt1 << ":" << _inconsistentCnt1 << std::endl; - - // check if there is a change - if (_currentBorder1 == newDetectedBorder) - { - // No change required - return false; - } - - bool borderChanged = false; - if (newDetectedBorder.unknown) - { - // apply the unknown border if we consistently can't determine a border - if (_consistentCnt1 == _unknownSwitchCnt) - { - _currentBorder1 = newDetectedBorder; - borderChanged = true; - } - } - else - { - // apply the detected border if it has been detected consistently - if (_currentBorder1.unknown || _consistentCnt1 == _borderSwitchCnt) - { - _currentBorder1 = newDetectedBorder; - borderChanged = true; - } - else - { - bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 ); - // apply smaller borders immediately - if ((newDetectedBorder.verticalSize < _currentBorder1.verticalSize) && (stable)) - { - _currentBorder1.verticalSize = newDetectedBorder.verticalSize; - borderChanged = true; - } - - if ((newDetectedBorder.horizontalSize < _currentBorder1.horizontalSize) && (stable)) - { - _currentBorder1.horizontalSize = newDetectedBorder.horizontalSize; - borderChanged = true; - } - } - } - - return borderChanged; -} - -bool BlackBorderProcessor::updateBorder2(const BlackBorder & newDetectedBorder) { // set the consistency counter if (newDetectedBorder == _previousDetectedBorder) @@ -124,8 +40,6 @@ bool BlackBorderProcessor::updateBorder2(const BlackBorder & newDetectedBorder) ++_inconsistentCnt; } -// std::cout << "cur: " << _currentBorder.verticalSize << " " << _currentBorder.horizontalSize << " new: " << newDetectedBorder.verticalSize << " " << newDetectedBorder.horizontalSize << " c:i " << _consistentCnt << ":" << _inconsistentCnt << std::endl; - // check if there is a change if (_currentBorder == newDetectedBorder) { From 4bc11548b4584f93b4e0b3fa83cf221d78e2edba Mon Sep 17 00:00:00 2001 From: wisc Date: Sun, 10 Jan 2016 18:42:55 +0100 Subject: [PATCH 25/26] faster detection less false positive Former-commit-id: 501de9bca4c20600fe1e6250e82143f0b0d6ade3 --- include/blackborder/BlackBorderDetector.h | 53 +-------------------- include/blackborder/BlackBorderProcessor.h | 2 - libsrc/blackborder/BlackBorderProcessor.cpp | 17 +++---- 3 files changed, 8 insertions(+), 64 deletions(-) diff --git a/include/blackborder/BlackBorderDetector.h b/include/blackborder/BlackBorderDetector.h index cd955b8a..14cf051c 100644 --- a/include/blackborder/BlackBorderDetector.h +++ b/include/blackborder/BlackBorderDetector.h @@ -62,15 +62,13 @@ namespace hyperion BlackBorder process(const Image & image) { - // only test the topleft third of the image + // test center and 1/3, 2/3 of width/heigth int width = image.width() / 3; int height = image.height() / 3; int width2 = width * 2; int height2 = height * 2; int xCenter = image.width() / 2; int yCenter = image.height() / 2; -// int maxSize = std::max(width, height); - int firstNonBlackXPixelIndex = -1; @@ -102,55 +100,6 @@ namespace hyperion } } - - -/* - // only test the topleft third of the image - int width = image.width() /3; - int height = image.height() / 3; - int maxSize = std::max(width, height); - - - - int firstNonBlackXPixelIndex = -1; - int firstNonBlackYPixelIndex = -1; - - // find some pixel of the image - for (int i = 0; i < maxSize; ++i) - { - int x = std::min(i, width); - int y = std::min(i, height); - - const Pixel_T & color = image(x, y); - if (!isBlack(color)) - { - firstNonBlackXPixelIndex = x; - firstNonBlackYPixelIndex = y; - break; - } - } - - // expand image to the left - for(; firstNonBlackXPixelIndex > 0; --firstNonBlackXPixelIndex) - { - const Pixel_T & color = image(firstNonBlackXPixelIndex-1, firstNonBlackYPixelIndex); - if (isBlack(color)) - { - break; - } - } - - // expand image to the top - for(; firstNonBlackYPixelIndex > 0; --firstNonBlackYPixelIndex) - { - const Pixel_T & color = image(firstNonBlackXPixelIndex, firstNonBlackYPixelIndex-1); - if (isBlack(color)) - { - break; - } - } -*/ - // Construct result BlackBorder detectedBorder; detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1; diff --git a/include/blackborder/BlackBorderProcessor.h b/include/blackborder/BlackBorderProcessor.h index ad8c7b83..14be0585 100644 --- a/include/blackborder/BlackBorderProcessor.h +++ b/include/blackborder/BlackBorderProcessor.h @@ -73,8 +73,6 @@ namespace hyperion /// @return True if the current border changed else false /// bool updateBorder(const BlackBorder & newDetectedBorder); - bool updateBorder1(const BlackBorder & newDetectedBorder); - bool updateBorder2(const BlackBorder & newDetectedBorder); /// The number of unknown-borders detected before it becomes the current border const unsigned _unknownSwitchCnt; diff --git a/libsrc/blackborder/BlackBorderProcessor.cpp b/libsrc/blackborder/BlackBorderProcessor.cpp index 28262229..2312da31 100644 --- a/libsrc/blackborder/BlackBorderProcessor.cpp +++ b/libsrc/blackborder/BlackBorderProcessor.cpp @@ -51,8 +51,7 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) if (newDetectedBorder.unknown) { // apply the unknown border if we consistently can't determine a border -// if (_consistentCnt == _unknownSwitchCnt) - if (_consistentCnt >= _unknownSwitchCnt) + if (_consistentCnt == _unknownSwitchCnt) { _currentBorder = newDetectedBorder; borderChanged = true; @@ -61,8 +60,7 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) else { // apply the detected border if it has been detected consistently -// if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt) - if (_currentBorder.unknown || _consistentCnt >= _borderSwitchCnt) + if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt) { _currentBorder = newDetectedBorder; borderChanged = true; @@ -70,17 +68,16 @@ bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) else { bool stable = (_consistentCnt >= 10) || (_inconsistentCnt >=30 ); - //more then A consistent seems like a new size not only a short flicker - //more then B inconsistent seems like the image is changing a lot and we need to set smaller border - // apply smaller borders immediately -// if (newDetectedBorder.verticalSize < _currentBorder.verticalSize) - if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (stable) )// almost immediatly - avoid switching for "abnormal" frames + //more then 10 consistent seems like a new size not only a short flicker + //more then 30 inconsistent seems like the image is changing a lot and we need to set smaller border + + // apply smaller borders (almost) immediately -> avoid switching for "abnormal" frames + if ( (newDetectedBorder.verticalSize < _currentBorder.verticalSize) && (stable) ) { _currentBorder.verticalSize = newDetectedBorder.verticalSize; borderChanged = true; } -// if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) if ( (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) && (stable) ) { _currentBorder.horizontalSize = newDetectedBorder.horizontalSize; From e0d04d606c56e6d7a43d4a29843d01bb4aa69349 Mon Sep 17 00:00:00 2001 From: "T.van der Zwan" Date: Wed, 13 Jan 2016 22:52:50 +0100 Subject: [PATCH 26/26] Updated releases with latest pulls Former-commit-id: 1734e9a6010789b31120f9630745b731da5109cd --- deploy/hyperion_imx6.tar.gz.REMOVED.git-id | 2 +- deploy/hyperion_rpi.tar.gz.REMOVED.git-id | 2 +- deploy/hyperion_wetek.tar.gz.REMOVED.git-id | 2 +- deploy/hyperion_x32.tar.gz.REMOVED.git-id | 2 +- deploy/hyperion_x64.tar.gz.REMOVED.git-id | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/deploy/hyperion_imx6.tar.gz.REMOVED.git-id b/deploy/hyperion_imx6.tar.gz.REMOVED.git-id index 294f2909..99536c87 100644 --- a/deploy/hyperion_imx6.tar.gz.REMOVED.git-id +++ b/deploy/hyperion_imx6.tar.gz.REMOVED.git-id @@ -1 +1 @@ -3785db40d7232275fbc00b20e627280e0e057f99 \ No newline at end of file +471d676fb66aa53e3b10d887a1d9e6d3b4afea90 \ No newline at end of file diff --git a/deploy/hyperion_rpi.tar.gz.REMOVED.git-id b/deploy/hyperion_rpi.tar.gz.REMOVED.git-id index 0f6903ba..44bbdc58 100644 --- a/deploy/hyperion_rpi.tar.gz.REMOVED.git-id +++ b/deploy/hyperion_rpi.tar.gz.REMOVED.git-id @@ -1 +1 @@ -0769228a95e4a0d4b2ed6649f21ddf70b43773d6 \ No newline at end of file +5c164e4ff52076a530461cdf6966943d52cd39df \ No newline at end of file diff --git a/deploy/hyperion_wetek.tar.gz.REMOVED.git-id b/deploy/hyperion_wetek.tar.gz.REMOVED.git-id index 4a4621a7..668065d1 100644 --- a/deploy/hyperion_wetek.tar.gz.REMOVED.git-id +++ b/deploy/hyperion_wetek.tar.gz.REMOVED.git-id @@ -1 +1 @@ -7e53ee35b7258e7d58d96514701a50014a98da31 \ No newline at end of file +d2bf44cca4e7753b53acc2ebbdb933ba8f74f93f \ No newline at end of file diff --git a/deploy/hyperion_x32.tar.gz.REMOVED.git-id b/deploy/hyperion_x32.tar.gz.REMOVED.git-id index 24239241..89355ddf 100644 --- a/deploy/hyperion_x32.tar.gz.REMOVED.git-id +++ b/deploy/hyperion_x32.tar.gz.REMOVED.git-id @@ -1 +1 @@ -36d03bb18626fa0faea8aabf6426e571eab4f719 \ No newline at end of file +7936b39302bec31b18f11a321ba6904c12b5c3ec \ No newline at end of file diff --git a/deploy/hyperion_x64.tar.gz.REMOVED.git-id b/deploy/hyperion_x64.tar.gz.REMOVED.git-id index f6368736..38e3e0b0 100644 --- a/deploy/hyperion_x64.tar.gz.REMOVED.git-id +++ b/deploy/hyperion_x64.tar.gz.REMOVED.git-id @@ -1 +1 @@ -6f86ceeb6650e527d179cf7153e0beada3b73889 \ No newline at end of file +774c67bd8e4e46d2ebf9c223a38fdfd93cae1100 \ No newline at end of file