Completed Example 22-TLV8_Characteristics

Must update Television.md documentation as well as Television Example to reflect recent changes to the Characteristics Apple made - there seems to be less flexibility in what needs to be defined to use the input sources.

Also need to add DisplayOrder Characteristic to TV documentation.
This commit is contained in:
Gregg 2024-04-23 06:41:44 -05:00
parent a785c1f937
commit 3273f7f24d
1 changed files with 57 additions and 56 deletions

View File

@ -33,7 +33,7 @@
// Example 24: Demonstrates the use of the TLV8 Library //
// by implementing DisplayOrder, an optional //
// TLV8 Characteristic used with the TV Service //
// to sets the order in which TV Inputs are //
// to set the order in which TV Inputs are //
// displayed for selection in the Home App //
// //
////////////////////////////////////////////////////////////////
@ -43,7 +43,7 @@
// NOTE: Please see the "Other Examples -> Television" sketch for complete details on how to implement a Television Service. The focus
// of this sketch is solely to demonstrate how to use the TLV8 Library to create TLV8 data for use with the DisplayOrder Characteristic.
// First we define a simple Television Input Source Service with only the Identifer and Name Characteristics
// First we define a simple Television Input Source Service
struct TVInput : Service::InputSource {
@ -54,18 +54,19 @@ struct TVInput : Service::InputSource {
inputID = new Characteristic::Identifier(id);
inputName = new Characteristic::ConfiguredName(name);
new Characteristic::IsConfigured(1);
new Characteristic::IsConfigured(Characteristic::IsConfigured::CONFIGURED);
new Characteristic::CurrentVisibilityState(Characteristic::CurrentVisibilityState::VISIBLE);
}
};
// Next we define a very simple Television Service
// Next we define a simple Television Service
struct HomeSpanTV : Service::Television {
SpanCharacteristic *active = new Characteristic::Active(0,true); // TV ON/OFF (set to OFF at start-up)
SpanCharacteristic *activeID = new Characteristic::ActiveIdentifier(30,true); // Set TV to input source with ID=30
SpanCharacteristic *active = new Characteristic::Active(0);
SpanCharacteristic *activeID = new Characteristic::ActiveIdentifier(10);
// SpanCharacteristic *displayOrder = new Characteristic::DisplayOrder(); // <-- This is the new TLV8 Characteristic. Note the constructor has no argument
SpanCharacteristic *displayOrder = new Characteristic::DisplayOrder(); // <-- This is the new TLV8 Characteristic. Note the constructor has no argument
HomeSpanTV() : Service::Television() {
@ -90,8 +91,8 @@ struct HomeSpanTV : Service::Television {
TLV8 orderTLV; // creates an empty TLV8 object
// Next, fill it with TAGS and VALUES based on the above specification. The easiest,
// though not necessarily most elegant, way to do this is as follows:
// Next, fill it with TAGS and VALUES based on the above specification. The easiest, though
// not necessarily most elegant, way to do this is by simply adding each TAG/VALUE as follows:
orderTLV.add(1,10); // TAG=1, VALUE=ID of first Input Source to be displayed
orderTLV.add(0); // TAG=0 (no value)
@ -104,12 +105,12 @@ struct HomeSpanTV : Service::Television {
orderTLV.add(1,40); // TAG=1, VALUE=ID of the fifth Input Source to be displayed
// Based on the above structure, we expect the Home App to display our input sources based on their IDs
// in the following order: 100, 200, 500, 300, 400. These IDs must of course match the IDs you choose
// in the following order: 10, 20, 50, 30, 40. These IDs must of course match the IDs you choose
// for your input sources when you create them at the end of this sketch in setup()
// The final step is to load this TLV8 object into the DisplayOrder Characteristic
// displayOrder->setTLV(orderTLV); // set the "value" of DisplayOrder to be the orderTLV object we just created
displayOrder->setTLV(orderTLV); // set the "value" of DisplayOrder to be the orderTLV object we just created
// That's it - you've created your first TLV8 Characteristic!
}
@ -119,11 +120,11 @@ struct HomeSpanTV : Service::Television {
boolean update() override {
if(active->updated()){
Serial.printf("Set TV Power to: %s\n",active->getNewVal()?"ON":"OFF");
LOG0("Set TV Power to: %s\n",active->getNewVal()?"ON":"OFF");
}
if(activeID->updated()){
Serial.printf("Set Input Source to ID=%d\n",activeID->getNewVal());
LOG0("Set Input Source to ID=%d\n",activeID->getNewVal());
}
return(true);