Go Down

Topic: Variables? (where is the structure defined?) (Read 843 times) previous topic - next topic

pert

#15
Jan 17, 2020, 06:33 am Last Edit: Jan 27, 2020, 03:40 am by pert Reason: Code tags!
Do you also know why there is only:

    PlaybackCommands getPlaybackCommand() {
      return _value.pbc;
    }

    InputValue getInputValue() {
      return _value.inp;
    }

    uint16_t getChannel() {
      return _value.cha;

and not also:

.setPlaybackCommand
.setInputValue
.setChannel
No. I can only guess that they just haven't gotten around to it yet. It looks like CloudTelevision is the most recently added class so it may be a work in progress.

The only way I know of to set these values is like this:
Code: [Select]
 Television televisionValues(tele.getSwitch(), tele.getVolume(), tele.getMute(), PlaybackCommands::Play, tele.getInputValue(), tele.getChannel());
  television=televisionValues;

or:
Code: [Select]
 Television televisionValues(tele.getSwitch(), tele.getVolume(), tele.getMute(), tele.getPlaybackCommand(), tele.getInputValue(), tele.getChannel());
  televisionValues.pbc=PlaybackCommands::Play;
  television=televisionValues;

In the above examples, the CloudTelevision object is named television and I'm setting the playback command to play. It's a bit awkward because you must set all the settings at once. In order to avoid changing the other settings, I must call their getter functions (e.g., getSwitch().

Can you also explain where initial volume /channel/ Input ... is set?
When you create the TV property, it adds this to the thingProperties.h tab of you sketch:
Code: [Select]
CloudTelevision television;
where "television" is the TV property's variable name. This calls this version of the CloudTelevision class's constructor:
Code: [Select]
CloudTelevision() : _value(false, 0, false, PlaybackCommands::None, InputValue::TV, 0), _cloud_value(false, 0, false, PlaybackCommands::None, InputValue::TV, 0) {}
_value is the variable that stores the settings values. _value is a Television class object. Here is the Television class's constructor:
Code: [Select]
Television(bool const swi, int const vol, bool const mut, PlaybackCommands const pbc, InputValue const inp, int const cha): swi(swi), vol(vol), mut(mut), pbc(pbc), inp(inp), cha(cha) {
    }

So the line:
Code: [Select]
CloudTelevision television;
sets swi (the switch state) to false, vol (the volume) to 0, mut (mute) to false, pbc to PlaybackCommands::None, and so on. So those are the initial values. If you wanted to set different initial values, you could use the other version of the CloudTelevision constructor:
Code: [Select]
CloudTelevision(bool const swi, int const vol, bool const mut, PlaybackCommands const pbc, InputValue const inp, int const cha) : _value(swi, vol, mut, pbc, inp, cha), _cloud_value(swi, vol, mut, pbc, inp, cha) {}
and set your desired initial values like this:
Code: [Select]
CloudTelevision television(true, 42, false, PlaybackCommands::Stop, InputValue::AUX1, 8);
That will set switch state to true, volume to 42, mute to false, playback command to PlaybackCommands::Stop, etc.

There is some good general information on C++ classes here that may be helpful in understanding the ArduinoCloudThing library's source code:
http://www.cplusplus.com/doc/tutorial/classes

And one more: On this "Dashboard" in the Arduino IOT Cloud, the TV has only one switch (Off / On) shouldn't it have all options? -> Volume, 0 to 100, Channel, input..
I would think so. Again, it might just be that this is work in progress and they haven't gotten around to it. You can implement this stuff yourself by using other properties. For example, volume could be set using a Custom Int property.

Thank you very much! You are really helpful!
You're very welcome. I'm glad if I can be of assistance.

janpho

#16
Jan 22, 2020, 10:01 am Last Edit: Jan 22, 2020, 10:13 am by janpho
Hello,


well, problems go on.


As the television.h is not finished yet, I tried the other smart home types. The SmartPlug does not work at all. I'm not sure what the problem might be.

Quote
code: switch1.setSwitch(false);



error: 'class CloudSmartPlug' has no member named 'setSwitch'

switch1.setSwitch(false);

^~~~~~~~~


Go Up