Esempio n. 1
0
bool onOffDelayUpdate(OnOffDelay* me, bool Trg) {
	switch (me->state) {
		case S0:
			if (Trg) {
				me->state = S1;
				timerStart(me->timer, me->TH);
			}
			break;
		case S1:
			if (Trg) {
				if (timerExpired(me->timer)) {
					me->state = S2;
				}
			} else {
				me->state = S0;
			}
			break;
		case S2:
			if (!Trg) {
				me->state = S3;
				timerStart(me->timer, me->TL);
			}
			break;
		case S3:
			if (!Trg) {
				if (timerExpired(me->timer)) {
					me->state = S0;
				}
			} else {
				me->state = S0;
			}
			break;
	}
	return onOffDelayOutput(me);
}
Esempio n. 2
0
static void issueDelayReqTimerExpired(PtpClock *ptpClock)
{
    switch (ptpClock->portDS.delayMechanism)
    {
    case E2E:

        if(ptpClock->portDS.portState != PTP_SLAVE)
        {
            break;
        }
        
        if (timerExpired(DELAYREQ_INTERVAL_TIMER, ptpClock->itimer))
        {
            timerStart(DELAYREQ_INTERVAL_TIMER, getRand(pow2ms(ptpClock->portDS.logMinDelayReqInterval + 1)), ptpClock->itimer);
            DBGV("event DELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
            issueDelayReq(ptpClock);
        }

        break;

    case P2P:

        if (timerExpired(PDELAYREQ_INTERVAL_TIMER, ptpClock->itimer))
        {
            timerStart(PDELAYREQ_INTERVAL_TIMER, getRand(pow2ms(ptpClock->portDS.logMinPdelayReqInterval + 1)), ptpClock->itimer);
            DBGV("event PDELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
            issuePDelayReq(ptpClock);
        }
        break;
    default:
        break;
    }
}
//print new line
void PrintLine()
{
	setTimerIn4ms(3);
	while(!timerExpired());
	UART_Transmit(13);
	
	setTimerIn4ms(3);
	while(!timerExpired());
	UART_Transmit(10);
	
}
Esempio n. 4
0
bool offDelayUpdate(OffDelay* me, bool Trg, bool R) {
	if (R) {
		me->state = S0;
	} else {
		switch (me->state) {
			case S0:
				if (Trg) {
					me->state = S1;
				}
				break;
			case S1:
				if (!Trg) {
					timerStart(me->timer, me->T);
					me->state = S2;
				}
				break;
			case S2:
				if (Trg) {
					me->state = S1;
				} else {
					if (timerExpired(me->timer)) {
						me->state = S0;
					}
				}
				break;
		}
	}
	return offDelayOutput(me);
}
//Need to add the hangs
unsigned char st_beforePowerOff(void){

     //State Transition is occurring 
    if (timerCountDownActivated == POWEROFF_ACK_WAITING) {

        if (isPowerLED_ON() == OFF)
        {
            timerCountDownActivated = NOT_ACTIVATED;
            setTimerIn100ms(ZERO);
            setActivityDetected(FALSE);
            powerSupplyON(OFF);
            return POWEROFF;
        }
        else if (timerExpired())
        {
            timerCountDownActivated = NOT_ACTIVATED;
        }
        else
        {
            return BEFOREPOWEROFF;
        }
    }

    //Needs to send every five seconds
    sendPowerOffRequest();
    timerCountDownActivated = POWEROFF_ACK_WAITING;
    setTimerIn100ms(POWEROFF_WAIT);

    return BEFOREPOWEROFF;
}
unsigned char st_powerOff(void){

    //State Transition is occuring 
    if (timerCountDownActivated == POWER_BUTTON_ON) {

        if (timerExpired())
        {
            powerButtonPressed(RELEASED);
            if (isPowerLED_ON()) {

                timerCountDownActivated = NOT_ACTIVATED;
                setTimerIn100ms(ZERO);
                setHeartBeat(OFF);
                return BOOTING;
            }
        }

        //May hangs here
        return POWEROFF;        
    }

    //Press the button for POWER_BUTTON_PRESSED time and switch state
    if (activityDetected()) {
		powerSupplyON(ON);		
        powerButtonPressed(PRESSED);
        timerCountDownActivated = POWER_BUTTON_ON;
        setTimerIn100ms(POWER_BUTTON_PRESSED);
    }

    return POWEROFF;
}
unsigned char st_suspend(void){

    //State Transition is occuring 
    if (timerCountDownActivated == POWER_BUTTON_OFF) {

        if (timerExpired())
        {
            powerButtonPressed(RELEASED);
            timerCountDownActivated = NOT_ACTIVATED;

            if (getActivityInactiveTimeInS() > POWEROFF_THRESOLD_SEC) {

                return BEFOREPOWEROFF;
            }
            else
            {
                setHeartBeat(OFF);
                return BOOTING;
            }
        }
        else{

            return SUSPEND;
        }
    }

    //Activty detected OR NON-Activity for too long
    if (activityDetected() || getActivityInactiveTimeInS() > POWEROFF_THRESOLD_SEC) {
        powerButtonPressed(PRESSED);
        timerCountDownActivated = POWER_BUTTON_OFF;
        setTimerIn100ms(POWER_BUTTON_PRESSED);
    }

    return SUSPEND;
}
Esempio n. 8
0
bool debounceUpdate(Debounce* me, bool i) {

	switch (me->state) {
		case S0:		// init
			timerInit(me->timer);
			timerSingleShot(me->timer);
			me->state = S1;
			break;

		case S1:											// steady state
			if (i) {										// rising edge of input
				timerStart(me->timer, DEBOUNCE_TIME);
				me->state = S2;
			}
			break;

		case S2:											// input is high
			if (i) {
				if (timerExpired(me->timer)) {				// if it is high for the debounce time
					me->state = S3;							// it is considered high for the observer (output)
				}
			} else {
				me->state = S1;
			}
			break;

		case S3:											// input is steady high
			if (!i) {										// if it goes low next state
				timerStart(me->timer, DEBOUNCE_TIME);
				me->state = S4;
			}
			break;

		case S4:
			if (!i) {
				if (timerExpired(me->timer)) {
					me->state = S1;
				}
			} else {
				me->state = S3;
			}
			break;
	}
	return debounceOutput(me);
}
Esempio n. 9
0
/**
 * @brief ClientInfo::ClientInfo default constructor for ClientInfo.
 * @param parent the parent object.
 * @param clientAddress the client IP address.
 */
ClientInfo::ClientInfo(QObject *parent, QString clientAddress) : QObject(parent)
{
    qDebug() << "Client Created";
    address = clientAddress;

    //start the timeout timer
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(timerExpired()));
    timer->start(1000);
}
//print text and new line
void PrintLn(char Text[40])
{
	unsigned char Len, i, T;
	Len = Length(Text);
	for (i=0; i<Len; i++)
	{
		T = Text[i];
		setTimerIn4ms(3);
		while(!timerExpired());
		UART_Transmit(T);
		
	}
	
	setTimerIn4ms(3);
	while(!timerExpired());
	UART_Transmit(13);
	
	setTimerIn4ms(3);
	while(!timerExpired());
	UART_Transmit(10);
	
}
unsigned char st_run(void){

      if (timerCountDownActivated == POWER_SUPPLY) {

         if (isPowerLED_ON()== OFF) {
				
                timerCountDownActivated = NOT_ACTIVATED;
                setTracking(OFF);
                setHeartBeat(OFF);
                setActivityDetected(FALSE);
                return POWEROFF;
         }			
        
		return RUN;        
      } 
      else if (timerCountDownActivated == SUSPEND_ACK_WAITING) {

          if (timerExpired()) {
              //Computer might hangs
              //Heartbeat = TRUE but never ACK SUSPEND
              timerCountDownActivated = NOT_ACTIVATED;
              
		 }else if (getSuspendAcknowledge()) {

              timerCountDownActivated = NOT_ACTIVATED;
              setTimerIn100ms(ZERO);
              setTracking(OFF);
              setHeartBeat(OFF);
              setActivityDetected(FALSE);
              return SUSPEND;
          }
		  
		  return RUN;
      }

    
    if (getHeartBeatInactiveTimeInS() > HEARTBEAT_THRESOLD_SEC) {
        //Ubuntu hangs -> Turn it off
        powerSupplyON(OFF);
		timerCountDownActivated = POWER_SUPPLY;
    }else if (getTracking()==OFF) {
        //Ubuntu not tracking -> Suspend
        sendSuspendRequest();
        timerCountDownActivated = SUSPEND_ACK_WAITING;
        setTimerIn100ms(SUSPENSION_WAIT);
    }

    return RUN;
}
Esempio n. 12
0
QueueScheduler::QueueScheduler()
{
	currentState    = NOT_ENABLED;
	isRatePeriod    = false;
	schedDb         = 0;
	currentSchedule = 0;
	restrictedSpeed = -1; // not restricted
	nextBoundary.setSingleShot(true);
	connect(&nextBoundary, SIGNAL(timeout()), this, SLOT(timerExpired()));

	currentTime = QDateTime::currentDateTime();
	currentMonday = currentTime.addDays((currentTime.date().dayOfWeek() - 1) * -1);
	QTime mondayTime(0,0);
	currentMonday.setTime(mondayTime);
	// qDebug() << "Monday is " << currentMonday.toString("ddd dd MM yyyy hh:mm:ss");
}
Esempio n. 13
0
/*
this function checks if wr timer has expired for a current WR state
*/
void wrTimerExpired(UInteger8 currentState, RunTimeOpts *rtOpts, PtpPortDS *ptpPortDS, Enumeration8 wrMode)
{
  UInteger8 wrStateRetry;
  /*WRS_IDLE state does not expire */
  if(currentState == WRS_IDLE)
    return;
  
  if(timerExpired(&ptpPortDS->wrTimers[currentState]))
  {

      if(currentState == WRS_CALIBRATION && ptpPortDS->calRetry > 0)
	wrStateRetry = ptpPortDS->calRetry;
      else if(currentState == WRS_RESP_CALIB_REQ && ptpPortDS->otherNodeCalRetry > 0)
	wrStateRetry = ptpPortDS->otherNodeCalRetry;
      else
	wrStateRetry = ptpPortDS->wrStateRetry;
	
      if (ptpPortDS->currentWRstateCnt < wrStateRetry)
      {
	PTPD_TRACE(TRACE_WR_PROTO, ptpPortDS, "WR_Slave_TIMEOUT: state[= %d] timeout, repeat state\n", currentState);
	toWRState(currentState, rtOpts, ptpPortDS);
      }
      else
      {
//	PTPD_TRACE(TRACE_WR_PROTO, ptpPortDS,"WR_Slave_TIMEOUT: state[=%d] timeout, repeated %d times, going to Standard PTP\n", \
	currentState,ptpPortDS->currentWRstateCnt );
	
	ptpPortDS->wrModeON = FALSE;
        toWRState(WRS_IDLE, rtOpts, ptpPortDS);

	if(rtOpts->disableFallbackIfWRFails)
	{
		PTPD_TRACE(TRACE_WR_PROTO, ptpPortDS,"WR_Slave_TIMEOUT: state[=%d] timeout, disabling port (standard PTP fallback OFF).\n", currentState);

	  toState(PTP_DISABLED, rtOpts, ptpPortDS);
	} else if(wrMode == WR_MASTER)
	  toState(PTP_MASTER, rtOpts, ptpPortDS);
	else toState(PTP_SLAVE, rtOpts, ptpPortDS);
	/*
	 * RE-INITIALIZATION OF White Rabbit Data Sets
	 * (chapter (Re-)Initialization of wrspec
	 */	
	initWrData(ptpPortDS, INIT); //INIT mode because we don't need to remember WR port mode and port role
      }

  }
}
Esempio n. 14
0
//------------------------------------------------------------------------------
void appService(Application *app)
{
    if(asicReportValid())
    {
        uint32_t nonce = asicGetNonce();
        uint32_t nonce_reversed = 0;

        timerStop(&app->work_timer);

        asicStop();
        asicResetSpi();

        app->state.state = STATE_RESET;

        SPCR |= _BV(SPIE);

        nonce_reversed |= nonce & 0xFF;
        nonce >>= 8;
        nonce_reversed <<= 8;
        nonce_reversed |= nonce & 0xFF;
        nonce >>= 8;
        nonce_reversed <<= 8;
        nonce_reversed |= nonce & 0xFF;
        nonce >>= 8;
        nonce_reversed <<= 8;
        nonce_reversed |= nonce & 0xFF;

        nonce_reversed = nonce_reversed - 0xC0;
        app->state.nonce = nonce_reversed;
        app->state.nonce_valid = 1;

        sendCmdReply(app, 'S', (uint8_t *)&app->state, sizeof(State));
    }

    if(timerExpired(&app->work_timer))
    {
        asicStop();
        asicResetSpi();
        app->state.state = STATE_RESET;

        app->state.nonce = 0;
        app->state.nonce_valid = 0;
        sendCmdReply(app, 'S', (uint8_t *)&app->state, sizeof(State));
    }
}
Esempio n. 15
0
/* handle actions and events for 'port_state' */
void 
doState(RunTimeOpts *rtOpts, PtpClock *ptpClock)
{
	UInteger8 state;
	
	ptpClock->message_activity = FALSE;
	
	/* Process record_update (BMC algorithm) before everything else */
	switch (ptpClock->portState)
	{
	case PTP_LISTENING:
	case PTP_PASSIVE:
	case PTP_SLAVE:
	case PTP_MASTER:
		/*State decision Event*/

		/* If we received a valid Announce message, and can use it (record_update), then run the BMC algorithm */
		if(ptpClock->record_update)
		{
			DBG2("event STATE_DECISION_EVENT\n");
			ptpClock->record_update = FALSE;
			state = bmc(ptpClock->foreign, rtOpts, ptpClock);
			if(state != ptpClock->portState)
				toState(state, rtOpts, ptpClock);
		}
		break;
		
	default:
		break;
	}
	
	
	switch (ptpClock->portState)
	{
	case PTP_FAULTY:
		/* imaginary troubleshooting */
		DBG("event FAULT_CLEARED\n");
		toState(PTP_INITIALIZING, rtOpts, ptpClock);
		return;
		
	case PTP_LISTENING:
	case PTP_UNCALIBRATED:
	case PTP_SLAVE:
	// passive mode behaves like the SLAVE state, in order to wait for the announce timeout of the current active master
	case PTP_PASSIVE:
		handle(rtOpts, ptpClock);
		
		/*
		 * handle SLAVE timers:
		 *   - No Announce message was received
		 *   - Time to send new delayReq  (miss of delayResp is not monitored explicitelly)
		 */
		if (timerExpired(ANNOUNCE_RECEIPT_TIMER, ptpClock->itimer))
		{
			DBG("event ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES\n");
			ptpClock->number_foreign_records = 0;
			ptpClock->foreign_record_i = 0;

			if(!ptpClock->slaveOnly && 
			   ptpClock->clockQuality.clockClass != 255) {
				m1(rtOpts,ptpClock);
				toState(PTP_MASTER, rtOpts, ptpClock);

			} else {
				/*
				 *  Force a reset when getting a timeout in state listening, that will lead to an IGMP reset
				 *  previously this was not the case when we were already in LISTENING mode
				 */
				toState(PTP_LISTENING, rtOpts, ptpClock);
			}
		}
		
		if (timerExpired(OPERATOR_MESSAGES_TIMER, ptpClock->itimer)) {
			reset_operator_messages(rtOpts, ptpClock);
		}


		if (ptpClock->delayMechanism == E2E) {
			if(timerExpired(DELAYREQ_INTERVAL_TIMER,
					ptpClock->itimer)) {
				DBG2("event DELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
				issueDelayReq(rtOpts,ptpClock);
			}
		} else if (ptpClock->delayMechanism == P2P) {
			if (timerExpired(PDELAYREQ_INTERVAL_TIMER,
					ptpClock->itimer)) {
				DBGV("event PDELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
				issuePDelayReq(rtOpts,ptpClock);
			}

			/* FIXME: Path delay should also rearm its timer with the value received from the Master */
		}
		break;

	case PTP_MASTER:
		/*
		 * handle SLAVE timers:
		 *   - Time to send new Sync
		 *   - Time to send new Announce
		 *   - Time to send new PathDelay
		 *      (DelayResp has no timer - as these are sent and retransmitted by the slaves)
		 */
	
		if (timerExpired(SYNC_INTERVAL_TIMER, ptpClock->itimer)) {
			DBGV("event SYNC_INTERVAL_TIMEOUT_EXPIRES\n");
			issueSync(rtOpts, ptpClock);
		}
		
		if (timerExpired(ANNOUNCE_INTERVAL_TIMER, ptpClock->itimer)) {
			DBGV("event ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES\n");
			issueAnnounce(rtOpts, ptpClock);
		}
		
		if (ptpClock->delayMechanism == P2P) {
			if (timerExpired(PDELAYREQ_INTERVAL_TIMER,
					ptpClock->itimer)) {
				DBGV("event PDELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
				issuePDelayReq(rtOpts,ptpClock);
			}
		}
		
		// TODO: why is handle() below expiretimer, while in slave is the opposite
		handle(rtOpts, ptpClock);
		
		if (ptpClock->slaveOnly || ptpClock->clockQuality.clockClass == 255)
			toState(PTP_LISTENING, rtOpts, ptpClock);
		
		break;

	case PTP_DISABLED:
		handle(rtOpts, ptpClock);
		break;
		
	default:
		DBG("(doState) do unrecognized state\n");
		break;
	}
}
Esempio n. 16
0
/* handle actions and events for 'port_state' */
void doState(PtpClock *ptpClock)
{
    ptpClock->messageActivity = FALSE;

    switch (ptpClock->portDS.portState)
    {
    case PTP_LISTENING:
    case PTP_UNCALIBRATED:
    case PTP_SLAVE:
    case PTP_PRE_MASTER:
    case PTP_MASTER:
    case PTP_PASSIVE:
        /*State decision Event*/

        if (getFlag(ptpClock->events, STATE_DECISION_EVENT))
        {
            DBGV("event STATE_DECISION_EVENT\n");
            clearFlag(ptpClock->events, STATE_DECISION_EVENT);
            ptpClock->recommendedState = bmc(ptpClock);

            switch (ptpClock->recommendedState)
            {
            case PTP_MASTER:
            case PTP_PASSIVE:

                if (ptpClock->defaultDS.slaveOnly || ptpClock->defaultDS.clockQuality.clockClass == 255)
                {
                    ptpClock->recommendedState = PTP_LISTENING;
                }

                break;

            default:
                break;
            }
        }

        break;

    default:
        break;
    }

    switch (ptpClock->recommendedState)
    {
    case PTP_MASTER:

        switch (ptpClock->portDS.portState)
        {
        case PTP_PRE_MASTER:

            if (timerExpired(QUALIFICATION_TIMEOUT, ptpClock->itimer))
            {
                toState(ptpClock, PTP_MASTER);
            }

            break;

        case PTP_MASTER:
            break;
        default:
            toState(ptpClock, PTP_PRE_MASTER);
            break;
        }

        break;

    case PTP_PASSIVE:

        if (ptpClock->portDS.portState != ptpClock->recommendedState)
        {
            toState(ptpClock, PTP_PASSIVE);
        }

        break;

    case PTP_SLAVE:

        switch (ptpClock->portDS.portState)
        {
        case PTP_UNCALIBRATED:

            if (getFlag(ptpClock->events, MASTER_CLOCK_SELECTED))
            {
                DBG("event MASTER_CLOCK_SELECTED\n");
                clearFlag(ptpClock->events, MASTER_CLOCK_SELECTED);
                toState(ptpClock, PTP_SLAVE);
            }

            if (getFlag(ptpClock->events, MASTER_CLOCK_CHANGED))
            {
                DBG("event MASTER_CLOCK_CHANGED\n");
                clearFlag(ptpClock->events, MASTER_CLOCK_CHANGED);
            }

            break;

        case PTP_SLAVE:

            if (getFlag(ptpClock->events, SYNCHRONIZATION_FAULT))
            {
                DBG("event SYNCHRONIZATION_FAULT\n");
                clearFlag(ptpClock->events, SYNCHRONIZATION_FAULT);
                toState(ptpClock, PTP_UNCALIBRATED);
            }

            if (getFlag(ptpClock->events, MASTER_CLOCK_CHANGED))
            {
                DBG("event MASTER_CLOCK_CHANGED\n");
                clearFlag(ptpClock->events, MASTER_CLOCK_CHANGED);
                toState(ptpClock, PTP_UNCALIBRATED);
            }

            break;

        default:
            toState(ptpClock, PTP_UNCALIBRATED);
            break;
        }

        break;

    case PTP_LISTENING:

        if (ptpClock->portDS.portState != ptpClock->recommendedState)
        {
            toState(ptpClock, PTP_LISTENING);
        }

        break;

    case PTP_INITIALIZING:
        break;
    default:
        DBG("doState: unrecognized recommended state %d\n", ptpClock->recommendedState);
        break;
    }

    switch (ptpClock->portDS.portState)
    {
    case PTP_INITIALIZING:

        if (TRUE == doInit(ptpClock))
        {
            toState(ptpClock, PTP_LISTENING);
        }
        else
        {
            toState(ptpClock, PTP_FAULTY);
        }

        break;

    case PTP_FAULTY:
        /* imaginary troubleshooting */

        DBG("event FAULT_CLEARED\n");
        toState(ptpClock, PTP_INITIALIZING);
        return;

    case PTP_DISABLED:
        handle(ptpClock);
        break;

    case PTP_LISTENING:
    case PTP_UNCALIBRATED:
    case PTP_SLAVE:
    case PTP_PASSIVE:

        if (timerExpired(ANNOUNCE_RECEIPT_TIMER, ptpClock->itimer))
        {
            DBGV("event ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES\n");
            ptpClock->foreignMasterDS.count = 0;
            ptpClock->foreignMasterDS.i = 0;

            if (!(ptpClock->defaultDS.slaveOnly || ptpClock->defaultDS.clockQuality.clockClass == 255))
            {
                m1(ptpClock);
                ptpClock->recommendedState = PTP_MASTER;
                toState(ptpClock, PTP_MASTER);
            }
            else if (ptpClock->portDS.portState != PTP_LISTENING)
            {
                toState(ptpClock, PTP_LISTENING);
            }

            break;
        }

        handle(ptpClock);

        break;

    case PTP_MASTER:

        if (timerExpired(SYNC_INTERVAL_TIMER, ptpClock->itimer))
        {
            DBGV("event SYNC_INTERVAL_TIMEOUT_EXPIRES\n");
            issueSync(ptpClock);
        }

        if (timerExpired(ANNOUNCE_INTERVAL_TIMER, ptpClock->itimer))
        {
            DBGV("event ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES\n");
            issueAnnounce(ptpClock);
        }

        handle(ptpClock);

        issueDelayReqTimerExpired(ptpClock);

        break;
    default:
        DBG("doState: do unrecognized state %d\n", ptpClock->portDS.portState);
        break;
    }
}
Esempio n. 17
0
SoundGenerator::SoundGenerator(QObject *parent)
    : QObject(parent)
    , m_clockCount(0)
    , m_function(Inactive)
    , m_device(0)
    , m_timer(new QTimer(this))
{
    m_channelA.fineTune = 0;
    m_channelA.coarseTune = 0;
    m_channelA.amplitudeLevel = 0;
    m_channelA.mixValue = 0;
    m_channelA.toneOutput = 0;
    m_channelA.counter = 0;
    m_channelB.fineTune = 0;
    m_channelB.coarseTune = 0;
    m_channelB.amplitudeLevel = 0;
    m_channelB.mixValue = 0;
    m_channelB.toneOutput = 0;
    m_channelB.counter = 0;
    m_channelC.fineTune = 0;
    m_channelC.coarseTune = 0;
    m_channelC.amplitudeLevel = 0;
    m_channelC.mixValue = 0;
    m_channelC.toneOutput = 0;
    m_channelC.counter = 0;
    m_envelope.fineTune = 0;
    m_envelope.coarseTune = 0;
    m_envelope.counter = 0;
    m_envelope.shapePosition = 0;
    m_envelope.shouldHold = true;
    m_mixerA.isChannelNoiseOn = false;
    m_mixerA.isChannelToneOn = false;
    m_mixerB.isChannelNoiseOn = false;
    m_mixerB.isChannelToneOn = false;
    m_mixerC.isChannelNoiseOn = false;
    m_mixerC.isChannelToneOn = false;
    m_noise.period = 0;
    m_noise.rng = 1;
    m_noise.noiseOutput = 0xff;
    m_noise.counter = 0;

    QList<byte_t> shape;
    shape << 15 << 14 << 13 << 12 << 11 << 10 << 9 << 8 << 7 << 6 << 5 << 4 << 3 << 2 << 1 << 0;
    ENVELOPE_SHAPES.append(shape);
    ENVELOPE_SHAPES.append(shape);
    ENVELOPE_SHAPES.append(shape);
    ENVELOPE_SHAPES.append(shape);
    shape.clear();
    shape << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 0;
    ENVELOPE_SHAPES.append(shape);
    ENVELOPE_SHAPES.append(shape);
    ENVELOPE_SHAPES.append(shape);
    ENVELOPE_SHAPES.append(shape);
    shape.clear();
    shape << 15 << 14 << 13 << 12 << 11 << 10 << 9 << 8 << 7 << 6 << 5 << 4 << 3 << 2 << 1 << 0;
    ENVELOPE_SHAPES.append(shape);
    ENVELOPE_SHAPES.append(shape);
    shape.clear();
    shape << 15 << 14 << 13 << 12 << 11 << 10 << 9 << 8 << 7 << 6 << 5 << 4 << 3 << 2 << 1 << 0
          << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15;
    ENVELOPE_SHAPES.append(shape);
    shape.clear();
    shape << 15 << 14 << 13 << 12 << 11 << 10 << 9 << 8 << 7 << 6 << 5 << 4 << 3 << 2 << 1 << 0 << 15;
    ENVELOPE_SHAPES.append(shape);
    shape.clear();
    shape << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15;
    ENVELOPE_SHAPES.append(shape);
    ENVELOPE_SHAPES.append(shape);
    shape.clear();
    shape << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15
          << 15 << 14 << 13 << 12 << 11 << 10 << 9 << 8 << 7 << 6 << 5 << 4 << 3 << 2 << 1 << 0;
    ENVELOPE_SHAPES.append(shape);
    shape.clear();
    shape << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 0;
    ENVELOPE_SHAPES.append(shape);

    m_envelope.currentShape = ENVELOPE_SHAPES[0];

    m_audioBuffer.resize(882000);
    m_bufferPos = 0;
    m_bufferPtr = reinterpret_cast<qint8 *>(m_audioBuffer.data());

    connect(m_timer, SIGNAL(timeout()), SLOT(timerExpired()));
    m_timer->start(20);
}
Esempio n. 18
0
void EventApplet::init()
{
    KConfigGroup cg = config();

    disabledResources = cg.readEntry("DisabledResources", QStringList());

    QString normalEventFormat = cg.readEntry("NormalEventFormat", QString("%{startDate} %{startTime} %{summary}"));
    QString todoFormat = cg.readEntry("TodoFormat", QString("%{dueDate} %{summary}"));
    QString noDueDateFormat = cg.readEntry("NoDueDateFormat", QString("%{summary}"));
    int dtFormat = cg.readEntry("DateFormat", ShortDateFormat);
    QString dtString = cg.readEntry("CustomDateFormat", QString("dd.MM."));
    m_period = cg.readEntry("Period", 365);

    m_urgency = cg.readEntry("UrgencyTime", 15);
    m_birthdayUrgency = cg.readEntry("BirthdayUrgencyTime", 14);

    m_urgentBg = QColor(cg.readEntry("UrgentColor", QString("#FF0000")));
    m_urgentBg.setAlphaF(cg.readEntry("UrgentOpacity", 10)/100.0);
    m_colors.insert(urgentColorPos, m_urgentBg);
    m_passedFg = QColor(cg.readEntry("PassedColor", QString("#C3C3C3")));
    m_colors.insert(passedColorPos, m_passedFg);
    
    m_todoBg = QColor(cg.readEntry("TodoColor", QString("#FFD235")));
    m_todoBg.setAlphaF(cg.readEntry("TodoOpacity", 10)/100.0);
    m_colors.insert(todoColorPos, m_todoBg);

    m_showFinishedTodos = cg.readEntry("ShowFinishedTodos", FALSE);
    
    m_finishedTodoBg = QColor(cg.readEntry("FinishedTodoColor", QString("#6FACE0")));
    m_finishedTodoBg.setAlphaF(cg.readEntry("FinishedTodoOpacity", 10)/100.0);
    m_colors.insert(finishedTodoColorPos, m_finishedTodoBg);

    int opacity = cg.readEntry("KOOpacity", 10);
    setupCategoryColors(opacity);

    QString koConfigPath = KStandardDirs::locateLocal("config", "korganizerrc");
    m_categoryColorWatch = new KDirWatch(this);
    m_categoryColorWatch->addFile(koConfigPath);
    connect(m_categoryColorWatch, SIGNAL(created(const QString &)), this, SLOT(koConfigChanged()));
    connect(m_categoryColorWatch, SIGNAL(dirty(const QString &)), this, SLOT(koConfigChanged()));

    connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(plasmaThemeChanged()));
    
    QStringList keys, values;
    keys << i18n("Birthday") << i18n("Holiday");
    values << QString("%{startDate} %{yearsSince}. %{summary}") << QString("%{startDate} %{summary} to %{endDate}");
    keys = cg.readEntry("CategoryFormatsKeys", keys);
    values = cg.readEntry("CategoryFormatsValues", values);

    for (int i = 0; i < keys.size(); ++i) {
        m_categoryFormat.insert(keys.at(i), values.at(i));
    }

    QStringList headerList;
    headerList << i18n("Today") << i18n("Events of today") << QString::number(0);
    headerList << i18n("Tomorrow") << i18n("Events for tomorrow") << QString::number(1);
    headerList << i18n("Week") << i18n("Events of the next week") << QString::number(2);
    headerList << i18n("Next 4 weeks") << i18n("Events for the next 4 weeks") << QString::number(8);
    headerList << i18n("Later") << i18n("Events later than 4 weeks") << QString::number(29);
    m_headerItemsList = cg.readEntry("HeaderItems", headerList);

    m_delegate = new EventItemDelegate(this, normalEventFormat, todoFormat, noDueDateFormat, dtFormat, dtString);
    m_delegate->setCategoryFormats(m_categoryFormat);

    graphicsWidget();

    Plasma::ToolTipManager::self()->registerWidget(this);
    createToolTip();

    lastCheckTime = QDateTime::currentDateTime();
    m_timer = new QTimer();
    connect(m_timer, SIGNAL(timeout()), this, SLOT(timerExpired()));
    QTimer::singleShot(0, this, SLOT(setupModel()));
}
Esempio n. 19
0
/* handle actions and events for 'port_state' */
void doState(PtpClock *ptpClock)
{
  UInteger8 state;
  
  ptpClock->message_activity = FALSE;
  
  switch(ptpClock->port_state)
  {
  case PTP_LISTENING:
  case PTP_PASSIVE:
  case PTP_SLAVE:
  case PTP_MASTER:
    if(ptpClock->record_update)
    {
      ptpClock->record_update = FALSE;
      state = bmc(ptpClock->foreign, ptpClock);
      if(state != ptpClock->port_state)
        toState(state, ptpClock);
    }
    break;
    
  default:
    break;
  }
  
  switch(ptpClock->port_state)
  {
  case PTP_FAULTY:
    /* imaginary troubleshooting */
    
    DBG("event FAULT_CLEARED\n");
    toState(PTP_INITIALIZING, ptpClock);
    return;
    
  case PTP_LISTENING:
  case PTP_PASSIVE:
  case PTP_UNCALIBRATED:
  case PTP_SLAVE:
    handle(ptpClock);
    
    if(timerExpired(SYNC_RECEIPT_TIMER, ptpClock->itimer))
    {
      DBG("event SYNC_RECEIPT_TIMEOUT_EXPIRES\n");
      ptpClock->number_foreign_records = 0;
      ptpClock->foreign_record_i = 0;
      if(!ptpClock->runTimeOpts.slaveOnly && ptpClock->clock_stratum != 255)
      {
        m1(ptpClock);
        toState(PTP_MASTER, ptpClock);
      }
      else if(ptpClock->port_state != PTP_LISTENING)
        toState(PTP_LISTENING, ptpClock);
    }
    
    break;
    
  case PTP_MASTER:
    if(timerExpired(SYNC_INTERVAL_TIMER, ptpClock->itimer))
    {
      DBGV("event SYNC_INTERVAL_TIMEOUT_EXPIRES\n");
      issueSync(ptpClock);
    }
    
    handle(ptpClock);
    
    if(ptpClock->runTimeOpts.slaveOnly || ptpClock->clock_stratum == 255)
      toState(PTP_LISTENING, ptpClock);
    
    break;
    
  case PTP_DISABLED:
    handle(ptpClock);
    break;
    
  default:
    DBG("do unrecognized state\n");
    break;
  }
}
Esempio n. 20
0
/**
 * switchCounterCount - count the number of subsequent switch toggles
 *
 * @param me
 * @param i - value of the input signal
 * @return value of the counter. It can be retrieved calling
 */
unsigned char switchCounterCount(SwitchCounter* me, bool i) {
	i = debounceUpdate(me->ireader, i);

	if (me->button==0) {						// bistable switch
		switch (me->state) {
			case 0:											// steady state: input=0
				if (i) {									// if input goes high
					me->cntr++;									// counter is incremented
					timerStart(me->timer, me->timeout);			// timer is retriggered
					me->state++;
				} else if (timerExpired(me->timer)) {		// if input stay low for the time
					me->cntr = 0;								// counter goes to 0
				}
				break;

			case 1:
				if (i) {									// if input stay high
					if (timerExpired(me->timer)) {				// after the timeout
						me->cntr = 0;							// counter goes to 0
						me->state++;
					}
				} else {									// if input goes low
					timerStart(me->timer, 500);				// for 1 s
					me->state--;
				}
				break;

			case 2:
				if (!i) {									// if input goes low
					me->state = 0;
				}
				break;
		}
	} else {									// monostable button
		switch (me->state) {
			case 0:											// steady state: input=0
ZERO:
				if (i) {									// on button press
					me->cntr++;									// counter is incremented
					me->state++;								// go next state
				} else if (timerExpired(me->timer)) {		// if input stay low for the timeout
					me->cntr = 0;								// counter goes to 0
				}
				break;

			case 1:											// button is pressed: wait till release
				if (!i) {									// on button release
					timerStart(me->timer, 1500);				// 1 s timer
					me->state++;								// go next state
				}
				break;

			case 2:											// button just released
				if (i) {									// if button pressed again
					me->state = 0;
					goto ZERO;
				}
				if (timerExpired(me->timer)) {					// if 1 s elapsed
					timerStart(me->timer, me->timeout);			// timeout is retriggered
					me->state = 0;
				}
				break;
		}
	}

	return me->cntr;
}
Esempio n. 21
0
void KHelpMenu::dialogFinished()
{
  QTimer::singleShot( 0, this, SLOT(timerExpired()) );
}
Esempio n. 22
0
GLWidget::GLWidget(QWidget *parent)
 : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
    // set default look at
    lookAt[0]=0;
    lookAt[1]=0;
    lookAt[2]=10;

    // set initial light position
    lightPos = { 0,0,0,1 };

    // load the model and move it down 100 units
    modelLocation[0] = 0;
    modelLocation[1] = -100;
    modelLocation[2] = 0;


    qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);

    // no models loaded yet so set it to a invalid id
    modelDisplayList = -1;

    numMaterial = 0;
    // create new timer to handle animation
    t = new QTimer();

    // connect the timers timeout signal to the timer expired slot
    connect(t, SIGNAL(timeout()), this, SLOT(timerExpired()));
    // start the timer with a 30ms timout (30ms ~ 30Hz)
    t->start(30);
    // steal all keyboard inputs
    this->grabKeyboard();
    theta = 180;
    phi = 0;


    // update the GL context
    updateGL();

    // go load the terain
    loadNewModel(GL_TEXTURE0, "./models/terrain1.obj");

    this->terrainModel = getModelByName("terrain1.obj");

    // activate all the textures
    glActiveTexture(GL_TEXTURE1);
    loadTexture("./models/Grass.jpg");
    glActiveTexture(GL_TEXTURE2);
    loadTexture("./models/WoodChips.jpg");
    glActiveTexture(GL_TEXTURE3);
    loadTexture("./models/SkyBox.jpg");

    // build the skybox
    this->skyBoxModel.setDisplayID( buildSkyBox(490));

    // activate the skybox texture
    glActiveTexture(GL_TEXTURE0);

    // load all shaders
    program.removeAllShaders();
    program.addShaderFromSourceFile(QGLShader::Vertex, "./shaders/perpixelphong.vert");
    program.addShaderFromSourceFile(QGLShader::Fragment, "./shaders/perpixelphong.frag");

    // compile and bind the shader
    program.bind();
    // update all uniform values
    program.setUniformValue("heightMap",0);
    program.setUniformValue("baseMap1", 1);
    program.setUniformValue("baseMap2", 2);
    program.setUniformValue("skybox", 3);
    program.setUniformValue("mode", int(0));
    program.setUniformValue("envMap", 3);
    program.setUniformValue("numWaves", int(4));


    // set the parameter for the sum of sins equation
    waveAmp = {1.5,1.5,1,2, 10,10,10,10};
    wavelength= {50,30,50,30, 10,10,10,10};
    waveSpeed = {10,20,10,10, 10,10,10,10};
    direction[0] = QVector2D(-.2,.5);
    direction[1] = QVector2D(.5, -.3);
    direction[2] = QVector2D(0,1);
    direction[3] = QVector2D(-.1, -.8);
    program.setUniformValueArray("direction", direction, 4);
    program.setUniformValueArray("amplitude", waveAmp, 8,1);
    program.setUniformValueArray("wavelength", wavelength, 8,1);
    program.setUniformValueArray("speed", waveSpeed, 8,1);

}