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 BREATHMODE_H 00019 #define BREATHMODE_H 00020 00021 #include <mode.h> 00022 00023 class BreathMode : public Mode 00024 { 00025 public: 00026 BreathMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0) 00027 :Mode(priority, freq, pulses, timeout), _timer_inc(0.0) 00028 { 00029 _color = color; 00030 _init_color = color; 00031 _inc = ((M_PI*2) / UPDATE_RATE_HZ) * _freq; 00032 } 00033 00034 void execute() 00035 { 00036 //double fV = (exp(sin(_timer_inc))-1.0/M_E)*(1.000/(M_E-1.0/M_E)); 00037 double fV = (exp(-cos(_timer_inc))-0.36787944)*0.42545906411; 00038 00039 _timer_inc += _inc; 00040 if(_timer_inc >= M_PI*2) 00041 { 00042 _timer_inc = 0.0; 00043 _pulsed++; 00044 } 00045 00046 _color.a = fV * _init_color.a; 00047 _color.a = _color.a > 1 ? 1 : _color.a < 0 ? 0 : _color.a; 00048 00049 m_sigColorReady(_color); 00050 } 00051 00052 std::string getName(){ return std::string("BreathMode"); } 00053 00054 private: 00055 double _timer_inc; 00056 double _inc; 00057 }; 00058 00059 #endif