modeFactory.cpp
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2010
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering   
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: care-o-bot
00011  * ROS stack name: cob_driver
00012  * ROS package name: cob_light
00013  * Description: Switch robots led color by sending data to
00014  * the led-µC over serial connection.
00015  *                                                              
00016  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00017  *                      
00018  * Author: Benjamin Maidel, email:benjamin.maidel@ipa.fraunhofer.de
00019  * Supervised by: Benjamin Maidel, email:benjamin.maidel@ipa.fraunhofer.de
00020  *
00021  * Date of creation: August 2012
00022  * ToDo:
00023  *
00024  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00025  *
00026  * Redistribution and use in source and binary forms, with or without
00027  * modification, are permitted provided that the following conditions are met:
00028  *
00029  *     * Redistributions of source code must retain the above copyright
00030  *       notice, this list of conditions and the following disclaimer.
00031  *     * Redistributions in binary form must reproduce the above copyright
00032  *       notice, this list of conditions and the following disclaimer in the
00033  *       documentation and/or other materials provided with the distribution.
00034  *     * Neither the name of the Fraunhofer Institute for Manufacturing 
00035  *       Engineering and Automation (IPA) nor the names of its
00036  *       contributors may be used to endorse or promote products derived from
00037  *       this software without specific prior written permission.
00038  *
00039  * This program is free software: you can redistribute it and/or modify
00040  * it under the terms of the GNU Lesser General Public License LGPL as 
00041  * published by the Free Software Foundation, either version 3 of the 
00042  * License, or (at your option) any later version.
00043  * 
00044  * This program is distributed in the hope that it will be useful,
00045  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00046  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00047  * GNU Lesser General Public License LGPL for more details.
00048  * 
00049  * You should have received a copy of the GNU Lesser General Public 
00050  * License LGPL along with this program. 
00051  * If not, see <http://www.gnu.org/licenses/>.
00052  *
00053  ****************************************************************/
00054 
00055 #include <modeFactory.h>
00056 #include <staticMode.h>
00057 #include <flashMode.h>
00058 #include <breathMode.h>
00059 #include <breathColorMode.h>
00060 #include <fadeColorMode.h>
00061 
00062 
00063 ModeFactory::ModeFactory()
00064 {
00065 }
00066 ModeFactory::~ModeFactory()
00067 {
00068 }
00069 
00070 Mode* ModeFactory::create(cob_light::LightMode requestMode)
00071 {
00072         Mode* mode = NULL;
00073         color::rgba color;
00074         color.r = requestMode.color.r;
00075         color.g = requestMode.color.g;
00076         color.b = requestMode.color.b;
00077         color.a = requestMode.color.a;
00078 
00079         switch(requestMode.mode)
00080         {
00081                 case cob_light::LightMode::STATIC:
00082                         mode = new StaticMode(color, requestMode.priority, requestMode.frequency,\
00083                                 requestMode.pulses, requestMode.timeout);
00084                 break;
00085 
00086                 case cob_light::LightMode::FLASH:
00087                         mode = new FlashMode(color, requestMode.priority, requestMode.frequency,\
00088                                 requestMode.pulses, requestMode.timeout);
00089                 break;
00090 
00091                 case cob_light::LightMode::BREATH:
00092                         mode = new BreathMode(color, requestMode.priority, requestMode.frequency,\
00093                                 requestMode.pulses, requestMode.timeout);
00094                 break;
00095 
00096                 case cob_light::LightMode::BREATH_COLOR:
00097                         mode = new BreathColorMode(color, requestMode.priority, requestMode.frequency,\
00098                                 requestMode.pulses, requestMode.timeout);
00099                 break;
00100 
00101                 case cob_light::LightMode::FADE_COLOR:
00102                         mode = new FadeColorMode(color, requestMode.priority, requestMode.frequency,\
00103                                 requestMode.pulses, requestMode.timeout);
00104                 break;
00105 
00106                 default:
00107                         mode = NULL;
00108         }
00109 
00110         return mode;
00111 }
00112 
00113 Mode* ModeFactory::create(std::string requestMode, color::rgba color)
00114 {
00115         Mode* mode = NULL;
00116 
00117         if(requestMode == "Static" || requestMode == "static" || requestMode == "STATIC")
00118         {
00119                         mode = new StaticMode(color);
00120         }
00121         else if(requestMode == "Flash" || requestMode == "flash" || requestMode == "FLASH")
00122         {
00123                         mode = new FlashMode(color);
00124         }
00125         else if(requestMode == "Breath" || requestMode == "breath" || requestMode == "BREATH")
00126         {
00127                         mode = new BreathMode(color);
00128         }
00129         else if(requestMode == "BreathColor" || requestMode == "BreathColor" || requestMode == "BreathColor" ||
00130                 requestMode == "Breath_Color" || requestMode == "breath_color" || requestMode == "BREATH_COLOR")
00131         {
00132                         mode = new BreathColorMode(color);
00133         }
00134         else if(requestMode == "FadeColor" || requestMode == "fadecolor" || requestMode == "FADECOLOR" ||
00135                 requestMode == "Fade_Color" || requestMode == "fade_color" || requestMode == "FADE_COLOR")
00136         {
00137                         mode = new FadeColorMode(color);
00138         }
00139         else
00140         {
00141                 mode = NULL;
00142         }
00143 
00144         return mode;
00145 }
00146 
00147 int ModeFactory::type(Mode *mode)
00148 {
00149         int ret;
00150         if (mode == NULL)
00151                 ret = cob_light::LightMode::NONE;
00152         else if(dynamic_cast<StaticMode*>(mode) != NULL)
00153                 ret = cob_light::LightMode::STATIC;
00154         else if(dynamic_cast<FlashMode*>(mode) != NULL)
00155                 ret = cob_light::LightMode::FLASH;
00156         else if(dynamic_cast<BreathMode*>(mode) != NULL)
00157                 ret = cob_light::LightMode::BREATH;
00158         else if(dynamic_cast<BreathColorMode*>(mode) != NULL)
00159                 ret = cob_light::LightMode::BREATH_COLOR;
00160         else if(dynamic_cast<FadeColorMode*>(mode) != NULL)
00161                 ret = cob_light::LightMode::FADE_COLOR;
00162         else
00163                 ret = cob_light::LightMode::NONE;
00164 
00165         return ret;
00166 }


cob_light
Author(s): Benjamin Maidel
autogenerated on Sun Oct 5 2014 23:09:07