From c0fca96074d59d085e3299edad94583f7592f5bf Mon Sep 17 00:00:00 2001
From: Antonio Ospite <ospite@studenti.unina.it>
Date: Thu, 28 Nov 2013 15:23:04 +0100
Subject: [PATCH 1/1] am7xxx: add support for setting the power mode on the
 PicoPix 2055

---
 src/am7xxx.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/am7xxx.c b/src/am7xxx.c
index 76b997c..4ac2461 100644
--- a/src/am7xxx.c
+++ b/src/am7xxx.c
@@ -79,6 +79,7 @@ struct am7xxx_usb_device_descriptor {
 };
 
 static int default_set_power_mode(am7xxx_device *dev, am7xxx_power_mode power);
+static int picopix_set_power_mode(am7xxx_device *dev, am7xxx_power_mode power);
 static int default_set_zoom_mode(am7xxx_device *dev, am7xxx_zoom_mode zoom);
 
 #define DEFAULT_OPS { \
@@ -125,6 +126,9 @@ static const struct am7xxx_usb_device_descriptor supported_devices[] = {
 		.product_id = 0x0016,
 		.configuration    = 2,
 		.interface_number = 0,
+		.ops = {
+			.set_power_mode = picopix_set_power_mode,
+		},
 	},
 	{
 		.name       = "Philips/Sagemcom PicoPix 2330",
@@ -163,6 +167,9 @@ typedef enum {
 	AM7XXX_PACKET_TYPE_IMAGE   = 0x02,
 	AM7XXX_PACKET_TYPE_POWER   = 0x04,
 	AM7XXX_PACKET_TYPE_ZOOM    = 0x05,
+	AM7XXX_PACKET_TYPE_PICOPIX_POWER_LOW    = 0x15,
+	AM7XXX_PACKET_TYPE_PICOPIX_POWER_MEDIUM = 0x16,
+	AM7XXX_PACKET_TYPE_PICOPIX_POWER_HIGH   = 0x17,
 } am7xxx_packet_type;
 
 struct am7xxx_generic_header {
@@ -890,6 +897,26 @@ static int default_set_power_mode(am7xxx_device *dev, am7xxx_power_mode power)
 	return 0;
 }
 
+static int picopix_set_power_mode(am7xxx_device *dev, am7xxx_power_mode power)
+{
+	switch(power) {
+	case AM7XXX_POWER_LOW:
+		return send_command(dev, AM7XXX_PACKET_TYPE_PICOPIX_POWER_LOW);
+
+	case AM7XXX_POWER_MIDDLE:
+		return send_command(dev, AM7XXX_PACKET_TYPE_PICOPIX_POWER_MEDIUM);
+
+	case AM7XXX_POWER_HIGH:
+		return send_command(dev, AM7XXX_PACKET_TYPE_PICOPIX_POWER_HIGH);
+
+	case AM7XXX_POWER_OFF:
+	case AM7XXX_POWER_TURBO:
+	default:
+		error(dev->ctx, "Unsupported power mode.\n");
+		return -EINVAL;
+	};
+}
+
 static int default_set_zoom_mode(am7xxx_device *dev, am7xxx_zoom_mode zoom)
 {
 	int ret;
-- 
2.1.4