Пример #1
0
/**
 * Show previous item.
 *
 * @return false if no more items are available
 * @return true an item has been displayed
 */
bool FindResults::displayPrevious()
{
    UMLFinder *finder = 0;
    if (m_listViewFinder.size() > 0)
        finder = &m_listViewFinder.first();
    else if (m_sceneFinder.size() > 0)
        finder = &m_sceneFinder.first();
    else if (m_docFinder.size() > 0)
        finder = &m_docFinder.first();
    if (finder == 0)
        return false;
    UMLFinder::Result result = finder->displayPrevious();
    if (result == UMLFinder::Empty)
        return false;
    else if (result == UMLFinder::End)
        return finder->displayPrevious() == UMLFinder::Found;
    else if (result == UMLFinder::NotFound)
        return displayNext();
    return true;
}
Пример #2
0
void WeatherStation::run()
{
    uint8_t dataType;
    int16_t data;
    boolean ret;

    /*event*/

    if (g_RTCIntFlag)  //it must be at the front of      processRTCAlarm()
    {
        g_RTCIntFlag = false;
        RTCObj.clearINTStatus();
    }

    if ( EVENT_STATE_SET == eventRTCState )
    {
        processRTCAlarm();
        eventRTCState = EVENT_STATE_DOING;
    }

    if ( EVENT_STATE_SET == eventButtonState )
    {
        processButton();
        eventButtonState = EVENT_STATE_DOING;
    }


    if ( SYS_STATE_WAITING == systemState )
    {
        if ( STATE_DOING == getActionState())  //high priority
        {
            systemState = SYS_STATE_ACTION;
        }
        else if ( (uint8_t)((millis()/1000) - startTime) >= overTime )
        {
            systemState = SYS_STATE_GOTOSLEEP;

            DBG_PRINTLN("goto sleep");

            /**to minimize the time to sleep state, so there is not sleep state case **/
            if ( (SW_RUN == digitalRead(PALETTE_PIN_SW)) && (SW_MAKE == switchState) )
            {
#if !_DEBUG
                dettachUSB();
#endif
                switchState = SW_RUN;
            }


            disableBeforeSleep();

            wakeFlag = false;

            sleep();

            enableAfterSleep();
            systemState = SYS_STATE_WAITING;

            DBG_PRINTLN_VAR(systemState,DEC);

        }
        else
        {
            //nothing
        }
    }
    else if ( SYS_STATE_ACTION == systemState )
    {

        /*action*/

        if ( STATE_DOING == a_actionList[ACTION_SAMPLE_DATA].state )
        {
            DBG_PRINTLN("**Sample");
            ret = sensorMgt.run();

            if ( ret )
            {
                a_actionList[ACTION_SAMPLE_DATA].state = STATE_DONE;
            }
            else
            {
                delay(10);
            }
        }

        if ( STATE_DOING == a_actionList[ACTION_SAVE_DATA].state )
        {
            if ( STATE_DONE == a_actionList[ACTION_SAMPLE_DATA].state )
            {
                DBG_PRINTLN("**Save");
                for ( uint8_t i = 0; i < DATA_TYPE_MAXNUM; i++ )
                {
                    if ( false == a_measureData[i].valid )
                    {
                        break;
                    }

                    dataType = a_measureData[i].dataType;
                    data = a_measureData[i].p_sensor->getValue( dataType );

                    dataHouse.putData( data, dataType, currentHour );
                }

                a_actionList[ACTION_SAVE_DATA].state = STATE_DONE;

            }

        }

        if ( STATE_DOING == a_actionList[ACTION_DISPLAY].state )
        {
            if (STATE_DONE == a_actionList[ACTION_SAMPLE_DATA].state)
            {
                displayMgt.state = DISPLAY_STATE_NEXT;
            }

            if ( DISPLAY_STATE_NEXT == displayMgt.state )
            {
                DBG_PRINTLN("**Display");

                displayNext();

                a_actionList[ACTION_DISPLAY].state = STATE_DONE;
            }

        }


        if ( STATE_DONE == getActionState() )
        {
            startTime = millis()/1000;

            if( (END_HOURTIME_ONEDAY == currentHour) && (EVENT_STATE_DOING == eventRTCState) )
            {   //todo:  muti thread
                DBG_PRINTLN_VAR(currentHour,DEC);
                dataHouse.updateDate( currentYear, currentMonth, currentDate );
            }

            eventRTCState = EVENT_STATE_DONE;
            eventButtonState = EVENT_STATE_DONE;

            for ( uint8_t i = 0; i < ACTION_NUMBER; i++ )  //todo
            {
                a_actionList[i].state = STATE_INIT;
            }

            systemState = SYS_STATE_WAITING;

            DBG_PRINTLN_VAR(systemState,DEC);

        }

    }



#if 0
DateTime now = RTCObj.now();
Serial.println(now.minute(), DEC);
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.date(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println(' ');
Serial.println(RTCObj.getTemperature());


#endif

}