Пример #1
0
void WatchMoviesView::startPlay()
{
	if(mUi->moviesTable->selectedItems().size() > 0 && mUi->moviesTable->item(mUi->moviesTable->currentRow(), 8)) {
		QString file = mUi->moviesTable->item(mUi->moviesTable->currentRow(), 8)->text();
		bool loadMovie = false;
		bool startMode = false;
		bool movieOk = false;
		bool playOk = false;
		MovieFile *movieFile = NULL;
		ModeManager *modeManager = ModeManager::instance();

		if(mMovieFile) {
			if(mMovieFile->getMovieFile() == file)
				mMovieFile->rewind();
			else
				loadMovie = true;
		} else {
			loadMovie = true;
			startMode = true;
		}

		if(loadMovie) {
			movieFile = new MovieFile(OptionsView::instance()->getMoviesDir()
										   + "/"
										   + file);
			movieOk = movieFile->loadMovie(true);
		}

		if(movieOk && startMode) {
			if(modeManager->startMode(MODE_PLAY)) {
				modeManager->setMovieFile(movieFile);
				playOk = true;
			}
		} else if(movieOk && !startMode) {
			modeManager->setMovieFile(movieFile);
			playOk = true;
		}

		if(playOk) {
			connect(movieFile, SIGNAL(movieStarted()), this, SLOT(onPlayStart()));
			connect(movieFile, SIGNAL(movieTime(uint32)), this, SLOT(onPlayTime(uint32)));

			mUi->stopButton->setEnabled(true);

			mUi->movieFileLabelValue->setText(mUi->moviesTable->item(mUi->moviesTable->currentRow(), 8)->text());
			mUi->speedLabelValue->setText("1.00x");
			mUi->speedSlider->setValue(0);
			mUi->playProgressBar->setValue(0);

			mUi->statusLabelValue->setText(tr("Waiting tibia connection..."));
			mUi->statusLabelValue->setStyleSheet("color: #808000; font-weight: bold");

			if(mMovieFile)
				delete mMovieFile;
			mMovieFile = movieFile;
		}
	} else {
		qCritical() << qPrintable(tr("You must select a movie to play."));
	}
}
void WorkspaceSettings::apply()
{
    selectWorkspace(m_currentIndex, true);

    saveSettings(Core::ICore::instance()->settings());

    ModeManager* modeManager = Core::ICore::instance()->modeManager();
    for (int i = 0; i < MAX_WORKSPACES; ++i) {
        Core::Internal::UAVGadgetMode *mode =
                qobject_cast<Core::Internal::UAVGadgetMode*>(modeManager->mode(modeName(i)));
        if (mode) {
            modeManager->updateModeNameIcon(mode, QIcon(iconName(i)), name(i));
        }
    }

}
Пример #3
0
void WorkspaceSettings::apply()
{
    selectWorkspace(m_currentIndex, true);

    saveSettings(Core::ICore::instance()->settings());

    if (m_numberOfWorkspaces != m_previousNumberOfWorkspaces) {
        Core::ICore::instance()->readMainSettings(Core::ICore::instance()->settings(), true);
        m_previousNumberOfWorkspaces = m_numberOfWorkspaces;
    }

    ModeManager* modeManager = Core::ICore::instance()->modeManager();
    for (int i = 0; i < MAX_WORKSPACES; ++i) {
        IMode *baseMode = modeManager->mode(modeName(i));
        Core::UAVGadgetManager *mode = qobject_cast<Core::UAVGadgetManager*>(baseMode);
        if (mode) {
            modeManager->updateModeNameIcon(mode, QIcon(iconName(i)), name(i));
        }
    }
    m_tabBarPlacementIndex = m_page->comboBoxTabBarPlacement->currentIndex();
    m_allowTabBarMovement = m_page->checkBoxAllowTabMovement->isChecked();
    QTabWidget::TabPosition pos = m_tabBarPlacementIndex == 0 ? QTabWidget::North : QTabWidget::South;
    emit tabBarSettingsApplied(pos, m_allowTabBarMovement);
}
Пример #4
0
//Callback function that is called when a commend is receied
void callback(const char *key, const char *value) 
{
    //pc.printf("CallBack %s : %s\n",key, value);

    if(strstr(value,"modeoff")!=NULL)
    {
        pc.printf("CallBack modeOFF\n\r");
        modeManager.setMode(OFF);
        modeManager.setModeJustChanged(true); 
    }
    else if(strstr(value,"modeauto")!=NULL)
    {
        pc.printf("CallBack modeAUTO\n\r"); 
        modeManager.setMode(AUTO);
        modeManager.setModeJustChanged(true); 
    }
    else if(strstr(value,"modeon")!=NULL)
    {
        pc.printf("CallBack modeON\n\r"); 
        modeManager.setMode(ON);
        modeManager.setModeJustChanged(true); 
    }
}
Пример #5
0
int main() 
{
    //Declaration of the object   
    LedCmd              ledcommander;
    LightDetector       lightDetector;
    FailureDetector     failureDetector;
    PowerConsumption    powerConsumption;
    PreviousState       previousState=LIGHT_OFF;
    Mode                previousMode=AUTO;
    bool    isFirstTime=true;
    float   power=0;
    float   lightSensor=0;
    char    str1[16];
    char    str2[16];
    char*   server="eu.airvantage.net";
    char*   apn="internet.maingate.se";
    int     port = 1883;
    char*   password="******";
    
    dout1=0;
        
    //Step 1 : Initialize in AUTO Mode
    modeManager.setMode(AUTO);
    
    //Step 2 Configure the Serial connection(used to communication with the Kompel card)
    pc.baud(115200);
    
    //Step 3 Start the Kompel card
    startKompel();
    
    wait(2);
    //Step 4 :
    MQTTClient  client(server, &callback, password, port, &pc, apn);  
     
    while(1) 
    {      
        if(client.connected == true)
        {  
            //Green Light On
            dout1 = 1;
            if(modeManager.getMode() == AUTO)
            {
                    //Check first if the ambiant light is under the threshold
                    if(lightDetector.isLightUnderTrigger())
                    {
                          
                        wait(0.5);
                        //If under, check if there is a failure and publish just once
                        if(failureDetector.isFailureDetected())
                        {
                            if(previousState!=FAIL)
                            {
                                wait(0.1);
                                ledcommander.setOff();
                                wait(0.5);
                                sprintf(str1,"%f",0.0); 
                                lightSensor = lightDetector.getLightSensorValue();
                                sprintf(str2,"%f",lightSensor); 
                                client.pub("st.power",str1,"st.lightsensor",str2,"st.lightstatus","on","st.failuredetected","true");
                                blinkPublish();
                                previousState = FAIL;
                            }
                        }
                        //If under and no failure, publish just once
                        else
                        {
                            if(previousMode == OFF || previousState == LIGHT_OFF || previousState == FAIL || previousMode == ON)
                            {  
                                wait(0.1);
                                ledcommander.setOn();
                                wait(0.5);
                                power = powerConsumption.getPower();
                                sprintf(str1,"%f",power); 
                                lightSensor=lightDetector.getLightSensorValue();
                                sprintf(str2,"%f",lightSensor); 
                                client.pub("st.power",str1,"st.lightsensor",str2,"st.lightstatus","on","st.failuredetected","false");
                                blinkPublish();
                                modeManager.setModeJustChanged(false);  
                                previousState = LIGHT_ON;
                            }    
                        }
                        
                    
                    }
                    //if the ambiant light isn't under the threshold, the lamp switches off.
                    else
                    {
                        ledcommander.setOff(); 
                        if(isFirstTime == true || previousMode == OFF || previousState == LIGHT_ON || previousState == FAIL || previousMode == ON)
                        { 
                            wait(0.1);
                            sprintf(str1,"%f",0.0); 
                            lightSensor = lightDetector.getLightSensorValue();
                            sprintf(str2,"%f",lightSensor); 
                            client.pub("st.power",str1,"st.lightsensor",str2,"st.lightstatus","off","st.failuredetected","false");
                            blinkPublish();
                            modeManager.setModeJustChanged(false); 
                            previousState = LIGHT_OFF;
                            isFirstTime = false;
                        }
                    }
                    
                previousMode = AUTO;
    
                                    
            }
            //When a command Mode OFF is received, the application switches in the OFF mode. The lamp will be always off.
            else if(modeManager.getMode() == OFF)
            {
                    if(previousMode == AUTO || previousMode == ON)
                    {
                        ledcommander.setOff();
                        wait(0.1);
                        sprintf(str1,"%f",0.0); 
                        lightSensor=lightDetector.getLightSensorValue();
                        sprintf(str2,"%f",lightSensor); 
                        client.pub("st.power",str1,"st.lightsensor",str2,"st.lightstatus","off","st.failuredetected","false");
                        blinkPublish();
                        modeManager.setModeJustChanged(false); 
                    }
                    previousState = LIGHT_OFF;
                    previousMode = OFF;
            }
            //When a command Mode ON is received, the application switches in the ON mode. The lamp will be always on.
            else if(modeManager.getMode() == ON)
            {
                    if(previousMode == AUTO || previousMode == OFF)
                    {
                        ledcommander.setOn();
                        wait(0.1);
                        power = powerConsumption.getPower();
                        sprintf(str1,"%f",power); 
                        lightSensor = lightDetector.getLightSensorValue();
                        sprintf(str2,"%f",lightSensor); 
                        client.pub("st.power",str1,"st.lightsensor",str2,"st.lightstatus","on","st.failuredetected","false");
                        blinkPublish();
                        modeManager.setModeJustChanged(false); 
                    }
                    previousState = LIGHT_ON;
                    previousMode = ON;
            }   
        }
        //If no more connected, try to reconnect.
        else
        { 
            pc.printf("Deconnected\n"); 
            //Green Light OFF
            dout1=0;
            client.reconnect();
            previousState=LIGHT_OFF;
            previousMode=AUTO;
        }  
        //Call the background task (i.e. Ping task + Receiv task)
        client.loop();
        
    }//while(1)
}