2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
2008-01-27 15:41:12 +01:00
|
|
|
* Copyright (c) 2004-2008
|
2006-12-18 15:39:33 +01:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Implements a multi-color LED
|
|
|
|
*
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
|
|
|
#include "multicolorled.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Implementation *************************************************************/
|
2008-01-17 19:56:43 +01:00
|
|
|
CMultiColorLEDbase::CMultiColorLEDbase ( QWidget* parent, Qt::WindowFlags f )
|
|
|
|
: QLabel ( parent, f ),
|
2008-01-15 23:54:04 +01:00
|
|
|
BitmCubeGreen ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL ),
|
|
|
|
BitmCubeRed ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL ),
|
|
|
|
BitmCubeGrey ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL ),
|
|
|
|
BitmCubeYellow ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2008-01-27 15:41:12 +01:00
|
|
|
// create bitmaps
|
|
|
|
BitmCubeGreen.fill ( QColor ( 0, 255, 0 ) );
|
|
|
|
BitmCubeRed.fill ( QColor ( 255, 0, 0 ) );
|
|
|
|
BitmCubeGrey.fill ( QColor ( 192, 192, 192 ) );
|
2007-09-08 12:45:14 +02:00
|
|
|
BitmCubeYellow.fill ( QColor ( 255, 255, 0 ) );
|
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
|
2007-09-08 12:45:14 +02: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
|
2006-12-18 15:39:33 +01:00
|
|
|
iUpdateTime = DEFAULT_UPDATE_TIME;
|
|
|
|
|
2008-01-27 15:41:12 +01:00
|
|
|
// connect timer events to the desired slots
|
2007-09-08 12:45:14 +02:00
|
|
|
connect ( &TimerRedLight, SIGNAL ( timeout() ),
|
|
|
|
this, SLOT ( OnTimerRedLight() ) );
|
|
|
|
connect ( &TimerGreenLight, SIGNAL ( timeout() ),
|
|
|
|
this, SLOT ( OnTimerGreenLight() ) );
|
|
|
|
connect ( &TimerYellowLight, SIGNAL ( timeout() ),
|
|
|
|
this, SLOT ( OnTimerYellowLight() ) );
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMultiColorLEDbase::Reset()
|
|
|
|
{
|
2008-01-27 15:41:12 +01:00
|
|
|
// reset color flags
|
|
|
|
bFlagRedLi = false;
|
|
|
|
bFlagGreenLi = false;
|
2006-12-18 15:39:33 +01:00
|
|
|
bFlagYellowLi = false;
|
|
|
|
|
|
|
|
UpdateColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMultiColorLEDbase::OnTimerRedLight()
|
|
|
|
{
|
|
|
|
bFlagRedLi = false;
|
|
|
|
UpdateColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMultiColorLEDbase::OnTimerGreenLight()
|
|
|
|
{
|
|
|
|
bFlagGreenLi = false;
|
|
|
|
UpdateColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMultiColorLEDbase::OnTimerYellowLight()
|
|
|
|
{
|
|
|
|
bFlagYellowLi = false;
|
|
|
|
UpdateColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMultiColorLEDbase::UpdateColor()
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
{
|
2007-09-08 12:45:14 +02:00
|
|
|
SetPixmap ( 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
|
|
|
{
|
2007-09-08 12:45:14 +02:00
|
|
|
SetPixmap ( 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
|
|
|
{
|
2007-09-08 12:45:14 +02:00
|
|
|
SetPixmap ( 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
|
|
|
{
|
2007-09-08 12:45:14 +02:00
|
|
|
SetPixmap ( BitmCubeGrey );
|
2006-12-18 15:39:33 +01:00
|
|
|
eColorFlag = RL_GREY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-27 15:41:12 +01:00
|
|
|
void CMultiColorLEDbase::SetLight ( const int iNewStatus )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
2007-09-08 12:45:14 +02:00
|
|
|
switch ( iNewStatus )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
|
|
|
case MUL_COL_LED_GREEN:
|
2008-01-27 15:41:12 +01:00
|
|
|
// green light
|
2006-12-18 15:39:33 +01:00
|
|
|
bFlagGreenLi = true;
|
2008-01-15 23:54:04 +01:00
|
|
|
TimerGreenLight.setInterval ( iUpdateTime );
|
2006-12-18 15:39:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MUL_COL_LED_YELLOW:
|
2008-01-27 15:41:12 +01:00
|
|
|
// yellow light
|
2006-12-18 15:39:33 +01:00
|
|
|
bFlagYellowLi = true;
|
2008-01-15 23:54:04 +01:00
|
|
|
TimerYellowLight.setInterval ( iUpdateTime );
|
2006-12-18 15:39:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MUL_COL_LED_RED:
|
2008-01-27 15:41:12 +01:00
|
|
|
// red light
|
2006-12-18 15:39:33 +01:00
|
|
|
bFlagRedLi = true;
|
2008-01-15 23:54:04 +01:00
|
|
|
TimerRedLight.setInterval ( iUpdateTime );
|
2006-12-18 15:39:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateColor();
|
|
|
|
}
|
|
|
|
|
2008-01-27 15:41:12 +01:00
|
|
|
void CMultiColorLEDbase::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 )
|
|
|
|
{
|
2006-12-18 15:39:33 +01:00
|
|
|
iUpdateTime = MIN_TIME_FOR_RED_LIGHT;
|
2007-09-08 12:45:14 +02:00
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
else
|
2007-09-08 12:45:14 +02:00
|
|
|
{
|
2006-12-18 15:39:33 +01:00
|
|
|
iUpdateTime = iNUTi;
|
2007-09-08 12:45:14 +02:00
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 19:56:43 +01:00
|
|
|
CMultiColorLED::CMultiColorLED ( QWidget* parent, Qt::WindowFlags f )
|
|
|
|
: CMultiColorLEDbase ( parent, f )
|
2006-12-18 15:39:33 +01:00
|
|
|
{
|
|
|
|
// set modified style
|
2008-01-27 15:41:12 +01:00
|
|
|
setFrameShape ( QFrame::Panel );
|
2007-09-08 12:45:14 +02:00
|
|
|
setFrameShadow ( QFrame::Sunken );
|
2008-01-27 15:41:12 +01:00
|
|
|
setIndent ( 0 );
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|