void Led::_blink(){ _blinkCount = 0; long time = _getBlinkDelay(); _light(!_isOn); bool exit = false; while(!exit) { fd_set rfds; struct timeval tv; int retval; FD_ZERO(&rfds); FD_SET(_pipe.getReadFd(), &rfds); tv.tv_sec = 0; tv.tv_usec = time; retval = select(_pipe.getReadFd()+1, &rfds, NULL, NULL, &tv); if(retval == -1) { log(LOG_ERR, "select() failed"); exit = true; } else if (!retval) { // timeout time = _getBlinkDelay(); _light(!_isOn); if(_status == Led::BLINK_NUMBER) { ++_blinkCount; if(_blinkNumber*2 <= _blinkCount) { _blinkCount = 0; } } } else { char value = _pipe.read(); if(value == 0) { exit = true; } else if(value == Led::QUIT){ exit = true; } else{ time = _getBlinkDelay(); if(tv.tv_usec > time){ time = tv.tv_usec - time; } else{ _light(!_isOn); } } } } }
QMenu * ViewLightGL::createToolsMenu(QWidget * parent) { QMenu * menu = new QMenu(parent); QPixmap home(ViewerIcon::getPixmap(ViewerIcon::home)); QPixmap _light(ViewerIcon::getPixmap(ViewerIcon::light)); menu->addAction(home,tr("&Home"),this,SLOT(home()),Qt::CTRL+Qt::SHIFT+Qt::Key_H); menu->addAction(tr("on X axis"),this,SLOT(XAxis()),Qt::CTRL+Qt::SHIFT+Qt::Key_X); menu->addAction(tr("on Y axis"),this,SLOT(YAxis()),Qt::CTRL+Qt::SHIFT+Qt::Key_Y); menu->addAction(tr("on Z axis"),this,SLOT(ZAxis()),Qt::CTRL+Qt::SHIFT+Qt::Key_Z); menu->addSeparator(); QAction * idVisibility = menu->addAction(_light,tr("Visible"),this,SLOT(changeVisibility()),Qt::CTRL+Qt::SHIFT+Qt::Key_S); idVisibility->setCheckable( TRUE ); idVisibility->setChecked( isVisible() ); QObject::connect(this,SIGNAL(visibilityChanged( bool)),idVisibility,SLOT(setChecked(bool))); menu->addSeparator(); QAction * idLight = menu->addAction(_light, tr("&Enabled"), this, SLOT(toggleEnabled())); idLight->setCheckable(true); idLight->setChecked(isEnabled()); idLight->setWhatsThis(tr("<b>Light Rendering</b><br><br>" "Set <b>Light Rendering</b> enable/disable.<br><br>" "The Rendering will (not) take into account ligth source.<br><br>" "You can also use Menu <br><b>Tools > Renderer > Light</b><br>")); return menu; }
void Led::off() { const std::lock_guard<std::mutex> lock(_mut); if(_status == Led::OFF){ return; } _stopBlinking(); _status = Led::OFF; _light(false); }
void Led::on() { const std::lock_guard<std::mutex> lock(_mut); if(_status == Led::ON){ return; } _stopBlinking(); _status = Led::ON; _light(true); }
void ViewLightGL::fillToolBar(QToolBar * toolBar) { QPixmap _light(ViewerIcon::getPixmap(ViewerIcon::light)); QAction * idLight = toolBar->addAction(_light, tr("&Light"), this, SLOT(toggleEnabled())); idLight->setCheckable(true); idLight->setChecked(isEnabled()); idLight->setWhatsThis(tr("<b>Light Rendering</b><br><br>" "Set <b>Light Rendering</b> enable/disable.<br><br>" "The Rendering will (not) take into account ligth source.<br><br>" "You can also use Menu <br><b>Tools > Renderer > Light</b><br>")); }
Led::~Led() { _stopBlinking(); _light(false); _pin.write(Gpio::low); }