mraa  2.0.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
led.hpp
1 /*
2  * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
3  * Copyright (c) 2017 Linaro Ltd.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #include "led.h"
28 #include "types.hpp"
29 #include <stdexcept>
30 
31 namespace mraa
32 {
33 
41 class Led
42 {
43  public:
49  Led(int led)
50  {
51  m_led = mraa_led_init(led);
52 
53  if (m_led == NULL) {
54  throw std::invalid_argument("Invalid LED name specified");
55  }
56  }
57 
63  Led(std::string led_dev)
64  {
65  m_led = mraa_led_init_raw(led_dev.c_str());
66 
67  if (m_led == NULL) {
68  throw std::invalid_argument("Invalid LED name specified");
69  }
70  }
71 
78  Led(void* led_context)
79  {
80  m_led = (mraa_led_context) led_context;
81  if (m_led == NULL) {
82  throw std::invalid_argument("Invalid LED name specified");
83  }
84  }
85 
89  ~Led()
90  {
91  mraa_led_close(m_led);
92  }
93 
100  Result
101  setBrightness(int value)
102  {
103  return (Result) mraa_led_set_brightness(m_led, value);
104  }
105 
111  int
113  {
114  return mraa_led_read_brightness(m_led);
115  }
116 
122  int
124  {
125  return mraa_led_read_max_brightness(m_led);
126  }
127 
134  Result
135  trigger(const char* trigger)
136  {
137  return (Result) mraa_led_set_trigger(m_led, trigger);
138  }
139 
145  Result
147  {
148  return (Result) mraa_led_clear_trigger(m_led);
149  }
150 
151  private:
152  mraa_led_context m_led;
153 };
154 }
Result
Definition: types.hpp:204
mraa_result_t mraa_led_set_brightness(mraa_led_context dev, int value)
Result setBrightness(int value)
Definition: led.hpp:101
struct _led * mraa_led_context
Definition: led.h:47
mraa_led_context mraa_led_init_raw(const char *led_dev)
mraa_led_context mraa_led_init(int led)
int mraa_led_read_max_brightness(mraa_led_context dev)
Result trigger(const char *trigger)
Definition: led.hpp:135
Led(int led)
Definition: led.hpp:49
Led(std::string led_dev)
Definition: led.hpp:63
mraa_result_t mraa_led_set_trigger(mraa_led_context dev, const char *trigger)
Result clearTrigger()
Definition: led.hpp:146
int readBrightness()
Definition: led.hpp:112
Led(void *led_context)
Definition: led.hpp:78
int mraa_led_read_brightness(mraa_led_context dev)
Definition: aio.hpp:31
API to Light Emitting Diode.
Definition: led.hpp:41
mraa_result_t mraa_led_clear_trigger(mraa_led_context dev)
~Led()
Definition: led.hpp:89
LED module.
int readMaxBrightness()
Definition: led.hpp:123
mraa_result_t mraa_led_close(mraa_led_context dev)