/*! Stop the message alert sound. Does nothing if no message alert is in progress. */ void RingControl::stopMessageAlert() { if (d->currentRingSource == Msg) { qLog(PowerManagement) << "system suspended, stop message alert"; stopRing(); } }
// should eventually timeout. void RingControl::nextRing() { if (d->currentRingSource != NotRinging && d->curAlertType != QPhoneProfile::Once) { if (d->curAlertType == QPhoneProfile::Ascending && d->lastRingVolume < 5) d->lastRingVolume++; #ifdef MEDIA_SERVER d->soundcontrol->setVolume(volmap[d->lastRingVolume]); d->soundcontrol->sound()->play(); #elif defined(Q_WS_QWS) if (d->soundclient) { d->soundclient->play(0, d->curRingTone, volmap[d->lastRingVolume], QWSSoundClient::Priority); } #endif } #ifdef MEDIA_SERVER else { if (d->soundcontrol) { if(d->soundcontrol) { d->soundcontrol->sound()->stop(); disconnect(d->soundcontrol, SIGNAL(done()), this, SLOT(nextRing()) ); delete d->soundcontrol->sound(); delete d->soundcontrol; d->soundcontrol = 0; } } } #endif // we need to stop the vibration timer when using ring once if (d->curAlertType == QPhoneProfile::Once) { stopRing(); } }
void RingControl::startRinging(RingType t) { stopRing(); if(t == Call && !d->callEnabled) return; else if(t == Msg && !d->msgEnabled) return; if(qLogEnabled(QtopiaServer)) { QString type; switch(t) { case NotRinging: type = "NotRinging"; break; case Call: type = "Call"; break; case Msg: type = "Message"; break; } qLog(QtopiaServer) << "RingControl: Ringing" << type; } if(t == NotRinging) return; d->ringtime.start(); QPhoneProfile profile = d->profileManager->activeProfile(); QString ringToneDoc; // try contact ringtone if (t == Call) { // try personalized ring tone ringToneDoc = findRingTone(); // try profile ring tone // try video ring tone first. if (ringToneDoc.isEmpty()) { ringToneDoc = profile.videoTone().fileName(); if (!ringToneDoc.isEmpty()) { d->videoTone = true; } } // try profile ring tone if (ringToneDoc.isEmpty() || d->videoToneFailed) { ringToneDoc = profile.callTone().fileName(); d->videoTone = false; d->videoToneFailed = false; } // last resort, fall back to system ring tone if (ringToneDoc.isEmpty()) ringToneDoc = profile.systemCallTone().fileName(); d->curRingTone = ringToneDoc; d->curAlertType = profile.callAlert(); } else if (t == Msg) { d->curAlertType = profile.msgAlert(); if (d->curAlertType == QPhoneProfile::Continuous || d->curAlertType == QPhoneProfile::Ascending) { d->msgTid = startTimer(msgRingTime()); } ringToneDoc = profile.messageTone().fileName(); // fall back if above settings lead to non-existent ringtone. if (ringToneDoc.isEmpty()) ringToneDoc = profile.systemMessageTone().fileName(); d->curRingTone = ringToneDoc; } if (profile.vibrate()) { QVibrateAccessory vib; vib.setVibrateNow( true ); d->vibrateActive = true; d->vrbTid = startTimer(vibrateDuration()); } if(d->curAlertType == QPhoneProfile::Ascending) d->lastRingVolume = 1; else d->lastRingVolume = d->ringVolume; d->currentRingSource = t; if(d->lastRingVolume && d->curAlertType != QPhoneProfile::Off) { initSound(); #ifdef MEDIA_SERVER if ( !d->videoTone ) { if(d->soundcontrol && d->soundcontrol->sound()->fileName() != ringToneDoc) { delete d->soundcontrol->sound(); delete d->soundcontrol; d->soundcontrol = 0; } if (!d->soundcontrol) { d->soundcontrol = new QSoundControl(new QSound(d->curRingTone)); connect(d->soundcontrol, SIGNAL(done()), this, SLOT(nextRing()) ); } d->soundcontrol->setPriority(QSoundControl::RingTone); d->soundcontrol->setVolume(volmap[d->lastRingVolume]); d->soundcontrol->sound()->play(); } else { qLog(Media) << "Video ringtone selected" << d->curRingTone; QtopiaIpcSendEnvelope env = d->videoAdaptor->send( MESSAGE(playVideo(QString)) ); env << d->curRingTone; } #elif defined(Q_WS_QWS) if(d->soundclient) d->soundclient->play(0, d->curRingTone, volmap[d->lastRingVolume], QWSSoundClient::Priority); #endif } emit ringTypeChanged(d->currentRingSource); }
int steering::getAngle(LineSensor lineSensor, int motorAngle, int speed) { static int pathCounter = 0; static int lastCase = 1; static long lastTime = 0L; static int lastIndex = 7; static State currentState = LINE_FOLLOW; static State lastState = LINE_FOLLOW; static int lastAngle = 0; int size = lineSensor.howManyPins(); int* data = new int [size]; lineSensor.update(); lineSensor.getCurrent(data); int index = -1; int offCenter; static long timer; static int dist = 0; static long lastTimer; int amountSeen = 0; for (int i = 0; i < size; ++i) { prt.print(data[i]); if (data[i] == 1) { ++amountSeen; if (index == -1) { index = i; } } } prt.print('\t'); prt.println(pathCounter); int angle = 0; switch (currentState) { case LINE_FOLLOW: if (amountSeen > 2) { if(RING_DROPS[pathCounter]){ dropRing(); } switch (PATH_TURNS[pathCounter]) { case 0: lastState = currentState; currentState = LEFT_TURN1; ++pathCounter; break; case 1: offCenter = motorAngle - STEERING_CENTER; if ( offCenter < 20 && offCenter > -20) { lastState = currentState; currentState = IGNORE_TURN; ++pathCounter; } break; case 2: lastState = currentState; currentState = RIGHT_TURN1; ++pathCounter; break; case -1: lastState = currentState; currentState = LAND_PLANE; ++pathCounter; break; } } else if(PATH_LENGTH-1 == pathCounter){ lastState = currentState; currentState = LAND_PLANE; ++pathCounter; timer = millis(); } break; case LEFT_TURN1: if (data[1] == 0) { lastState = currentState; currentState = LEFT_TURN2; } break; case LEFT_TURN2: if (data[1] == 1) { lastState = currentState; currentState = LINE_FOLLOW; } break; case RIGHT_TURN1: if (data[6] == 0) { lastState = currentState; currentState = RIGHT_TURN2; } break; case RIGHT_TURN2: if (data[6] == 1) { lastState = currentState; currentState = LINE_FOLLOW; } break; case IGNORE_TURN: if (amountSeen < 3) { lastState = currentState; currentState = LINE_FOLLOW; } break; } switch (currentState) { case LINE_FOLLOW: if (index == -1) { angle = lastAngle; }else if ( millis() - lastTime > 5) { /*for (int i = 0; i < size; ++i) { Serial.print(data[i]); Serial1.print(data[i]); } Serial.print('\n'); Serial1.print('\n');*/ angle = index * 2; if (amountSeen == 2) { ++angle; } lastTime = millis(); angle = SENSOR_ANGLES[angle]; lastAngle = angle; } prt.println('F'); break; case LEFT_TURN1: angle = 180; prt.println("L1"); break; case LEFT_TURN2: angle = -180; prt.println("L2"); break; case RIGHT_TURN1: angle = 0; prt.println('R'); break; case RIGHT_TURN2: angle = 180; prt.println('R'); break; case IGNORE_TURN: angle = 0; prt.println('I'); break; case LAND_PLANE: prt.println('P'); dist = speed * (millis()-timer); if (dist < TILL_TURN) { prt.println("it"); if (index == -1) { angle = lastAngle; }else if ( millis() - lastTime > 5) { /*for (int i = 0; i < size; ++i) { Serial.print(data[i]); Serial1.print(data[i]); } Serial.print('\n'); Serial1.print('\n');*/ angle = index * 2; if (amountSeen == 2) { ++angle; } lastTime = millis(); angle = SENSOR_ANGLES[angle]; lastAngle = angle; } } else if(dist < TILL_TURN + TURN) { prt.println('t'); angle = 180; } else if (dist < TILL_TURN + TURN + AFTER_TURN) { prt.println("at"); angle = -314; } else { prt.println("done"); angle = 314; } break; } delete [] data; data = NULL; //Serial.println(angle); //Serial1.println(angle); stopRing(); return angle; }