Пример #1
0
static bool wait_changing_power_status(struct node *node, unsigned me, unsigned la, __u8 &new_status,
				       unsigned &unresponsive_time)
{
	__u8 old_status;
	time_t t = time(NULL);

	announce("Checking for power status change. This may take up to %u s.", long_timeout);
	if (!get_power_status(node, me, la, old_status))
		return false;
	while (time(NULL) - t < long_timeout) {
		__u8 power_status;

		if (!get_power_status(node, me, la, power_status)) {
			/* Some TVs become completely unresponsive when transitioning
			   between power modes. Register that this happens, but continue
			   the test. */
			unresponsive_time = time(NULL) - t;
		} else if (old_status != power_status) {
			new_status = power_status;
			return true;
		}
		sleep(SLEEP_POLL_POWER_STATUS);
	}
	new_status = old_status;
	return false;
}
Пример #2
0
static bool poll_stable_power_status(struct node *node, unsigned me, unsigned la,
				     __u8 expected_status, unsigned &unresponsive_time)
{
	bool transient = false;
	unsigned time_to_transient = 0;
	time_t t = time(NULL);

	/* Some devices can use several seconds to transition from one power
	   state to another, so the power state must be repeatedly polled */
	announce("Waiting for new stable power status. This may take up to %u s.", long_timeout);
	while (time(NULL) - t < long_timeout) {
		__u8 power_status;

		if (!get_power_status(node, me, la, power_status)) {
			/* Some TVs become completely unresponsive when transitioning
			   between power modes. Register that this happens, but continue
			   the test. */
			unresponsive_time = time(NULL) - t;
		}
		if (!transient && (power_status == CEC_OP_POWER_STATUS_TO_ON ||
				   power_status == CEC_OP_POWER_STATUS_TO_STANDBY)) {
			time_to_transient = time(NULL) - t;
			transient = true;
		}
		if (power_status == expected_status) {
			announce("Transient state after %d s, stable state %s after %d s",
			     time_to_transient, power_status2s(power_status), (int)(time(NULL) - t));
			return true;
		}
		sleep(SLEEP_POLL_POWER_STATUS);
	}
	return false;
}
Пример #3
0
void wait_release (void)
{
    short debounce;
    short status;
    for (debounce = 0; debounce < 10; debounce++) {
	get_power_status(0x4000, &status);
	if (!status)
	    debounce = 0;
    }   
}
Пример #4
0
bool util_interactive_ensure_power_state(struct node *node, unsigned me, unsigned la, bool interactive,
						__u8 target_pwr)
{
	interactive_info(true, "Please ensure that the device is in state %s.",
			 power_status2s(target_pwr));

	if (!node->remote[la].has_power_status)
		return true;

	while (interactive) {
		__u8 pwr;

		if (!get_power_status(node, me, la, pwr))
			announce("Failed to retrieve power status.");
		else if (pwr == target_pwr)
			return true;
		else
			announce("The device reported power status %s.", power_status2s(pwr));
		if (!question("Retry?"))
			return false;
	}

	return true;
}
Пример #5
0
int cgiMain() {
	int power_num,group_serial_num[5],group_num,group_idx;
	int i,j,k;
	char name[81];
	ctrl_group *p_group ;

	cgiFormInteger("power_num", &power_num, 0);
	cgiFormInteger("group_num", &group_num, 0);
	memset(name,0,sizeof(name));
	cgiFormStringNoNewlines("serial_num", name, 81);
	get_serial_num(name,&group_serial_num);
	
	if(power_num > 100) power_num = 100;
	if(group_num > 5) group_num = 5;
	if(group_serial_num[0] > 100) group_serial_num[0] = 100;
	if(group_serial_num[1] > 100) group_serial_num[1] = 100;
	if(group_serial_num[2] > 100) group_serial_num[2] = 100;
	if(group_serial_num[3] > 100) group_serial_num[3] = 100;
	if(group_serial_num[4] > 100) group_serial_num[4] = 100;


	cgiWriteEnvironment("/CHANGE/THIS/PATH/capcgi.dat");
	cgiHeaderContentType("text/html");

	OutHead();
	OutBodyStart();

	if(0 == check_password())
		return 0;

	fprintf(cgiOut, "<p>power_num=%d group_num=%d [%d-%d-%d-%d-%d]</p>\n",
		power_num,group_num,group_serial_num[0],group_serial_num[1],
		group_serial_num[2],group_serial_num[3],group_serial_num[4]);

	if(0 == power_num)
	{
		fprintf(cgiOut, "<p>数据出错,退出!!</p>\n");
		OutBodyEnd();	
		return 0;
	}
	else
	{
		pwsw_h.power_num = power_num;
		pwsw_h.group_num = group_num;
		pwsw_h.group[0].ctrl_serial_num = group_serial_num[0];
		pwsw_h.group[1].ctrl_serial_num = group_serial_num[1];
		pwsw_h.group[2].ctrl_serial_num = group_serial_num[2];
		pwsw_h.group[3].ctrl_serial_num = group_serial_num[3];
		pwsw_h.group[4].ctrl_serial_num = group_serial_num[4];

		for(i=0;i<group_num;i++)
		{
			p_group = &pwsw_h.group[i];
			p_group->projector_on = 0;
			p_group->ctrl_serial_num = group_serial_num[i];
			get_start_time(i,&p_group->start_time);
			get_end_time(i,&p_group->end_time);
			for(j=0;j<p_group->ctrl_serial_num;j++)
			{
				p_group->serial_info[j].duration_ms = get_duration_ms(i,j);
				for(k=0;k<power_num;k++)
				{
					p_group->serial_info[j].power_status[k]= get_power_status(i,j,k);
				}
				
			}
		}
	}

	//Out_pwsw_xml();
	save_to_xml_file();
	fprintf(cgiOut, "<p>保存成功,请返回!</p>\n");
	fprintf(cgiOut, "&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"button\" name=\"rest\" onclick=\"javascript:history.go(-1)\" value=\"重新载入\" />\n");

	OutBodyEnd();

	return 0;
}
Пример #6
0
int main (int argc, char *argv[])
{
  pm_status power_status;
  XEvent event;
  int fbc_toggle=1, fbc_auto=1;
  int old_battery_charging;
  time_t polling = 0;
  struct timespec delay;     /* pause between interface updates */
  char Command[CMDLINELEN+3];
  int warned = 0;

  delay.tv_sec  = 0;
  delay.tv_nsec = 500000000;

  BlinkRate     = (BlinkRate >= 0.0) ? BlinkRate : -1.0 * BlinkRate;
	waittime      = 0;       /* /proc polling interval */
	minBrightness = -1;
	maxBrightness = -1;

  fprintf(stderr, "\nWelcome to wmpower version %s...\n", VERSION);

	cpufreq_online_governor  = NULL;
	cpufreq_offline_governor = NULL;

  /* Parse any command line arguments. */
  ParseCMDLine (argc, argv);

  /*  Check for Power Management support  */
  if (!pm_support(our_battery))
  {
    fprintf (stderr, "\nNo power management support...\n");
    return EXIT_FAILURE;
  }

  /* Create window of the program */
  if (UseLowColorPixmap) openXwindow (argc, argv, wmpower_master_LowColor, (char *) wmpower_mask_bits, wmpower_mask_width, wmpower_mask_height);
  else openXwindow (argc, argv, wmpower_master, (char *) wmpower_mask_bits, wmpower_mask_width, wmpower_mask_height);

  /* Loop until we die... */
  while (1)
  {
    /* Get current power status */
    old_battery_charging = power_status.battery_charging;
    if (!waittime) get_power_status(&power_status);
    else if ((time(NULL)-polling) >= waittime)
    {
      get_power_status(&power_status);
      polling = time(NULL);
    }

    /* Manage power features only if function is not disabled */
    if (!no_meddling)
    {
      /* Re-enable auto power mode switching whan battery status changes */
      if (old_battery_charging != power_status.battery_charging) fbc_auto = 1;

      /* Enable fast battery charge mode if on AC and batt is charging   */
      if (!no_full_battery && power_status.ac_on_line && power_status.battery_charging && fbc_auto && !fbc_toggle && !(power_status.battery_percentage == 100))
      {
        fast_battery_charge(1);
				fbc_toggle = 1;
        fbc_auto   = 1;
      }

      /* Adjust variables value when battery reaches 100% */
      if (fbc_toggle && (power_status.battery_percentage == 100))
      {
				fast_battery_charge(0);
        fbc_toggle = 0;
        fbc_auto   = 1;
      }

			/* If battery not present and fast charge mode, disable it */
			if (fbc_toggle && !(power_status.battery_present))
			{
				fast_battery_charge(0);
				fbc_toggle = 0;
				fbc_auto   = 1;
			}

      /* Set various pm features whenever applicable */
      set_pm_features();
    }

    /* Execute the warning command, if needed */
    if (WarnCommand && *WarnCommand && !power_status.ac_on_line && !warned
				&& power_status.battery_time <= WarnTime)
		{
			warned = 1;
			sprintf(Command, "%s &", WarnCommand);
			system(Command);
    }
    if (power_status.ac_on_line)
      warned = 0;

    /* Show AC status led */
    ShowACstatus(power_status.ac_on_line);

    /* Display FAN status. */
    ShowFanStatus(power_status.fan_status);

    /* Display temperature. */
    ShowTemperature(power_status.temperature, power_status.temp_is_celsius);

    /* Display charge status */
    ShowChargeStatus(power_status.battery_charging);

    /* Display the "Time Left" */
    ShowBatteryTime(power_status.battery_time, power_status.battery_percentage, power_status.battery_charging, power_status.ac_on_line);

    /* Display battery percentage */
    ShowBatteryPercentage(power_status.battery_percentage);

    /* Display battery status led */
    ShowBatteryLed(power_status.battery_present, power_status.battery_percentage, power_status.ac_on_line);

    /* Process any pending X events. */
    while (XPending (display))
    {
      XNextEvent (display, &event);
      switch (event.type)
      {
				case Expose:
					RedrawWindow ();
					continue;
				case ButtonPress:
					if (no_meddling)
					{
						fprintf(stderr, "You cannot change PM status in '-no-meddling' mode of operation\n");
						continue;
					}
					if (event.xbutton.button == wheel_button_up)
					{
						lcdBrightness_UpOneStep();
						continue;
					}
					if (event.xbutton.button == wheel_button_down)
					{
						lcdBrightness_DownOneStep();
						continue;
					}
					fbc_toggle = !get_fast_battery_charge_mode();
					fbc_auto   = 0;
          fast_battery_charge(fbc_toggle);
					continue;
				case ButtonRelease:
					continue;
      }
    }

    /* Redraw and wait for next update */
    RedrawWindow ();
    nanosleep(&delay, NULL);
  }
}