Esempio n. 1
0
//***********************************************************************//
//                      State Machine: Output to LED Matrix              //
//***********************************************************************//
int SMTick1 (int state) {


	//Read in Reset button, ATmega1284 inputs are pulled HIGH!
	unsigned char ResetButton = ((~PINA) & 0x08);
	
	//if reset is press, reassigns all variables and reinit states
	if(ResetFlag) {
		state=1;
	}
	
	switch(state) {
		case LED_Multiplex:
		    
			//if the reset button is held down, send the reset signal to slave and reassign all variables
		    if(ResetButton) {ResetEverything(); SendTxData(0xFE);}
			else {ResetFlag=0;}
				
		    SeederCount++; //count up seed so new random will be generated
			ToLEDRegister(LED_Register);
			state = LED_Multiplex;
			break;
			
		default:
			break;
		
	}
	return state;
}
void B9UpdateManager::OnCancelUpdate()
{
    ignoreReplies = true;
    timeoutTimer.stop();
    ResetEverything();
    QMessageBox msgBox;
    msgBox.setText("Update Cancelled");
    msgBox.setIcon(QMessageBox::Warning);
    msgBox.exec();
    qDebug() << "UpdateManager: User Aborted, Update Cancelled";
}
void B9UpdateManager::OnDownloadTimeout()
{
    ignoreReplies = true;
    ResetEverything();
    qDebug() << "UpdateManager: Timed Out";
    if(!silentUpdateChecking){
    QMessageBox msgBox;
    msgBox.setIcon(QMessageBox::Warning);
    msgBox.setText("Unable to update,\nplease check your internet connection.");
    msgBox.exec();
    }
}
void B9UpdateManager::OnRecievedReply(QNetworkReply* reply)
{

    timeoutTimer.stop();
    if(ignoreReplies)
    {
        currentReply->deleteLater();
        currentReply = NULL;
        return;
    }


    if(reply->bytesAvailable() == 0)//nothing downloaded.
    {
        qDebug() << "B9Update Manager, zero bytes downloaded.";
        if(!silentUpdateChecking)
        {
            QMessageBox msgBox;
            msgBox.setText("Online Update Attempt Failed.");
            if(downloadState == "DownloadingFileVersions")
            {
                waitingbar->hide();
                msgBox.setInformativeText("You may use a B9Creator update pack if available. \nBrowse to a local update pack now?");
                msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
                msgBox.setDefaultButton(QMessageBox::Cancel);
                int ret = msgBox.exec();

                if(ret == QMessageBox::Ok)
                {
                    ResetEverything();
                    PromptDoUpdates(true,true);
                    return;
                }//if no - continue to reset below.
            }
            else
            {
                msgBox.setInformativeText("please check your internet connection.");
                msgBox.exec();
            }

        }
        ResetEverything();
        return;
    }

    if(downloadState == "DownloadingFileVersions")
    {
        //remoteEntries - localEntries = updateEntries
        CopyInRemoteEntries();
        CopyInLocalEntries();
        CalculateUpdateEntries();

        //so now we have a big list of local things that need updated...
        if(updateEntries.size() > 0)
        {
            waitingbar->hide();
            QMessageBox msgBox;
            msgBox.setIcon(QMessageBox::Question);
            if(updateEntries.size() == 1)
            {
                msgBox.setText("There is " + QString::number(updateEntries.size()) + " file update available.");
                msgBox.setInformativeText("Do you want to update it? <a href=\"http://b9creator.com/softwaredelta\">View change log</a>");
            }
            else
            {
                msgBox.setText("There are " + QString::number(updateEntries.size()) + " file updates available.");
                msgBox.setInformativeText("Do you want to update them? <a href=\"http://b9creator.com/softwaredelta\">View change log</a>");
            }
            msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
            msgBox.setDefaultButton(QMessageBox::Yes);

            int doUpdates = msgBox.exec();

            currentUpdateIndx = 0;//at this point we know we can iterate through
            //needed updates

            if(doUpdates == QMessageBox::Yes)
            {
                waitingbar->show();
                downloadState = "DownloadingFiles";//next state
                //send a new request
                currentReply->deleteLater();
                currentReply = NULL;

                //request the file in the right directory on the server
                QNetworkRequest request(QUrl(RemoteManifestPath + updateEntries[currentUpdateIndx].OSDir + updateEntries[currentUpdateIndx].fileName));


                StartNewDownload(request);

            }
            else//no
            {
                ResetEverything();
            }
        }
        else
        {
            ResetEverything();
            emit NotifyUpdateFinished();//emit update finished signal
            if(!silentUpdateChecking)
            {
                QMessageBox msgBox;
                msgBox.setText("All files are up to date");
                msgBox.setIcon(QMessageBox::Information);
                msgBox.exec();
            }
        }

    }
    else if(downloadState == "DownloadingFiles")
    {
        //lets put the file in the temp directory
        if(!OnDownloadDone())
        {
            //bail
            ResetEverything();
            return;
        }
        if(currentUpdateIndx < updateEntries.size() - 1)
        {
            currentUpdateIndx++;
            currentReply->deleteLater();
            currentReply = NULL;


            QNetworkRequest request(QUrl(RemoteManifestPath + updateEntries[currentUpdateIndx].OSDir + updateEntries[currentUpdateIndx].fileName));

            StartNewDownload(request);
        }
        else
        {
            if(!CopyFromTemp())
            {
                //bail
                qDebug() << "UpdateManager: Unable To Copy Files From Temp Directory";
                QMessageBox msgBox;
                msgBox.setText("Unable to update,\nUnable To Copy Files From Temp Directory.");
                msgBox.setIcon(QMessageBox::Warning);
                msgBox.exec();
                ResetEverything();
                return;
            }

            if(!UpdateLocalFileVersionList())
            {
                qDebug() << "UpdateManager: Unable To overwrite local FileVersions.txt";
                QMessageBox msgBox;
                msgBox.setText("Unable to update,\nUnable To overwrite local FileVersions.txt.");
                msgBox.setIcon(QMessageBox::Warning);
                msgBox.exec();
                ResetEverything();
                return;
            }

            waitingbar->hide();
            QMessageBox msgBox;
            msgBox.setIcon(QMessageBox::Information);
            msgBox.setText("All files up to date");
            msgBox.setInformativeText("Please Re-Launch B9Creator.");
            msgBox.exec();

            ResetEverything();

            //Safely Exit the Program.....
            QCoreApplication::exit();
        }
    }
}
Esempio n. 5
0
void Init()
{
    ResetEverything();
}