Пример #1
0
void Aquarium::LoadSetup() {
  // read in all bytes from EEPROM
  for (int i = 0; i < sizeof(SETUP); i++) {
    uint8_t byte = EEPROM.read(i);
    ((uint8_t *)(&setup))[i] = byte;
  }

  // calculate checksum
  uint8_t cs = 0;

  for (int i = 0; i < sizeof(SETUP) - 1; i++) {
    cs |= ((uint8_t *)(&setup))[i];
  }

  // if checksum or magic bytes are not ok, then reset to default values
  if (cs != setup.chksum || setup.magic1 != 0x12 || setup.magic2 != 0x34) {
    setup.magic1 = 0x12;
    setup.hour_on = 9;
    setup.min_on = 0;
    setup.hour_off = 22;
    setup.min_off = 0;
    setup.temp_high = 24;
    setup.temp_low = 21;
    setup.magic2 = 0x34;
    setup.chksum = 0;

    SaveSetup(); // save to EEPROM
  }
}
Пример #2
0
/*************************************************
Function: 	void SetupModule(SetUp *setinfo)
Description: 设置模块
Calls: // 被本函数调用的函数清单
Called By: // 调用本函数的函数清单
Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
Input: // 输入参数说明,包括每个参数的作
// 用、取值说明及参数间关系。
Output: // 对输出参数的说明。
Return: // 函数返回值的说明
Others:  
*************************************************/
void SetupModule(SetUp *setinfo)
{
	INTERFACE_COLOR_3;
	setinfo=LoadSetup();
	Displaysetup(setinfo);
	
    printf("\n\nDo you want to set up?:[ ]\b\b");

	if (YesOrNo()==YES)
	{
		printf("\ntime(1~5):");
		setinfo->speaktime=Select(1,5);
		
		printf("\ndelay(s):");
		setinfo->speakdelay=Select(1,10)*1000;
		
		printf("\nautospeak(y/n):[ ]\b\b");
		setinfo->autospeak=YesOrNo();
		
		printf("\nautoback(y/n):[ ]\b\b");
		setinfo->autoback=YesOrNo();
		
	    printf("\nautoinsearch(y/n):[ ]\b\b");
		setinfo->autoinsearch=YesOrNo();   //lack ()

		system("cls");
		Displaysetup(setinfo);
		printf("\nDo you want to save it?:[ ]\b\b");
		if (YesOrNo()==YES)
		{
			SaveSetup(setinfo);
			return;
		}
		else
		{
			return;
		}
	}
	else
	{
		printf("\nPress any key to back...");
		getche();
		return;
	}
}
Пример #3
0
bool SetupCmd(char *Command) {

    //
    // MO - Mode command
    //
    if( StrEQ(Command,"MO") ) {
        ModeCmd(ParseToken());
        return true;
        }


    //
    // LS - Save setup
    //
    if( StrEQ(Command,"LS") ) {
        char *SetupText = ParseToken();
        int   SetupNum  = atoi(SetupText);

        if( !strlen(SetupText) )
            SetupNum = CurrSetup;

        LoadSetup(SetupNum);

        StartMsg();
        PrintStringP(PSTR("Loaded setup "));
        PrintD(CurrSetup,0);            // == %d
        return true;
        }

    //
    // PS - Print current setup
    //
    if( StrEQ(Command,"PS") ) {
        char *SetupText = ParseToken();
        int   SetupNum  = atoi(SetupText);

        if( !strlen(SetupText) ) PrintSetup(-1      ,&TransducerSet);
        else                     PrintSetup(SetupNum,&EEPROM.Setups[SetupNum].Setup);
        return true;
        }

    //
    // SS - Save current setup
    //
    if( StrEQ(Command,"SS") ) {
        char *SetupText = ParseToken();
        int   SetupNum  = atoi(SetupText);

        if( !strlen(SetupText) )
            SetupNum = CurrSetup;

        SaveSetup(SetupNum);

        StartMsg();
        PrintStringP(PSTR("Saved as setup "));
        PrintD(CurrSetup,SetupNum);            // == %d
        return true;
        }

    return false;
    }
Пример #4
0
void VSPAEROScreen::GuiDeviceCallBack( GuiDevice* device )
{
    assert( m_ScreenMgr );

    Vehicle *veh = VehicleMgr.GetVehicle();

    if( veh )
    {
        //TODO add callback to determine if the setup file text has been edited

        if ( device == &m_SetupButton )
        {
            if( veh->GetVSPAEROCmd().empty() || !FileExist( VSPAEROMgr.m_DegenFileFull ) || VSPAEROMgr.IsSolverRunning() )
            { /* Do nothing. Should not be reachable, button should be deactivated.*/ }
            else
            {
                if ( FileExist( VSPAEROMgr.m_SetupFile ) )
                {
                    switch( fl_choice( "Overwrite any existing setup file?", "Cancel", "Abort", "Overwrite" ) )
                    {
                    case( 0 ):
                    case ( 1 ):
                        break;
                    case( 2 ):
                        // Clear the solver console
                        m_SolverBuffer->text( "" );

                        m_SolverProcess.StartThread( solver_setup_thread_fun, ( void* ) &m_SolverPair );
                        break;
                    }
                }
                else
                {
                    // Clear the solver console
                    m_SolverBuffer->text( "" );

                    m_SolverProcess.StartThread( solver_setup_thread_fun, ( void* ) &m_SolverPair );
                }
            }
        }
        else if ( device == &m_SolverButton )
        {
            if( veh->GetVSPAEROCmd().empty() || !FileExist( VSPAEROMgr.m_DegenFileFull ) || VSPAEROMgr.IsSolverRunning() )
            { /* Do nothing. Should not be reachable, button should be deactivated.*/ }
            else
            {
                // Clear out previous results
                VSPAEROMgr.ClearAllPreviousResults();

                // Clear the solver console
                m_SolverBuffer->text( "" );

                //Show the plot screen
                m_ScreenMgr->m_ShowPlotScreenOnce = true;   //deferred show of plot screen

                VSPAEROPlotScreen * vspapscreen = ( VSPAEROPlotScreen * )m_ScreenMgr->GetScreen( ScreenMgr::VSP_VSPAERO_PLOT_SCREEN );
                if( vspapscreen )
                {
                    vspapscreen->SetDefaultView();
                    vspapscreen->Update();
                }

                m_SolverProcess.StartThread( solver_thread_fun, ( void* ) &m_SolverPair );

            }
        }
        else if ( device == &m_ViewerButton )
        {
            if( veh->GetVIEWERCmd().empty() || !FileExist( VSPAEROMgr.m_DegenFileFull ) || m_ViewerProcess.IsRunning() )
            { /* Do nothing. Should not be reachable, button should be deactivated.*/ }
            else
            {
                vector<string> args;
                args.push_back( VSPAEROMgr.m_ModelNameBase );

                m_ViewerProcess.ForkCmd( veh->GetExePath(), veh->GetVIEWERCmd(), args );

                m_ViewerBuffer->text( "" );
                m_ViewerMonitor.StartThread( monitorfun, ( void* ) &m_ViewerPair );

            }
        }
        else if( device == &m_KillSolverSetupButton )
        {
            VSPAEROMgr.KillSolver();
        }
        else if( device == &m_KillSolverButton )
        {
            VSPAEROMgr.KillSolver();
        }
        else if( device == &m_PlotButton )
        {
            m_ScreenMgr->m_ShowPlotScreenOnce = true;   //deferred show of plot screen
        }
        else if( device == &m_SaveSetup )
        {
            SaveSetup();
        }
        else if( device == &m_ReadSetup )
        {
            ReadSetup();
        }
        else if( device == &m_RefWingChoice )
        {
            int id = m_RefWingChoice.GetVal();
            VSPAEROMgr.m_RefGeomID = m_WingGeomVec[id];
        }
        else if( device == &m_GeomSetChoice )
        {
            VSPAEROMgr.m_GeomSet = m_GeomSetChoice.GetVal();
        }
        else if( device == &m_ComputeGeometryButton )
        {
            VSPAEROMgr.ComputeGeometry();
        }
        else if( device == &m_DegenFileButton )
        {
            veh->setExportFileName( vsp::DEGEN_GEOM_CSV_TYPE, m_ScreenMgr->GetSelectFileScreen()->FileChooser( "Select degen geom CSV output file.", "*.csv" ) );
        }
        else if( device == &m_CompGeomFileButton )
        {
            veh->setExportFileName( vsp::VSPAERO_PANEL_TRI_TYPE, m_ScreenMgr->GetSelectFileScreen()->FileChooser( "Select comp geom TRI output file.", "*.tri" ) );
        }
        else if( device == &m_CGSetChoice )
        {
            VSPAEROMgr.m_CGGeomSet = m_CGSetChoice.GetVal();
        }
        else if( device == &m_MassPropButton )
        {
            string id = veh->MassPropsAndFlatten( m_CGSetChoice.GetVal(), VSPAEROMgr.m_NumMassSlice(), false, false );
            veh->DeleteGeom( id );

            VSPAEROMgr.m_Xcg = veh->m_CG.x();
            VSPAEROMgr.m_Ycg = veh->m_CG.y();
            VSPAEROMgr.m_Zcg = veh->m_CG.z();
        }
        else if( device == &m_ExportResultsToCsvButton )
        {
            string fileName = m_ScreenMgr->GetSelectFileScreen()->FileChooser( "Select CSV File", "*.csv" );
            if ( fileName.size() > 0 )
            {
                int status = VSPAEROMgr.ExportResultsToCSV( fileName );
                if ( status != vsp::VSP_OK )
                {
                    char strBuf[1000];
                    sprintf( strBuf, "File export failed\nFile: %s", fileName.c_str() );
                    fl_alert( strBuf );
                }
            }
        }
    }
    m_ScreenMgr->SetUpdateFlag( true );
}