*/
#include <stdio.h>
+#include <stdlib.h>
#include <errno.h>
#include <hw/display.h>
+#define DUMMY_MAX_BRIGHTNESS 100
+
+static enum display_state dummy_state;
+static int dummy_brightness;
+
+static int dummy_display_get_max_brightness(int *val)
+{
+ if (!val)
+ return -EINVAL;
+
+ *val = DUMMY_MAX_BRIGHTNESS;
+ return 0;
+}
+
+static int dummy_display_get_brightness(int *brightness)
+{
+ if (!brightness)
+ return -EINVAL;
+
+ *brightness = dummy_brightness;
+ return 0;
+}
+
+static int dummy_display_set_brightness(int brightness)
+{
+ if (brightness < 0 || brightness > DUMMY_MAX_BRIGHTNESS)
+ return -EINVAL;
+
+ dummy_brightness = brightness;
+ return 0;
+}
+
+static int dummy_display_get_state(enum display_state *state)
+{
+ *state = dummy_state;
+ return 0;
+}
+
+static int dummy_display_set_state(enum display_state state)
+{
+ dummy_state = state;
+ return 0;
+}
+
static int display_open(struct hw_info *info,
const char *id, struct hw_common **common)
{
+ struct display_device *display_dev;
+
if (!info || !common)
return -EINVAL;
- *common = NULL;
+ display_dev = calloc(1, sizeof(struct display_device));
+ if (!display_dev)
+ return -ENOMEM;
+
+ dummy_state = DISPLAY_ON;
+ dummy_brightness = 100;
+
+ display_dev->common.info = info;
+ display_dev->get_max_brightness = dummy_display_get_max_brightness;
+ display_dev->get_brightness = dummy_display_get_brightness;
+ display_dev->set_brightness = dummy_display_set_brightness;
+
+ display_dev->get_state = dummy_display_get_state;
+ display_dev->set_state = dummy_display_set_state;
+
+ *common = (struct hw_common *)display_dev;
return 0;
}
static int display_close(struct hw_common *common)
{
- if (common) /* we use NULL display_dev */
+ if (!common)
return -EINVAL;
+ free(common);
return 0;
}