|
- /**
- @page controlling_control_buttons Controlling control buttons
-
- In addition to sending button pressed and button released events, ControlButton objects can allow your application code to change the colour of the LED behind the corresponding physical button on a BLOCKS device.
-
- An array of pointers to the available %ControlButton objects can be obtained from the Block::getButtons() method of a Block --- see the @ref discovering_blocks section for details of how to obtain a %Block object.
- Once you have a %ControlButton, the functions involving the LED are ControlButton::hasLight() and ControlButton::setLightColour(), which are descriptively named.
- A code snippet showing how to turn all the available buttons of a %Block red is shown below.
-
- @code{.cpp}
- class BlockButtonExample
- {
- void setAllButtonsRed (Block& block)
- {
- for (auto button : block.getButtons())
- if (button->hasLight())
- button->setLightColour (LEDColour (0xffff0000));
- }
- };
- @endcode
-
- @section controlling_control_buttons_example_usage Example usage
-
- To add this functionality to the BlockFinder example project, add the above function to the BlockFinder class implementation. Then in the @s_projcode{topologyChanged()} callback, check if the connected %Block is a Control %Block and call the above function as shown below:
-
- @code{.cpp}
- void topologyChanged() override
- {
- //...
- for (auto& block : currentTopology.blocks)
- {
- //...
- if (block->getType() == Block::liveBlock || block->getType() == Block::loopBlock
- || block->getType() == Block::developerControlBlock || block->getType() == Block::touchBlock)
- {
- setAllButtonsRed (*block);
- }
- }
- }
- @endcode
-
- If you run the application now and connect a Control %Block, you should see the control buttons turn red.
-
- Learn more about other Block methods from the following pages:
-
- @ref getting_touch_events
-
- @ref getting_control_button_events
-
- @ref controlling_led_grids
-
- @ref controlling_led_strips
- */
|