Example #1
0
void Cycle::setPeriod(unsigned long time, int period){
    unsigned long current_time = adjustTime(time);
    float expand = ((float)period)/_period;
    
    _period_offset = ((unsigned long)(current_time * expand)) - (time % period); 
    _period = period;
}
Example #2
0
void Menu::setTime() {
	_currentIndex = _index;
	_currentTime = getSaveLoad()->getTime(_currentIndex);

	if (_time == _currentTime)
		adjustTime();
}
Example #3
0
int Heartbeat::value(unsigned long time)
{
    fadeAmplitude(time);    
    
    float portion = adjustTime(time)/((float) _period) * N_ECG; // normalize the proportion to 2PI
    return (int)(ECG[(int)portion] * (_amplitude/255.0));
}
Example #4
0
int SineWave::value(unsigned long time)
{
    fadeAmplitude(time);
    
    float portion = adjustTime(time)/((float) _period) * 2 * M_PI; // normalize the proportion to 2PI
    return (int) ((sin(portion) + 1) * _amplitude) / 2;
}
bool FrameManager::transformHasProblems(const std::string& frame, ros::Time time, std::string& error)
{
  if ( !adjustTime(frame, time) )
  {
    return false;
  }

  std::string tf_error;
  bool transform_succeeded = tf_->canTransform(fixed_frame_, frame, time, &tf_error);
  if (transform_succeeded)
  {
    return false;
  }

  bool ok = true;
  ok = ok && !frameHasProblems(fixed_frame_, time, error);
  ok = ok && !frameHasProblems(frame, time, error);

  if (ok)
  {
    std::stringstream ss;
    ss << "No transform to fixed frame [" << fixed_frame_ << "].  TF error: [" << tf_error << "]";
    error = ss.str();
    ok = false;
  }

  {
    std::stringstream ss;
    ss << "For frame [" << frame << "]: " << error;
    error = ss.str();
  }

  return !ok;
}
Example #6
0
void Menu::eventTick(const Common::Event&) {
	if (hasTimeDelta())
		adjustTime();
	else if (_handleTimeDelta)
		_handleTimeDelta = false;

	// Check hotspots
	if (!--_checkHotspotsTicks) {
		checkHotspots();
		_checkHotspotsTicks = 15;
	}
}
Example #7
0
inline void page_modifyTime() {
  static int timeScaleIndex = 0;
  if (pre_page != MODIFY_TIME)
  {
    PTLS("Page Mod Time");
    pre_page = MODIFY_TIME;
    lcd.cursor();
  }
  lcd.setCursor(0,1);
  String str_time = getTimeString(); 
  lcd.print(str_time);

  if (timeScaleIndex == 0) lcd.setCursor(0,1);
  else if (timeScaleIndex == 1) lcd.setCursor(0,4);
  else if (timeScaleIndex == 2) lcd.setCursor(0,7);
    
  if (button_input == PLUS_UP || button_input == PLUS_HOLD)
  {
    long adjust = timeScale[timeScaleIndex];
    adjustTime(adjust);
    setSyncInterval(SCALE_HOUR);
  }
  else if (button_input == MINUS_UP || button_input == MINUS_HOLD)
  {
    long adjust = -timeScale[timeScaleIndex];
    adjustTime(adjust);
    setSyncInterval(SCALE_HOUR);
  }
  else if (button_input == SET_UP)
  {
    setSyncInterval( 3600 );
    switchPage(HOME);
  }
  else if (button_input == MODE_UP)
  {
    timeScaleIndex++;
    timeScaleIndex = timeScaleIndex % 3;
    PTS("Changed focus: "); PTL(timeScaleIndex);
  }
}
Example #8
0
  // ensure that stored time is less than 24 hrs and adjust date accordingly
  void DateTime::normalize()
  {
    // total number of whole days in the time 
    int wholeDays = m_time.days();

    // if time is longer than a day (either positive or negative) normalize it to remainder less than 24 hrs
    if (wholeDays != 0){
      Time adjustTime(wholeDays,0,0,0);
      m_date += adjustTime;
      m_time -= adjustTime;
    }

    // total number of fractional days in the time 
    double fracDays = m_time.totalDays();

    // if time is negative add a day to make it positive
    if (fracDays < 0){
      Time adjustTime(1,0,0,0);
      m_date -= adjustTime;
      m_time += adjustTime;
    }
  }
Example #9
0
void godob::handle_time_keys(btnval_e lcd_key)
{
  switch (lcd_key)
    {
    case btnRIGHT:
      if(t_set==true){
	t_idx++;
	t_idx %= 7;
      }
      t_set = true;
      t_adjust=show_adjust(t_idx);
      break;
    case btnLEFT:
      if(t_set==true){
	t_idx+=6;
	t_idx %= 7;
      }
      t_set = true;
      t_adjust=show_adjust(t_idx);
      break;
    case btnUP:
      if(t_set == true){
	//adjustTime(t_adjust); /* doesn't work when t_adjust>0. weird! */
	setTime(now() + t_adjust);
      }
      else{
	handle_main_keys(lcd_key);
      }
      break;
    case btnDOWN:
      if(t_set == true){
	adjustTime(-t_adjust);
      }
      else{
	handle_main_keys(lcd_key);
      }
      break;
    case btnSELECT:
      if(t_set==false){
	handle_main_keys(lcd_key);
      }
      else{
	setRTC();
	LCD->noCursor();
      }
      t_set=false;
      break;
    case btnNONE:
      break;
    }
}
void TimeState::incomingMessageCallback(const struct ble_msg_attributes_value_evt_t *msg) {
    isWaitingForResponse = false;
    if(msg -> value.data[0] == 0x02)//Time return
    {
      byte b[4] = {
        msg -> value.data[4], msg -> value.data[3], msg -> value.data[2], msg -> value.data[1] };
      long timeStamp = bytesToInteger(b);
      Serial.print(F("TimeStamp: "));
      Serial.println(timeStamp);
      setTime(timeStamp);
      long timeZoneOffset = 60*60*TIME_ZONE_OFFSET;
      adjustTime(timeZoneOffset);//Adjusting time zone . . . 
      renderClockType1();
    }
}
Example #11
0
bool DateVariable::loadOdf(const KXmlElement & element, KShapeLoadingContext & context)
{
    const QString localName(element.localName());
    QString dateFormat = "";
    QString dataStyle = element.attributeNS(KOdfXmlNS::style, "data-style-name");
    if (!dataStyle.isEmpty()) {
        if (context.odfLoadingContext().stylesReader().dataFormats().contains(dataStyle)) {
            KOdf::NumericStyleFormat dataFormat = context.odfLoadingContext().stylesReader().dataFormats().value(dataStyle).first;
            dateFormat = dataFormat.prefix + dataFormat.formatStr + dataFormat.suffix;
        }
    }

    //dateProperties.setProperty("fixed", QVariant(element.attributeNS(KOdfXmlNS::text, "fixed") == "true"));
    if (element.attributeNS(KOdfXmlNS::text, "fixed", "false") == "true") {
        m_type = Fixed;
    } else {
        m_type = AutoUpdate;
    }

    //dateProperties.setProperty("time", element.attributeNS(KOdfXmlNS::text, localName + "-value"));
    const QString value(element.attributeNS(KOdfXmlNS::text, localName + "-value", ""));
    if (!value.isEmpty()) {
        m_time = QDateTime::fromString(value, Qt::ISODate);
    } else {
        //TODO see 6.2.1 Date Fields
    }

    //dateProperties.setProperty("definition", dateFormat);
    m_definition = dateFormat;

    if (dateFormat.isEmpty())
        if (localName == "time") {
            m_displayType = Time;
        } else {
            m_displayType = Date;
        }
    else {
        m_displayType = Custom;
    }

    //dateProperties.setProperty("adjust", element.attributeNS(KOdfXmlNS::text, localName + "-adjust"));
    const QString adjust(element.attributeNS(KOdfXmlNS::text, localName + "-adjust", ""));
    adjustTime(adjust);
    update();
    return true;
}
Example #12
0
	bool update()
	{
		tick();
		adjustTime();
		FramePtr newFrame = fetchFrame();

		if(newFrame != 0){
			// Don't free currentFrame if it is currentFrame itself that's being converted
			if(currentFrame == 0 || currentFrame->GetAvFrame() != newFrame->GetAvFrame()){
				currentFrame = newFrame; // Save the current frame for snapshots etc.
			}

			lastFrameQueuePts = timeFromTs(newFrame->GetPts());
			return true;
		}

		return false;
	}
Example #13
0
void DateVariable::readProperties(const KProperties *props)
{
    m_definition = props->stringProperty("definition");
    if (!props->stringProperty("time").isEmpty())
        m_time = QDateTime::fromString(props->stringProperty("time"), Qt::ISODate);
    if (props->intProperty("id") == Fixed)
        m_type = Fixed;
    else
        m_type = AutoUpdate;
    QString displayTypeProp = props->stringProperty("displayType", "custom");
    if (displayTypeProp == "custom")
        m_displayType = Custom;
    else if (displayTypeProp == "date")
        m_displayType = Date;
    else if (displayTypeProp == "time")
        m_displayType = Time;
    adjustTime(props->stringProperty("adjust"));
    update();
}
Example #14
0
bool FrameManager::transform(const std::string& frame, ros::Time time, const geometry_msgs::Pose& pose_msg, Ogre::Vector3& position, Ogre::Quaternion& orientation)
{
  if ( !adjustTime(frame, time) )
  {
    return false;
  }

  position = Ogre::Vector3::ZERO;
  orientation = Ogre::Quaternion::IDENTITY;

  // put all pose data into a tf stamped pose
  tf::Quaternion bt_orientation(pose_msg.orientation.x, pose_msg.orientation.y, pose_msg.orientation.z, pose_msg.orientation.w);
  tf::Vector3 bt_position(pose_msg.position.x, pose_msg.position.y, pose_msg.position.z);

  if (bt_orientation.x() == 0.0 && bt_orientation.y() == 0.0 && bt_orientation.z() == 0.0 && bt_orientation.w() == 0.0)
  {
    bt_orientation.setW(1.0);
  }

  tf::Stamped<tf::Pose> pose_in(tf::Transform(bt_orientation,bt_position), time, frame);
  tf::Stamped<tf::Pose> pose_out;

  // convert pose into new frame
  try
  {
    tf_->transformPose( fixed_frame_, pose_in, pose_out );
  }
  catch(std::runtime_error& e)
  {
    ROS_DEBUG("Error transforming from frame '%s' to frame '%s': %s", frame.c_str(), fixed_frame_.c_str(), e.what());
    return false;
  }

  bt_position = pose_out.getOrigin();
  position = Ogre::Vector3(bt_position.x(), bt_position.y(), bt_position.z());

  bt_orientation = pose_out.getRotation();
  orientation = Ogre::Quaternion( bt_orientation.w(), bt_orientation.x(), bt_orientation.y(), bt_orientation.z() );

  return true;
}
Example #15
0
bool FrameManager::getTransform(const std::string& frame, ros::Time time, Ogre::Vector3& position, Ogre::Quaternion& orientation)
{
  if ( !adjustTime(frame, time) )
  {
    return false;
  }

  boost::mutex::scoped_lock lock(cache_mutex_);

  position = Ogre::Vector3(9999999, 9999999, 9999999);
  orientation = Ogre::Quaternion::IDENTITY;

  if (fixed_frame_.empty())
  {
    return false;
  }

  M_Cache::iterator it = cache_.find(CacheKey(frame, time));
  if (it != cache_.end())
  {
    position = it->second.position;
    orientation = it->second.orientation;
    return true;
  }

  geometry_msgs::Pose pose;
  pose.orientation.w = 1.0f;

  if (!transform(frame, time, pose, position, orientation))
  {
    return false;
  }

  cache_.insert(std::make_pair(CacheKey(frame, time), CacheEntry(position, orientation)));

  return true;
}
void MainWindow::fastForward()
{
    adjustTime(getAdjustInterval());
}
Example #17
0
bool DateVariable::loadOdf(const KoXmlElement & element, KoShapeLoadingContext & context)
{
    const QString localName(element.localName());
    QString dateFormat = "";
    QString dataStyle = element.attributeNS(KoXmlNS::style, "data-style-name");
    if (!dataStyle.isEmpty()) {
        if (context.odfLoadingContext().stylesReader().dataFormats().contains(dataStyle)) {
            KoOdfNumberStyles::NumericStyleFormat dataFormat = context.odfLoadingContext().stylesReader().dataFormats().value(dataStyle).first;
            dateFormat = dataFormat.prefix + dataFormat.formatStr + dataFormat.suffix;
        }
    }

    //dateProperties.setProperty("fixed", QVariant(element.attributeNS(KoXmlNS::text, "fixed") == "true"));
    if (element.attributeNS(KoXmlNS::text, "fixed", "false") == "true") {
        m_type = Fixed;
    } else {
        m_type = AutoUpdate;
    }

    if (localName == "time") {
        m_displayType = Time;
    } else {
        m_displayType = Date;
    }

    //dateProperties.setProperty("time", element.attributeNS(KoXmlNS::text, localName + "-value"));
    QString value(element.attributeNS(KoXmlNS::text, localName + "-value", ""));
    if (!value.isEmpty()) {
#ifndef NWORKAROUND_ODF_BUGS
        KoOdfWorkaround::fixBadDateForTextTime(value);
#endif
        // hopefully this simple detection works in all cases
        const bool isDateTime = (value.indexOf(QLatin1Char('T')) != -1);

        if (isDateTime) {
            m_datetime = QDateTime::fromString(value, Qt::ISODate);
            m_valueType = DateTime;
        } else {
            if (m_displayType == Time) {
                const QTime time = QTime::fromString(value, Qt::ISODate);
                m_datetime = QDateTime(QDate::currentDate(), time);
            } else {
                const QDate date = QDate::fromString(value, Qt::ISODate);
                m_datetime = QDateTime(date);
            }
            m_valueType = DateOrTime;
        }
    } else {
        // if value is not set current time is assumed  ODF 19.881 text:time-value
        m_type = AutoUpdate;
    }

    //dateProperties.setProperty("definition", dateFormat);
    m_definition = dateFormat;

    //dateProperties.setProperty("adjust", element.attributeNS(KoXmlNS::text, localName + "-adjust"));
    const QString adjust(element.attributeNS(KoXmlNS::text, localName + "-adjust", ""));
    adjustTime(adjust);
    update();
    return true;
}
void MainWindow::fastBackward()
{
    adjustTime(-getAdjustInterval());
}