modeFactory.cpp
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 #include <modeFactory.h>
00019 #include <staticMode.h>
00020 #include <flashMode.h>
00021 #include <breathMode.h>
00022 #include <breathColorMode.h>
00023 #include <fadeColorMode.h>
00024 #include <sequenceMode.h>
00025 #include <circleColorMode.h>
00026 #include <sweepColorMode.h>
00027 #include <distApproxMode.h>
00028 #include <glowColorMode.h>
00029 #include <xmasMode.h>
00030 
00031 ModeFactory::ModeFactory()
00032 {
00033 }
00034 ModeFactory::~ModeFactory()
00035 {
00036 }
00037 
00038 boost::shared_ptr<Mode> ModeFactory::create(cob_light::LightMode requestMode, IColorO* colorO)
00039 {
00040     boost::shared_ptr<Mode> mode;
00041     color::rgba color;
00042     color.r = requestMode.colors[0].r;
00043     color.g = requestMode.colors[0].g;
00044     color.b = requestMode.colors[0].b;
00045     color.a = requestMode.colors[0].a;
00046 
00047     switch(requestMode.mode)
00048     {
00049     case cob_light::LightModes::STATIC:
00050         mode.reset(new StaticMode(color, requestMode.priority, requestMode.frequency,\
00051                                   requestMode.pulses, requestMode.timeout));
00052         break;
00053 
00054     case cob_light::LightModes::FLASH:
00055         mode.reset(new FlashMode(color, requestMode.priority, requestMode.frequency,\
00056                                  requestMode.pulses, requestMode.timeout));
00057         break;
00058 
00059     case cob_light::LightModes::BREATH:
00060         mode.reset(new BreathMode(color, requestMode.priority, requestMode.frequency,\
00061                                   requestMode.pulses, requestMode.timeout));
00062         break;
00063 
00064     case cob_light::LightModes::BREATH_COLOR:
00065         mode.reset(new BreathColorMode(color, requestMode.priority, requestMode.frequency,\
00066                                        requestMode.pulses, requestMode.timeout));
00067         break;
00068 
00069     case cob_light::LightModes::FADE_COLOR:
00070         mode.reset(new FadeColorMode(color, requestMode.priority, requestMode.frequency,\
00071                                      requestMode.pulses, requestMode.timeout));
00072         break;
00073 
00074     case cob_light::LightModes::SEQ:
00075     {
00076         std::vector<seq_t> seqs;
00077         for(size_t i = 0; i < requestMode.sequences.size(); i++)
00078         {
00079             seq_t seq;
00080             seq.color.r = requestMode.sequences[i].color.r;
00081             seq.color.g = requestMode.sequences[i].color.g;
00082             seq.color.b = requestMode.sequences[i].color.b;
00083             seq.color.a = requestMode.sequences[i].color.a;
00084             seq.holdtime = requestMode.sequences[i].hold_time;
00085             seq.crosstime = requestMode.sequences[i].cross_time;
00086             seqs.push_back(seq);
00087             std::cout<<"got new seq: "<<seq.color.r<<" "<<seq.color.g<<" "<<seq.color.b<<std::endl;
00088         }
00089         mode.reset(new SequenceMode(seqs, requestMode.priority, requestMode.frequency,\
00090                                     requestMode.pulses, requestMode.timeout));
00091     }
00092         break;
00093 
00094     case cob_light::LightModes::CIRCLE_COLORS:
00095     {
00096         std::vector<color::rgba> colors;
00097         if(requestMode.colors.empty())
00098         {
00099             colors.push_back(color);
00100         }
00101         else
00102         {
00103             for(size_t i = 0; i < requestMode.colors.size(); i++)
00104             {
00105                 color.r = requestMode.colors[i].r;
00106                 color.g = requestMode.colors[i].g;
00107                 color.b = requestMode.colors[i].b;
00108                 color.a = requestMode.colors[i].a;
00109                 colors.push_back(color);
00110             }
00111         }
00112         mode.reset(new CircleColorMode(colors, colorO->getNumLeds(), requestMode.priority, requestMode.frequency,\
00113                                        requestMode.pulses, requestMode.timeout));
00114     }
00115         break;
00116 
00117     case cob_light::LightModes::SWEEP:
00118     {
00119         std::vector<color::rgba> colors;
00120         if(requestMode.colors.empty())
00121         {
00122             colors.push_back(color);
00123         }
00124         else
00125         {
00126             for(size_t i = 0; i < requestMode.colors.size(); i++)
00127             {
00128                 color.r = requestMode.colors[i].r;
00129                 color.g = requestMode.colors[i].g;
00130                 color.b = requestMode.colors[i].b;
00131                 color.a = requestMode.colors[i].a;
00132                 colors.push_back(color);
00133             }
00134         }
00135         mode.reset(new SweepColorMode(colors, colorO->getNumLeds(), requestMode.priority, requestMode.frequency,
00136                                       requestMode.pulses, requestMode.timeout));
00137     }
00138         break;
00139 
00140     case cob_light::LightModes::DIST_APPROX:
00141         mode.reset(new DistApproxMode(colorO->getNumLeds(), requestMode.priority, requestMode.frequency,
00142                                       requestMode.pulses, requestMode.timeout));
00143         break;
00144 
00145     case cob_light::LightModes::GLOW:
00146         mode.reset(new GlowColorMode(color, requestMode.priority, requestMode.frequency,\
00147                                      requestMode.pulses, requestMode.timeout));
00148         break;
00149 
00150     case cob_light::LightModes::XMAS:
00151         mode.reset(new XMasMode(colorO->getNumLeds(), requestMode.priority, requestMode.frequency,\
00152                                      requestMode.pulses, requestMode.timeout));
00153         break;
00154 
00155     default:
00156         mode.reset();
00157     }
00158 
00159     return mode;
00160 }
00161 
00162 boost::shared_ptr<Mode> ModeFactory::create(std::string requestMode, color::rgba color)
00163 {
00164     boost::shared_ptr<Mode> mode;
00165 
00166     if(requestMode == "Static" || requestMode == "static" || requestMode == "STATIC")
00167     {
00168         mode.reset(new StaticMode(color));
00169     }
00170     else if(requestMode == "Flash" || requestMode == "flash" || requestMode == "FLASH")
00171     {
00172         mode.reset(new FlashMode(color));
00173     }
00174     else if(requestMode == "Breath" || requestMode == "breath" || requestMode == "BREATH")
00175     {
00176         mode.reset(new BreathMode(color));
00177     }
00178     else if(requestMode == "BreathColor" || requestMode == "BreathColor" || requestMode == "BreathColor" ||
00179             requestMode == "Breath_Color" || requestMode == "breath_color" || requestMode == "BREATH_COLOR")
00180     {
00181         mode.reset(new BreathColorMode(color));
00182     }
00183     else if(requestMode == "FadeColor" || requestMode == "fadecolor" || requestMode == "FADECOLOR" ||
00184             requestMode == "Fade_Color" || requestMode == "fade_color" || requestMode == "FADE_COLOR")
00185     {
00186         mode.reset(new FadeColorMode(color));
00187     }
00188     else
00189         mode.reset();
00190 
00191     return mode;
00192 }
00193 
00194 int ModeFactory::type(Mode *mode)
00195 {
00196     int ret;
00197     if (mode == NULL)
00198         ret = cob_light::LightModes::NONE;
00199     else if(dynamic_cast<StaticMode*>(mode) != NULL)
00200         ret = cob_light::LightModes::STATIC;
00201     else if(dynamic_cast<FlashMode*>(mode) != NULL)
00202         ret = cob_light::LightModes::FLASH;
00203     else if(dynamic_cast<BreathMode*>(mode) != NULL)
00204         ret = cob_light::LightModes::BREATH;
00205     else if(dynamic_cast<BreathColorMode*>(mode) != NULL)
00206         ret = cob_light::LightModes::BREATH_COLOR;
00207     else if(dynamic_cast<FadeColorMode*>(mode) != NULL)
00208         ret = cob_light::LightModes::FADE_COLOR;
00209     else if(dynamic_cast<SequenceMode*>(mode) != NULL)
00210         ret = cob_light::LightModes::SEQ;
00211     else if(dynamic_cast<CircleColorMode*>(mode) != NULL)
00212         ret = cob_light::LightModes::CIRCLE_COLORS;
00213     else if(dynamic_cast<SweepColorMode*>(mode) != NULL)
00214         ret = cob_light::LightModes::SWEEP;
00215     else if(dynamic_cast<DistApproxMode*>(mode) != NULL)
00216         ret = cob_light::LightModes::DIST_APPROX;
00217     else if(dynamic_cast<GlowColorMode*>(mode) != NULL)
00218         ret = cob_light::LightModes::GLOW;
00219     else if(dynamic_cast<XMasMode*>(mode) != NULL)
00220         ret = cob_light::LightModes::XMAS;
00221     else
00222         ret = cob_light::LightModes::NONE;
00223 
00224     return ret;
00225 }


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