cec: mark the active source as active and other devices as inactive. removed duplicat...
[deb_libcec.git] / include / cectypes.h
index e6c953e855221def2abceb9083d336e56ddfda51..4a503710248ea2557b92f4f577dde9f2dc054de5 100644 (file)
@@ -82,14 +82,14 @@ typedef enum
   CEC_AUDIO_RATE_SLOW_RATE_MIN_99_9 = 6
 } ECecAudioRate;
 
-typedef enum
+typedef enum cec_audio_status
 {
   CEC_AUDIO_MUTE_STATUS_MASK = 0x80,
   CEC_AUDIO_VOLUME_STATUS_MASK = 0x7F,
   CEC_AUDIO_VOLUME_MIN = 0x00,
   CEC_AUDIO_VOLUME_MAX = 0x64,
   CEC_AUDIO_VOLUME_STATUS_UNKNOWN = 0x7F
-} ECecAudioStatus;
+} cec_audio_status;
 
 typedef enum
 {
@@ -97,13 +97,14 @@ typedef enum
   CEC_TRUE = 1
 } ECecBoolean;
 
-typedef enum
+typedef enum cec_version
 {
-  CEC_VERSION_1_2 = 0x01,
-  CEC_VERSION_1_2A = 0x02,
-  CEC_VERSION_1_3 = 0x03,
-  CEC_VERSION_1_3A = 0x04
-} ECecVersion;
+  CEC_VERSION_UNKNOWN = 0x00,
+  CEC_VERSION_1_2     = 0x01,
+  CEC_VERSION_1_2A    = 0x02,
+  CEC_VERSION_1_3     = 0x03,
+  CEC_VERSION_1_3A    = 0x04
+} cec_version;
 
 typedef enum
 {
@@ -114,15 +115,15 @@ typedef enum
   CEC_MINOR_CHANNEL_NUMBER_MASK = 0xFFFF
 } ECecChannelIdentifier;
 
-typedef enum
+typedef enum cec_deck_control_mode
 {
   CEC_DESK_CONTROL_MODE_SKIP_FORWARD_WIND = 1,
   CEC_DESK_CONTROL_MODE_SKIP_REVERSE_REWIND = 2,
   CEC_DESK_CONTROL_MODE_STOP = 3,
   CEC_DESK_CONTROL_MODE_EJECT = 4
-} ECecDeskControlMode;
+} cec_deck_control_mode;
 
-typedef enum
+typedef enum cec_deck_info
 {
   CEC_DECK_INFO_PLAY = 0x11,
   CEC_DECK_INFO_RECORD = 0x12,
@@ -139,9 +140,9 @@ typedef enum
   CEC_DECK_INFO_INDEX_SEARCH_FORWARD = 0x1D,
   CEC_DECK_INFO_INDEX_SEARCH_REVERSE = 0x1E,
   CEC_DECK_INFO_OTHER_STATUS = 0x1F
-} ECecDeckInfo;
+} cec_deck_info;
 
-typedef enum
+typedef enum cec_device_type
 {
   CEC_DEVICE_TYPE_TV = 0,
   CEC_DEVICE_TYPE_RECORDING_DEVICE = 1,
@@ -149,7 +150,56 @@ typedef enum
   CEC_DEVICE_TYPE_TUNER = 3,
   CEC_DEVICE_TYPE_PLAYBACK_DEVICE = 4,
   CEC_DEVICE_TYPE_AUDIO_SYSTEM = 5
-} ECecDeviceType;
+} cec_device_type;
+
+typedef struct cec_device_type_list
+{
+  cec_device_type types[5];
+
+#ifdef __cplusplus
+  void clear(void)
+  {
+    for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+     types[iPtr] = CEC_DEVICE_TYPE_RESERVED;
+  }
+
+  void add(const cec_device_type type)
+  {
+    for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+    {
+      if (types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
+      {
+        types[iPtr] = type;
+        break;
+      }
+    }
+  }
+
+  bool isset(cec_device_type type)
+  {
+    bool bReturn(false);
+    for (unsigned int iPtr = 0; !bReturn && iPtr < 5; iPtr++)
+    {
+      if (types[iPtr] == type)
+        bReturn = true;
+    }
+    return bReturn;
+  }
+
+  bool empty()
+  {
+    bool bReturn(true);
+    for (unsigned int iPtr = 0; bReturn && iPtr < 5; iPtr++)
+    {
+      if (types[iPtr] != CEC_DEVICE_TYPE_RESERVED)
+        bReturn = false;
+    }
+    return bReturn;
+  }
+
+  cec_device_type operator[](uint8_t pos) const { return pos < 5 ? types[pos] : CEC_DEVICE_TYPE_RESERVED; }
+#endif
+} cec_device_type_list;
 
 typedef enum cec_display_control
 {
@@ -197,13 +247,14 @@ typedef enum
   CEC_PLAY_MODE_SLOW_REVERSE_MAX_SPEED = 0x1B
 } ECecPlayMode;
 
-typedef enum
+typedef enum cec_power_status
 {
   CEC_POWER_STATUS_ON = 0x00,
   CEC_POWER_STATUS_STANDBY = 0x01,
   CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON = 0x02,
-  CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY = 0x03
-} ECecPowerStatus;
+  CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY = 0x03,
+  CEC_POWER_STATUS_UNKNOWN = 0x99
+} cec_power_status;
 
 typedef enum
 {
@@ -261,11 +312,11 @@ typedef enum
   CEC_STATUS_REQUEST_ONCE = 3
 } ECecStatusRequest;
 
-typedef enum
+typedef enum cec_system_audio_status
 {
   CEC_SYSTEM_AUDIO_STATUS_OFF = 0,
   CEC_SYSTEM_AUDIO_STATUS_ON = 1
-} ECecSystemAudioStatus;
+} cec_system_audio_status;
 
 typedef enum
 {
@@ -434,6 +485,11 @@ typedef enum cec_user_control_code
   CEC_USER_CONTROL_CODE_UNKNOWN
 } cec_user_control_code;
 
+typedef enum cec_an_user_control_code
+{
+  CEC_AN_USER_CONTROL_CODE_RETURN = 0x91
+} cec_an_user_control_code;
+
 typedef enum cec_logical_address
 {
   CECDEVICE_UNKNOWN = -1, //not a valid logical address
@@ -456,6 +512,54 @@ typedef enum cec_logical_address
   CECDEVICE_BROADCAST = 15
 } cec_logical_address;
 
+typedef struct cec_logical_addresses
+{
+  cec_logical_address primary;
+  int                 addresses[16];
+
+#ifdef __cplusplus
+  void clear(void)
+  {
+    primary = CECDEVICE_UNKNOWN;
+    for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+      addresses[iPtr] = 0;
+  }
+
+  bool empty(void) const
+  {
+    return primary == CECDEVICE_UNKNOWN;
+  }
+
+  uint16_t ackmask(void) const
+  {
+    uint16_t mask = 0;
+    for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+      if (addresses[iPtr] == 1)
+        mask |= 0x1 << iPtr;
+    return mask;
+  }
+
+  void set(cec_logical_address address)
+  {
+    if (primary == CECDEVICE_UNKNOWN)
+      primary = address;
+
+    addresses[(int) address] = 1;
+  }
+
+  void unset(cec_logical_address address)
+  {
+    if (primary == address)
+      primary = CECDEVICE_UNKNOWN;
+
+    addresses[(int) address] = 0;
+  }
+
+  bool isset(cec_logical_address address) const { return addresses[(int) address] == 1; }
+  bool operator[](uint8_t pos) const { return pos < 16 ? isset((cec_logical_address) pos) : false; }
+#endif
+} cec_logical_addresses;
+
 typedef enum cec_opcode
 {
   CEC_OPCODE_ACTIVE_SOURCE = 0x82,
@@ -519,17 +623,26 @@ typedef enum cec_opcode
   CEC_OPCODE_SET_SYSTEM_AUDIO_MODE = 0x72,
   CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST = 0x70,
   CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS = 0x7E,
-  CEC_OPCODE_SET_AUDIO_RATE = 0x9A
+  CEC_OPCODE_SET_AUDIO_RATE = 0x9A,
+  CEC_OPCODE_NONE = 0xFD /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */
 } cec_opcode;
 
 typedef enum cec_log_level
 {
-  CEC_LOG_DEBUG = 0,
-  CEC_LOG_NOTICE,
-  CEC_LOG_WARNING,
-  CEC_LOG_ERROR
+  CEC_LOG_ERROR   = 1,
+  CEC_LOG_WARNING = 2,
+  CEC_LOG_NOTICE  = 4,
+  CEC_LOG_TRAFFIC = 8,
+  CEC_LOG_DEBUG   = 16,
+  CEC_LOG_ALL     = 31
 } cec_log_level;
 
+typedef struct cec_menu_language
+{
+  char                language[4];
+  cec_logical_address device;
+} cec_menu_language;
+
 typedef struct cec_log_message
 {
   char          message[1024];
@@ -584,6 +697,15 @@ typedef struct cec_datapacket
   uint8_t size;
 
 #ifdef __cplusplus
+  cec_datapacket &operator =(const struct cec_datapacket &packet)
+  {
+    clear();
+    for (uint8_t iPtr = 0; iPtr < packet.size; iPtr++)
+      push_back(packet[iPtr]);
+
+    return *this;
+  }
+
   bool    empty(void) const             { return size == 0; }
   bool    full(void) const              { return size == 100; }
   uint8_t operator[](uint8_t pos) const { return pos < size ? data[pos] : 0; }
@@ -618,26 +740,6 @@ typedef struct cec_datapacket
 
 } cec_datapacket;
 
-typedef struct cec_adapter_message
-{
-  cec_datapacket packet;
-
-#ifdef __cplusplus
-  bool                    empty(void) const             { return packet.empty(); }
-  uint8_t                 operator[](uint8_t pos) const { return packet[pos]; }
-  uint8_t                 at(uint8_t pos) const         { return packet[pos]; }
-  uint8_t                 size(void) const              { return packet.size; }
-  void                    clear(void)                   { packet.clear(); }
-  void                    shift(uint8_t iShiftBy)       { packet.shift(iShiftBy); }
-  void                    push_back(uint8_t add)        { packet.push_back(add); }
-  cec_adapter_messagecode message(void) const           { return packet.size >= 1 ? (cec_adapter_messagecode) (packet.at(0) & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK))  : MSGCODE_NOTHING; }
-  bool                    eom(void) const               { return packet.size >= 1 ? (packet.at(0) & MSGCODE_FRAME_EOM) != 0 : false; }
-  bool                    ack(void) const               { return packet.size >= 1 ? (packet.at(0) & MSGCODE_FRAME_ACK) != 0 : false; }
-  cec_logical_address     initiator(void) const         { return packet.size >= 2 ? (cec_logical_address) (packet.at(1) >> 4)  : CECDEVICE_UNKNOWN; };
-  cec_logical_address     destination(void) const       { return packet.size >= 2 ? (cec_logical_address) (packet.at(1) & 0xF) : CECDEVICE_UNKNOWN; };
-#endif
-} cec_adapter_message;
-
 typedef struct cec_command
 {
   cec_logical_address initiator;
@@ -647,15 +749,33 @@ typedef struct cec_command
   cec_opcode          opcode;
   cec_datapacket      parameters;
   int8_t              opcode_set;
+  int32_t             transmit_timeout;
 
 #ifdef __cplusplus
+  cec_command &operator =(const struct cec_command &command)
+  {
+    initiator        = command.initiator;
+    destination      = command.destination;
+    ack              = command.ack;
+    eom              = command.eom;
+    opcode           = command.opcode;
+    opcode_set       = command.opcode_set;
+    transmit_timeout = command.transmit_timeout;
+    parameters       = command.parameters;
+
+    return *this;
+  }
+
   static void format(cec_command &command, cec_logical_address initiator, cec_logical_address destination, cec_opcode opcode)
   {
     command.clear();
-    command.initiator   = initiator;
-    command.destination = destination;
-    command.opcode      = opcode;
-    command.opcode_set  = 1;
+    command.initiator    = initiator;
+    command.destination  = destination;
+    if (opcode != CEC_OPCODE_NONE)
+    {
+      command.opcode     = opcode;
+      command.opcode_set = 1;
+    }
   }
 
   void push_back(uint8_t data)
@@ -676,12 +796,13 @@ typedef struct cec_command
 
   void clear(void)
   {
-    initiator   = CECDEVICE_UNKNOWN;
-    destination = CECDEVICE_UNKNOWN;
-    ack         = 0;
-    eom         = 0;
-    opcode_set  = 0;
-    opcode      = CEC_OPCODE_FEATURE_ABORT;
+    initiator        = CECDEVICE_UNKNOWN;
+    destination      = CECDEVICE_UNKNOWN;
+    ack              = 0;
+    eom              = 0;
+    opcode_set       = 0;
+    opcode           = CEC_OPCODE_FEATURE_ABORT;
+    transmit_timeout = 1000;
     parameters.clear();
   };
 #endif
@@ -689,9 +810,34 @@ typedef struct cec_command
 
 typedef enum cec_vendor_id
 {
-  CEC_VENDOR_SAMSUNG = 240,
-  CEC_VENDOR_UNKNOWN = 0
-} vendor_id;
+  CEC_VENDOR_SAMSUNG   = 0x00F0,
+  CEC_VENDOR_LG        = 0xE091,
+  CEC_VENDOR_PANASONIC = 0x8045,
+  CEC_VENDOR_PIONEER   = 0xE036,
+  CEC_VENDOR_UNKNOWN   = 0
+} cec_vendor_id;
+
+typedef struct cec_vendor
+{
+  const char *AsString(void) const
+  {
+    switch (vendor)
+    {
+    case CEC_VENDOR_SAMSUNG:
+      return "Samsung";
+    case CEC_VENDOR_LG:
+      return "LG";
+    case CEC_VENDOR_PANASONIC:
+      return "Panasonic";
+    case CEC_VENDOR_PIONEER:
+      return "Pioneer";
+    default:
+      return "Unknown";
+    }
+  }
+
+  cec_vendor_id vendor;
+} cec_vendor;
 
 //default physical address 1.0.0.0, HDMI port 1
 #define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000
@@ -699,10 +845,12 @@ typedef enum cec_vendor_id
 #define MSGEND                       0xFE
 #define MSGESC                       0xFD
 #define ESCOFFSET                    3
-#define CEC_MIN_VERSION              6
-#define CEC_LIB_VERSION              8
 #define CEC_BUTTON_TIMEOUT           500
 
+#define CEC_MIN_LIB_VERSION          1
+#define CEC_LIB_VERSION_MAJOR        1
+#define CEC_LIB_VERSION_MINOR        0
+
 #ifdef __cplusplus
 };
 };