PX4 Firmware
PX4 Autopilot Software http://px4.io
status_display.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2017 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file status_display.cpp
36  * Status Display: this decouples the LED and tune logic from the control logic in commander
37  *
38  * @author Simone Guscetti <simone@px4.io>
39  * @author Beat Küng <beat-kueng@gmx.net>
40  * @editor Christoph Tobler <christoph@px4.io>
41  */
42 
43 #include "status_display.h"
44 #include <drivers/drv_led.h>
45 
46 namespace events
47 {
48 namespace status
49 {
50 
52  : _subscriber_handler(subscriber_handler)
53 {
54  // set the base color
56  _led_control.led_mask = 0xff;
57  _led_control.color = led_control_s::COLOR_CYAN;
58  _led_control.mode = led_control_s::MODE_ON;
59  publish();
60 
62  _led_control.num_blinks = 0; // infinite blinking
63 }
64 
66 {
67  bool got_updates = false;
68 
71  got_updates = true;
72  }
73 
76  got_updates = true;
77  }
78 
81  got_updates = true;
82  }
83 
86  got_updates = true;
87  }
88 
89  return got_updates;
90 }
91 
93 {
94  if (!check_for_updates()) {
95  return;
96  }
97 
98  set_leds();
99 }
100 
102 {
104 
106 }
107 
108 } /* namespace status */
109 } /* namespace events */
struct vehicle_status_s _vehicle_status
int orb_copy(const struct orb_metadata *meta, int handle, void *buffer)
Definition: uORB.cpp:90
void publish()
publish LED control
static struct vehicle_status_s status
Definition: Commander.cpp:138
Contains a list of uORB subscriptions and maintains their update state.
uint8_t priority
Definition: led_control.h:77
bool publish(const T &data)
Publish the struct.
uint8_t led_mask
Definition: led_control.h:73
uint8_t color
Definition: led_control.h:74
struct battery_status_s _battery_status
Status Display decouples LED and tunes from commander.
StatusDisplay(const events::SubscriberHandler &subscriber_handler)
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Definition: uORB.h:87
void set_leds()
handle LED logic changes & call publish()
Definition: set_leds.cpp:48
uORB::PublicationQueued< led_control_s > _led_control_pub
uint8_t mode
Definition: led_control.h:75
Led device API to control the external LED(s) via uORB interface.
int get_vehicle_status_flags_sub() const
uint64_t timestamp
Definition: led_control.h:72
uint8_t num_blinks
Definition: led_control.h:76
static struct cpuload_s cpuload
Definition: Commander.cpp:151
bool vehicle_status_flags_updated() const
bool check_for_updates()
check for topic updates
const events::SubscriberHandler & _subscriber_handler
struct vehicle_status_flags_s _vehicle_status_flags
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
void process()
regularily called to handle state updates
struct led_control_s _led_control