Project

General

Profile

Building libdaq example applicationslibraries » mainwindow.cpp

gpiosingle example - Jonathan Cormier, 07/08/2021 02:56 PM

 
1
#include "mainwindow.h"
2
#include "ui_mainwindow.h"
3

    
4
#define GPIO_TO_PIN(bank, gpio) ((bank)*32 + (gpio))
5

    
6
MainWindow::MainWindow(QWidget *parent)
7
    : QMainWindow(parent)
8
    , ui(new Ui::MainWindow)
9
    , gpioRedLed(GPIO_TO_NUM(1,12)) // gpio1_12
10
{
11
    ui->setupUi(this);
12

    
13
    gpioRedLed.setDirection(1, 0); // Set gpio as output low
14
}
15

    
16
MainWindow::~MainWindow()
17
{
18
    delete ui;
19
}
20

    
21

    
22
void MainWindow::on_pbToggleLed_clicked()
23
{
24
    int ret;
25
    unsigned int value;
26

    
27
    ret = gpioRedLed.GetValue(value);
28
    if (ret < 0) {
29
        qDebug() << "Error: Failed to get gpio value";
30
        return;
31
    }
32
    ret = gpioRedLed.SetValue(!value);
33
    if (ret < 0) {
34
        qDebug() << "Error: Failed to set gpio value";
35
        return;
36
    }
37
}
(5-5/5) Go to top
Add picture from clipboard (Maximum size: 1 GB)