xmasMode.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #ifndef XMASMODE_H
00019 #define XMASMODE_H
00020 
00021 #include <mode.h>
00022 #include <algorithm>
00023 
00024 class XMasMode : public Mode
00025 {
00026 public:
00027    XMasMode(size_t num_leds, int priority = 0, double freq = 5, int pulses = 0, double timeout = 0)
00028     :Mode(priority, freq, pulses, timeout), _toggle(false), _timer_inc(0), _num_leds(num_leds), _chucksize(5)
00029   {
00030     _colors.resize(num_leds);
00031     if(_num_leds >= _chucksize*2)
00032     {
00033       int n_chunks = _num_leds / _chucksize + (_num_leds%_chucksize ? 1 : 0);
00034       int k = 0;
00035       for(int i = 0; i < n_chunks; i++)
00036       {
00037         for(int j = 0; j < _chucksize; j++)
00038         {
00039           if(k >= _num_leds)
00040             break;
00041           if(i%2 == 0)
00042           {
00043             _colors.at(k).r = 1.0; _colors.at(k).g = 0.0; _colors.at(k).b = 0.0; _colors.at(k).a = 1.0;
00044           }
00045           else
00046           {
00047             _colors.at(k).r = 1.0; _colors.at(k).g = 1.0; _colors.at(k).b = 1.0; _colors.at(k).a = 1.0;
00048           }
00049           k++;
00050         }
00051       }
00052     }
00053     else
00054     {
00055       for(int i = 0; i < _num_leds; i++)
00056       {
00057         if(i%2==0)
00058         {
00059           _colors.at(i).r = 1.0; _colors.at(i).g = 0.0; _colors.at(i).b = 0.0; _colors.at(i).a = 1.0;
00060         }
00061         else
00062         {
00063           _colors.at(i).r = 1.0; _colors.at(i).g = 1.0; _colors.at(i).b = 1.0; _colors.at(i).a = 1.0;
00064         }
00065       }
00066     }
00067     if(_pulses != 0)
00068     {
00069       _pulses *=2;
00070       _pulses +=1;
00071     }
00072     _inc = (1. / UPDATE_RATE_HZ) * _freq;
00073   }
00074 
00075   void execute()
00076   {
00077     if(_timer_inc >= 1.0)
00078     {
00079       if(_num_leds >= _chucksize*2)
00080         std::rotate(_colors.begin(), _colors.begin()+_chucksize, _colors.end());
00081       else
00082         std::rotate(_colors.begin(), _colors.begin()+1, _colors.end());
00083       _pulsed++;
00084       m_sigColorsReady(_colors);
00085       _timer_inc = 0.0;
00086     }
00087     else
00088       _timer_inc += _inc;
00089   }
00090 
00091   std::string getName(){ return std::string("XMasMode"); }
00092 
00093 private:
00094   bool _toggle;
00095   double _timer_inc;
00096   double _inc;
00097   size_t _num_leds;
00098   size_t _chucksize;
00099 };
00100 
00101 #endif


cob_light
Author(s): Benjamin Maidel
autogenerated on Sat Jun 8 2019 21:02:07