2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
2011-02-22 19:56:52 +01:00
|
|
|
* Copyright (c) 2004-2011
|
2006-12-18 15:39:33 +01:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
* Description:
|
2009-05-01 12:06:07 +02:00
|
|
|
* Implements a multi color LED
|
2008-03-28 22:46:13 +01:00
|
|
|
*
|
2006-12-18 15:39:33 +01:00
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
2008-03-28 22:46:13 +01:00
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
2006-12-18 15:39:33 +01:00
|
|
|
* version.
|
|
|
|
*
|
2008-03-28 22:46:13 +01:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
2006-12-18 15:39:33 +01:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2008-03-28 22:46:13 +01:00
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
2006-12-18 15:39:33 +01:00
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
2008-03-28 22:46:13 +01:00
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
2006-12-18 15:39:33 +01:00
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
|
|
|
#include "multicolorled.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Implementation *************************************************************/
|
2008-02-01 09:27:09 +01:00
|
|
|
CMultiColorLED::CMultiColorLED ( QWidget* parent, Qt::WindowFlags f )
|
2008-01-17 19:56:43 +01:00
|
|
|
: QLabel ( parent, f ),
|
2009-06-13 10:14:11 +02:00
|
|
|
BitmCubeDisabled ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDDisabledSmall.png" ) ),
|
|
|
|
BitmCubeGrey ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDGreySmall.png" ) ),
|
|
|
|
BitmCubeGreen ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDGreenSmall.png" ) ),
|
|
|
|
BitmCubeYellow ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDYellowSmall.png" ) ),
|
|
|
|
BitmCubeRed ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDRedSmall.png" ) )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2008-01-27 15:41:12 +01:00
|
|
|
// init color flags
|
2006-12-18 15:39:33 +01:00
|
|
|
Reset();
|
|
|
|
|
2008-01-27 15:41:12 +01:00
|
|
|
// set init bitmap
|
2008-02-01 09:27:09 +01:00
|
|
|
setPixmap ( BitmCubeGrey );
|
2006-12-18 15:39:33 +01:00
|
|
|
eColorFlag = RL_GREY;
|
|
|
|
|
2008-01-27 15:41:12 +01:00
|
|
|
// init update time
|
2008-03-28 22:46:13 +01:00
|
|
|
SetUpdateTime ( DEFAULT_UPDATE_TIME );
|
2008-03-28 19:41:46 +01:00
|
|
|
|
2008-03-28 22:46:13 +01:00
|
|
|
// init timers -> we want to have single shot timers
|
|
|
|
TimerRedLight.setSingleShot ( true );
|
|
|
|
TimerGreenLight.setSingleShot ( true );
|
|
|
|
TimerYellowLight.setSingleShot ( true );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2008-01-27 15:41:12 +01:00
|
|
|
// connect timer events to the desired slots
|
2009-05-01 12:06:07 +02:00
|
|
|
connect ( &TimerRedLight, SIGNAL ( timeout() ),
|
2007-09-08 12:45:14 +02:00
|
|
|
this, SLOT ( OnTimerRedLight() ) );
|
2009-05-01 12:06:07 +02:00
|
|
|
connect ( &TimerGreenLight, SIGNAL ( timeout() ),
|
2007-09-08 12:45:14 +02:00
|
|
|
this, SLOT ( OnTimerGreenLight() ) );
|
2009-05-01 12:06:07 +02:00
|
|
|
connect ( &TimerYellowLight, SIGNAL ( timeout() ),
|
2007-09-08 12:45:14 +02:00
|
|
|
this, SLOT ( OnTimerYellowLight() ) );
|
2008-03-28 22:46:13 +01:00
|
|
|
|
2009-05-01 12:06:07 +02:00
|
|
|
connect ( this, SIGNAL ( newPixmap ( const QPixmap& ) ),
|
2008-03-28 22:46:13 +01:00
|
|
|
this, SLOT ( OnNewPixmap ( const QPixmap& ) ) );
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
|
2009-06-13 10:14:11 +02:00
|
|
|
void CMultiColorLED::changeEvent ( QEvent* curEvent )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2009-06-13 10:14:11 +02:00
|
|
|
// act on enabled changed state
|
|
|
|
if ( curEvent->type() == QEvent::EnabledChange )
|
|
|
|
{
|
|
|
|
if ( this->isEnabled() )
|
|
|
|
{
|
|
|
|
emit newPixmap ( BitmCubeGrey );
|
|
|
|
eColorFlag = RL_GREY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
emit newPixmap ( BitmCubeDisabled );
|
|
|
|
eColorFlag = RL_DISABLED;
|
|
|
|
}
|
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
|
2008-02-01 09:27:09 +01:00
|
|
|
void CMultiColorLED::OnTimerRedLight()
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
|
|
|
bFlagRedLi = false;
|
|
|
|
UpdateColor();
|
|
|
|
}
|
|
|
|
|
2008-02-01 09:27:09 +01:00
|
|
|
void CMultiColorLED::OnTimerGreenLight()
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
|
|
|
bFlagGreenLi = false;
|
|
|
|
UpdateColor();
|
|
|
|
}
|
|
|
|
|
2008-02-01 09:27:09 +01:00
|
|
|
void CMultiColorLED::OnTimerYellowLight()
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
|
|
|
bFlagYellowLi = false;
|
|
|
|
UpdateColor();
|
|
|
|
}
|
|
|
|
|
2008-02-01 09:27:09 +01:00
|
|
|
void CMultiColorLED::UpdateColor()
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
|
|
|
/* Red light has highest priority, then comes yellow and at the end, we
|
|
|
|
decide to set green light. Allways check the current color of the
|
|
|
|
control before setting the color to prevent flicking */
|
2007-09-08 12:45:14 +02:00
|
|
|
if ( bFlagRedLi )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2007-09-08 12:45:14 +02:00
|
|
|
if ( eColorFlag != RL_RED )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2008-03-29 07:32:44 +01:00
|
|
|
emit newPixmap ( BitmCubeRed );
|
2006-12-18 15:39:33 +01:00
|
|
|
eColorFlag = RL_RED;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
if ( bFlagYellowLi )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2007-09-08 12:45:14 +02:00
|
|
|
if ( eColorFlag != RL_YELLOW )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2008-03-29 07:32:44 +01:00
|
|
|
emit newPixmap ( BitmCubeYellow );
|
2006-12-18 15:39:33 +01:00
|
|
|
eColorFlag = RL_YELLOW;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
if ( bFlagGreenLi )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2007-09-08 12:45:14 +02:00
|
|
|
if ( eColorFlag != RL_GREEN )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2008-03-29 07:32:44 +01:00
|
|
|
emit newPixmap ( BitmCubeGreen );
|
2006-12-18 15:39:33 +01:00
|
|
|
eColorFlag = RL_GREEN;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-27 15:41:12 +01:00
|
|
|
// if no color is active, set control to grey light
|
2007-09-08 12:45:14 +02:00
|
|
|
if ( eColorFlag != RL_GREY )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2008-02-01 09:27:09 +01:00
|
|
|
setPixmap ( BitmCubeGrey );
|
2006-12-18 15:39:33 +01:00
|
|
|
eColorFlag = RL_GREY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-13 10:14:11 +02:00
|
|
|
void CMultiColorLED::Reset()
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2009-06-13 10:14:11 +02:00
|
|
|
if ( this->isEnabled() )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2009-06-13 10:14:11 +02:00
|
|
|
// reset color flags
|
|
|
|
bFlagRedLi = false;
|
|
|
|
bFlagGreenLi = false;
|
|
|
|
bFlagYellowLi = false;
|
|
|
|
|
|
|
|
UpdateColor();
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
2009-06-13 10:14:11 +02:00
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2009-06-13 10:14:11 +02:00
|
|
|
void CMultiColorLED::SetLight ( const int iNewStatus )
|
|
|
|
{
|
|
|
|
if ( this->isEnabled() )
|
|
|
|
{
|
|
|
|
switch ( iNewStatus )
|
|
|
|
{
|
|
|
|
case MUL_COL_LED_GREEN:
|
|
|
|
// green light
|
|
|
|
bFlagGreenLi = true;
|
|
|
|
TimerGreenLight.start();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MUL_COL_LED_YELLOW:
|
|
|
|
// yellow light
|
|
|
|
bFlagYellowLi = true;
|
|
|
|
TimerYellowLight.start();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MUL_COL_LED_RED:
|
|
|
|
// red light
|
|
|
|
bFlagRedLi = true;
|
|
|
|
TimerRedLight.start();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateColor();
|
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
|
2008-02-01 09:27:09 +01:00
|
|
|
void CMultiColorLED::SetUpdateTime ( const int iNUTi )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2008-01-27 15:41:12 +01:00
|
|
|
// avoid too short intervals
|
2007-09-08 12:45:14 +02:00
|
|
|
if ( iNUTi < MIN_TIME_FOR_RED_LIGHT )
|
2008-03-28 22:46:13 +01:00
|
|
|
{
|
2006-12-18 15:39:33 +01:00
|
|
|
iUpdateTime = MIN_TIME_FOR_RED_LIGHT;
|
2008-03-28 22:46:13 +01:00
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
else
|
2008-03-28 22:46:13 +01:00
|
|
|
{
|
2006-12-18 15:39:33 +01:00
|
|
|
iUpdateTime = iNUTi;
|
2008-03-28 22:46:13 +01:00
|
|
|
}
|
2008-03-28 19:41:46 +01:00
|
|
|
|
2008-03-28 22:46:13 +01:00
|
|
|
TimerGreenLight.setInterval ( iUpdateTime );
|
|
|
|
TimerYellowLight.setInterval ( iUpdateTime );
|
|
|
|
TimerRedLight.setInterval ( iUpdateTime );
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|