mraa  1.8.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 
40 class Led
41 {
42  public:
48  Led(const char* led)
49  {
50  m_led = mraa_led_init(led);
51 
52  if (m_led == NULL) {
53  throw std::invalid_argument("Invalid LED name specified");
54  }
55  }
56 
63  Led(void* led_context)
64  {
65  m_led = (mraa_led_context) led_context;
66  if (m_led == NULL) {
67  throw std::invalid_argument("Invalid LED name specified");
68  }
69  }
70 
74  ~Led()
75  {
76  mraa_led_close(m_led);
77  }
78 
85  Result
86  setBrightness(int value)
87  {
88  return (Result) mraa_led_set_brightness(m_led, value);
89  }
90 
96  int
98  {
99  return mraa_led_read_brightness(m_led);
100  }
101 
107  int
109  {
110  return mraa_led_read_max_brightness(m_led);
111  }
112 
119  Result
120  trigger(const char* trigger)
121  {
122  return (Result) mraa_led_set_trigger(m_led, trigger);
123  }
124 
130  Result
132  {
133  return (Result) mraa_led_clear_trigger(m_led);
134  }
135 
136  private:
137  mraa_led_context m_led;
138 };
139 }
Result
Definition: types.hpp:200
mraa_result_t mraa_led_set_brightness(mraa_led_context dev, int value)
Result setBrightness(int value)
Definition: led.hpp:86
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:120
Led(const char *led)
Definition: led.hpp:48
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:131
int readBrightness()
Definition: led.hpp:97
Led(void *led_context)
Definition: led.hpp:63
int mraa_led_read_brightness(mraa_led_context dev)
Definition: aio.hpp:31
API to Light Emitting Diode.
Definition: led.hpp:40
mraa_result_t mraa_led_clear_trigger(mraa_led_context dev)
~Led()
Definition: led.hpp:74
LED module.
int readMaxBrightness()
Definition: led.hpp:108
mraa_result_t mraa_led_close(mraa_led_context dev)