sweepColorMode.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 SWEEPCOLORMODE_H
00019 #define SWEEPCOLORMODE_H
00020 
00021 #include <mode.h>
00022 #include <algorithm>
00023 
00024 class SweepColorMode : public Mode
00025 {
00026 public:
00027    SweepColorMode(std::vector<color::rgba> colors, 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)
00029   {
00030     _colors = colors;
00031 
00032     _startcolor.r = 0.0;
00033     _startcolor.g = 0.4;
00034     _startcolor.b = 0.28;
00035     _startcolor.a = 1.0;
00036     if(_colors.size() == 1)
00037       _startcolor = _colors[0];
00038     _colors.resize(_num_leds);
00039     if(_num_leds%2 == 0)
00040     {
00041       _colors[_num_leds/2] = _startcolor;
00042       _colors[_num_leds/2-1] = _startcolor;
00043     }
00044     else
00045       _colors[_num_leds/2] = _startcolor;
00046     _pos = 0;
00047 
00048     _inc = (1. / UPDATE_RATE_HZ) * _freq;
00049   }
00050 
00051   void execute()
00052   {
00053     if(_timer_inc >= 1.0)
00054     {
00055       for(int i = _num_leds/2; i < _num_leds; i++)
00056       {
00057         _colors[i].a *= 0.7;
00058       }
00059       for(int i = _num_leds/2-1; i >= 0; i--)
00060       {
00061         _colors[i].a *= 0.7;
00062       }
00063       _colors[(_num_leds/2)+_pos] = _startcolor;
00064       _colors[(_num_leds/2)-1-_pos] = _startcolor;
00065 
00066       _pos++;
00067       if(_pos >= (_num_leds/2))
00068         _pos = 0;
00069 
00070       _pulsed++;
00071       m_sigColorsReady(_colors);
00072       _timer_inc = 0.0;
00073     }
00074     else
00075       _timer_inc += _inc;
00076   }
00077 
00078   std::string getName(){ return std::string("SweepColorMode"); }
00079 
00080 private:
00081   bool _toggle;
00082   double _timer_inc;
00083   double _inc;
00084   size_t _num_leds;
00085   int _pos;
00086   color::rgba _startcolor;
00087 };
00088 
00089 #endif


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