mraa  1.9.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(const char* 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 
64  Led(void* led_context)
65  {
66  m_led = (mraa_led_context) led_context;
67  if (m_led == NULL) {
68  throw std::invalid_argument("Invalid LED name specified");
69  }
70  }
71 
75  ~Led()
76  {
77  mraa_led_close(m_led);
78  }
79 
86  Result
87  setBrightness(int value)
88  {
89  return (Result) mraa_led_set_brightness(m_led, value);
90  }
91 
97  int
99  {
100  return mraa_led_read_brightness(m_led);
101  }
102 
108  int
110  {
111  return mraa_led_read_max_brightness(m_led);
112  }
113 
120  Result
121  trigger(const char* trigger)
122  {
123  return (Result) mraa_led_set_trigger(m_led, trigger);
124  }
125 
131  Result
133  {
134  return (Result) mraa_led_clear_trigger(m_led);
135  }
136 
137  private:
138  mraa_led_context m_led;
139 };
140 }
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:87
struct _led * mraa_led_context
Definition: led.h:47
int mraa_led_read_max_brightness(mraa_led_context dev)
Result trigger(const char *trigger)
Definition: led.hpp:121
Led(const char *led)
Definition: led.hpp:49
mraa_led_context mraa_led_init(const char *led)
mraa_result_t mraa_led_set_trigger(mraa_led_context dev, const char *trigger)
Result clearTrigger()
Definition: led.hpp:132
int readBrightness()
Definition: led.hpp:98
Led(void *led_context)
Definition: led.hpp:64
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:75
LED module.
int readMaxBrightness()
Definition: led.hpp:109
mraa_result_t mraa_led_close(mraa_led_context dev)