Пример #1
0
static void
fire_or_rearm_alarm (GoaAlarm *self)
{
  GTimeSpan time_until_fire;
  GTimeSpan previous_time_until_fire;
  GDateTime *now;

  now = g_date_time_new_now_local ();
  time_until_fire = g_date_time_difference (self->priv->time, now);

  if (self->priv->previous_wakeup_time == NULL)
    {
      self->priv->previous_wakeup_time = now;

      /* If, according to the time, we're past when we should have fired,
       * then fire the alarm.
       */
      if (time_until_fire <= 0)
        fire_alarm (self);
    }
  else
    {
      previous_time_until_fire =
          g_date_time_difference (self->priv->time,
                                  self->priv->previous_wakeup_time);

      g_date_time_unref (self->priv->previous_wakeup_time);
      self->priv->previous_wakeup_time = now;

      /* If, according to the time, we're past when we should have fired,
       * and this is the first wakeup where that's been true then fire
       * the alarm. The first check makes sure we don't fire prematurely,
       * and the second check makes sure we don't fire more than once
       */
      if (time_until_fire <= 0 && previous_time_until_fire > 0)
        {
          fire_alarm (self);

          /* If, according to the time, we're before when we should fire,
           * and we previously fired the alarm, then we've jumped back in
           * time and need to rearm the alarm.
           */
        }
      else if (time_until_fire > 0 && previous_time_until_fire <= 0)
        {
          rearm_alarm (self);
        }
    }
}
Пример #2
0
/**
* @brief Send message to each expired alarm.
*/
static void
notify_alarms(void)
{
	time_t now;
	bool fired = false;

	now = reference_time();

	GSequenceIter *iter = g_sequence_get_begin_iter(gAlarmQueue->alarms);

	while (!g_sequence_iter_is_end(iter))
	{
		_Alarm *alarm = (_Alarm *)g_sequence_get(iter);
		GSequenceIter *next = g_sequence_iter_next(iter);

		if (alarm && alarm->expiry <= now)
		{
			fire_alarm(alarm);
			g_sequence_remove(iter);

			fired = true;
		}

		iter = next;
	}

	if (fired)
	{
		alarm_write_db();
	}
}
Пример #3
0
/*
 * Power nap countdown
 */
void power_nap_countdown() {

  if (!power_nap_mode)
    return;

  if (power_nap_settle_count != 0)
    return;

  if (power_nap_minute_count == 0)
    return;

  power_nap_minute_count--;

  char power_nap_ind[3];
  snprintf(power_nap_ind, sizeof(power_nap_ind), "%d", power_nap_minute_count);
  analogue_powernap_text(power_nap_ind);

  if (power_nap_minute_count == 0)
    fire_alarm();
}
Пример #4
0
/*
 * Has pebble been tapped?
 */
void accel_data_handler(AccelData *data, uint32_t num_samples) {
	// Average the data
	uint32_t avg_x = 0;
	uint32_t avg_y = 0;
	uint32_t avg_z = 0;
	AccelData *dx = data;
	for (uint32_t i = 0; i < num_samples; i++, dx++) {
		avg_x = avg_x + scale_accel(dx->x);
		avg_y = avg_y + scale_accel(dx->y);
		avg_z = avg_z + scale_accel(dx->z);
	}
	avg_x = avg_x / num_samples;
	avg_y = avg_y / num_samples;
	avg_z = avg_z / num_samples;

	// Work out deviations
	uint16_t biggest = 0;
	AccelData *d = data;
	for (uint32_t i = 0; i < num_samples; i++, d++) {
		uint16_t x = scale_accel(d->x) ;
		uint16_t y = scale_accel(d->y) ;
		uint16_t z = scale_accel(d->z) ;

		if (x < avg_x)
			x = avg_x - x;
		else
			x = x - avg_x;

		if (y < avg_y)
			y = avg_y - y;
		else
			y = y - avg_y;

		if (z < avg_z)
			z = avg_z - z;
		else
			z = z - avg_z;

		// Store the largest deviation in the period
		if (x > biggest) biggest = x;
		if (y > biggest) biggest = y;
		if (z> biggest) biggest = z;

	}

	// Waggle wrist and we start rotating events faster
	if (biggest >= 200) {
	  rotate_change = MIN_SECOND_PER_ROTATE;
	}

#ifdef ATTACK_ALARM
	if (biggest > 3000 && alarm_value == UTILITIES_FIND_MY_PHONE_PAUSE) {
		alarm_value = UTILITIES_FIND_MY_PHONE_PLAY;
		fire_alarm();
	} else if (biggest > 2000 && alarm_value == UTILITIES_FIND_MY_PHONE_PLAY) {
		alarm_value = UTILITIES_FIND_MY_PHONE_PAUSE;
		fire_alarm();
    }
#endif

}