-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathgpio.cpp
48 lines (42 loc) · 1.01 KB
/
gpio.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <QDebug>
#include <lgpio.h>
#include "gpio.h"
#include "config.h"
gpio::gpio(QObject *parent) : QObject(parent)
{
m_handle = lgGpiochipOpen(CHIP); // get a handle to the GPIO
int init_level = 0;
for (auto pin : LEDS) // Outputs
lgGpioClaimOutput(m_handle, LFLAGS, pin, init_level);
for (auto pin : BUTTONS) // Inputs
lgGpioClaimInput(m_handle, LFLAGS, pin);
}
gpio::~gpio()
{
// Cleanup GPIO
int init_level = 0;
for (auto pin : LEDS)
lgGpioWrite(m_handle, pin, init_level);
lgGpiochipClose(m_handle);
qDebug() << "bye";
}
// Write to pins
void gpio::set(int pin, bool value)
{
lgGpioWrite(m_handle, pin, value);
}
void gpio::set(unsigned int pattern)
{
int n = 0;
int value = 0;
for (auto pin: LEDS) {
// n-te Stelle vom pattern ausmaskieren, value =
lgGpioWrite(m_handle, pin, value);
// Maske um 1 Stelle nach vorne verschieben
}
}
// Read pin state
bool gpio::get(int pin)
{
return lgGpioRead(m_handle, pin);
}