#![allow(unused_imports)]
use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};
pub const ID: ClusterId = 0x0509;
pub const REVISION: u16 = 1;
pub const PICS: &str = "KEYPADINPUT";
pub mod feature {
pub const NAVIGATION_KEY_CODES: u32 = 1 << 0;
pub const LOCATION_KEYS: u32 = 1 << 1;
pub const NUMBER_KEYS: u32 = 1 << 2;
}
pub const FEATURES: &[Feature] = &[
Feature {
bit: 0,
code: "NV",
name: "NavigationKeyCodes",
conform: Conform::OPTIONAL,
},
Feature {
bit: 1,
code: "LK",
name: "LocationKeys",
conform: Conform::OPTIONAL,
},
Feature {
bit: 2,
code: "NK",
name: "NumberKeys",
conform: Conform::OPTIONAL,
},
];
pub mod command {
use crate::im::CommandId;
pub const SEND_KEY: CommandId = 0x00;
pub const SEND_KEY_RESPONSE: CommandId = 0x01;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum CecKeyCodeEnum {
Select = 0,
Up = 1,
Down = 2,
Left = 3,
Right = 4,
RightUp = 5,
RightDown = 6,
LeftUp = 7,
LeftDown = 8,
RootMenu = 9,
SetupMenu = 10,
ContentsMenu = 11,
FavoriteMenu = 12,
Exit = 13,
MediaTopMenu = 16,
MediaContextSensitiveMenu = 17,
NumberEntryMode = 29,
Number11 = 30,
Number12 = 31,
Number0OrNumber10 = 32,
Numbers1 = 33,
Numbers2 = 34,
Numbers3 = 35,
Numbers4 = 36,
Numbers5 = 37,
Numbers6 = 38,
Numbers7 = 39,
Numbers8 = 40,
Numbers9 = 41,
Dot = 42,
Enter = 43,
Clear = 44,
NextFavorite = 47,
ChannelUp = 48,
ChannelDown = 49,
PreviousChannel = 50,
SoundSelect = 51,
InputSelect = 52,
DisplayInformation = 53,
Help = 54,
PageUp = 55,
PageDown = 56,
Power = 64,
VolumeUp = 65,
VolumeDown = 66,
Mute = 67,
Play = 68,
Stop = 69,
Pause = 70,
Record = 71,
Rewind = 72,
FastForward = 73,
Eject = 74,
Forward = 75,
Backward = 76,
StopRecord = 77,
PauseRecord = 78,
Reserved = 79,
Angle = 80,
SubPicture = 81,
VideoOnDemand = 82,
ElectronicProgramGuide = 83,
TimerProgramming = 84,
InitialConfiguration = 85,
SelectBroadcastType = 86,
SelectSoundPresentation = 87,
PlayFunction = 96,
PausePlayFunction = 97,
RecordFunction = 98,
PauseRecordFunction = 99,
StopFunction = 100,
MuteFunction = 101,
RestoreVolumeFunction = 102,
TuneFunction = 103,
SelectMediaFunction = 104,
SelectAvInputFunction = 105,
SelectAudioInputFunction = 106,
PowerToggleFunction = 107,
PowerOffFunction = 108,
PowerOnFunction = 109,
F1Blue = 113,
F2Red = 114,
F3Green = 115,
F4Yellow = 116,
F5 = 117,
Data = 118,
}
impl CecKeyCodeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Select),
1 => Some(Self::Up),
2 => Some(Self::Down),
3 => Some(Self::Left),
4 => Some(Self::Right),
5 => Some(Self::RightUp),
6 => Some(Self::RightDown),
7 => Some(Self::LeftUp),
8 => Some(Self::LeftDown),
9 => Some(Self::RootMenu),
10 => Some(Self::SetupMenu),
11 => Some(Self::ContentsMenu),
12 => Some(Self::FavoriteMenu),
13 => Some(Self::Exit),
16 => Some(Self::MediaTopMenu),
17 => Some(Self::MediaContextSensitiveMenu),
29 => Some(Self::NumberEntryMode),
30 => Some(Self::Number11),
31 => Some(Self::Number12),
32 => Some(Self::Number0OrNumber10),
33 => Some(Self::Numbers1),
34 => Some(Self::Numbers2),
35 => Some(Self::Numbers3),
36 => Some(Self::Numbers4),
37 => Some(Self::Numbers5),
38 => Some(Self::Numbers6),
39 => Some(Self::Numbers7),
40 => Some(Self::Numbers8),
41 => Some(Self::Numbers9),
42 => Some(Self::Dot),
43 => Some(Self::Enter),
44 => Some(Self::Clear),
47 => Some(Self::NextFavorite),
48 => Some(Self::ChannelUp),
49 => Some(Self::ChannelDown),
50 => Some(Self::PreviousChannel),
51 => Some(Self::SoundSelect),
52 => Some(Self::InputSelect),
53 => Some(Self::DisplayInformation),
54 => Some(Self::Help),
55 => Some(Self::PageUp),
56 => Some(Self::PageDown),
64 => Some(Self::Power),
65 => Some(Self::VolumeUp),
66 => Some(Self::VolumeDown),
67 => Some(Self::Mute),
68 => Some(Self::Play),
69 => Some(Self::Stop),
70 => Some(Self::Pause),
71 => Some(Self::Record),
72 => Some(Self::Rewind),
73 => Some(Self::FastForward),
74 => Some(Self::Eject),
75 => Some(Self::Forward),
76 => Some(Self::Backward),
77 => Some(Self::StopRecord),
78 => Some(Self::PauseRecord),
79 => Some(Self::Reserved),
80 => Some(Self::Angle),
81 => Some(Self::SubPicture),
82 => Some(Self::VideoOnDemand),
83 => Some(Self::ElectronicProgramGuide),
84 => Some(Self::TimerProgramming),
85 => Some(Self::InitialConfiguration),
86 => Some(Self::SelectBroadcastType),
87 => Some(Self::SelectSoundPresentation),
96 => Some(Self::PlayFunction),
97 => Some(Self::PausePlayFunction),
98 => Some(Self::RecordFunction),
99 => Some(Self::PauseRecordFunction),
100 => Some(Self::StopFunction),
101 => Some(Self::MuteFunction),
102 => Some(Self::RestoreVolumeFunction),
103 => Some(Self::TuneFunction),
104 => Some(Self::SelectMediaFunction),
105 => Some(Self::SelectAvInputFunction),
106 => Some(Self::SelectAudioInputFunction),
107 => Some(Self::PowerToggleFunction),
108 => Some(Self::PowerOffFunction),
109 => Some(Self::PowerOnFunction),
113 => Some(Self::F1Blue),
114 => Some(Self::F2Red),
115 => Some(Self::F3Green),
116 => Some(Self::F4Yellow),
117 => Some(Self::F5),
118 => Some(Self::Data),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for CecKeyCodeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for CecKeyCodeEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum StatusEnum {
Success = 0,
UnsupportedKey = 1,
InvalidKeyInCurrentState = 2,
}
impl StatusEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Success),
1 => Some(Self::UnsupportedKey),
2 => Some(Self::InvalidKeyInCurrentState),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for StatusEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for StatusEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SendKeyFields {
pub key_code: CecKeyCodeEnum,
}
impl ToTlv for SendKeyFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.key_code.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SendKeyFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut key_code = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => key_code = Some(<CecKeyCodeEnum>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
key_code: key_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SendKeyResponseFields {
pub status: StatusEnum,
}
impl ToTlv for SendKeyResponseFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.status.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for SendKeyResponseFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut status = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "SendKey",
to_server: true,
response: Some(0x01),
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x01,
name: "SendKeyResponse",
to_server: false,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
];
pub const EVENTS: &[Event] = &[];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Keypad Input",
revision: REVISION,
pics: "KEYPADINPUT",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};