Beispiel #1
0
/**
 * Dim the screen if necessary. Called by the Controller. Will dim in
 * several steps (one dim level at each call)
 */
void Controller::do_dimming() {

  if(m_never_dim) return;

  // only dim if not in brightness changing mode
  if(!m_dim_off) {
    // Check for no key presses then dim screen
    uint32_t release_time = cap_last_press_any();
    uint32_t   press_time = cap_last_release_any();
    uint32_t current_time = realtime_get_unixtime();

    uint8_t current_brightness = display_get_brightness();
    if(((current_time - press_time) > 10) && ((current_time - release_time) > 10)) {
      if(current_brightness > 1) display_set_brightness(current_brightness-1);
    } else {
      const char *sbright = flashstorage_keyval_get("BRIGHTNESS");
      unsigned int user_brightness=15;
      if(sbright != 0) {
        sscanf(sbright, "%u", &user_brightness);
      }
      if(current_brightness < user_brightness) {
        display_set_brightness(current_brightness+1);
      }
    }
  }
}
irom static app_action_t application_function_display_brightness(application_parameters_t ap)
{
	int8_t id;
	int8_t value;
	static const char *usage = "display-brightness: usage: display_id <brightess>=0,1,2,3,4\n";

	id = (uint8_t)atoi((*ap.args)[1]);

	if(ap.nargs > 2)
	{
		value = (uint8_t)atoi((*ap.args)[2]);

		if(!display_set_brightness(id, value))
		{
			snprintf(ap.dst, ap.size, "%s", usage);
			return(app_action_error);
		}
	}

	if(!display_get_brightness(id, &value))
	{
		snprintf(ap.dst, ap.size, "%s", usage);
		return(app_action_error);
	}

	snprintf(ap.dst, ap.size, "display %u brightness: %u\n", id, value);

	return(app_action_normal);
}