├── Plot-Real-Time-Graphs-Qt-Example └── Qt_Test │ ├── main.cpp │ ├── mainwindow.h │ ├── Qt_Test.pro │ ├── spi.h │ ├── mainwindow.ui │ ├── ad7190.h │ ├── mainwindow.cpp │ ├── spi.cpp │ ├── ad7190.cpp │ └── Qt_Test.pro.user ├── README.md └── LICENSE /Plot-Real-Time-Graphs-Qt-Example/Qt_Test/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Plot-Real-Time-Graphs-Qt-Embedded-Linux 2 | 3 | This is an example code that demonstartes how to use the qcustomplot Library to plot real-time graphs using Qt on Embedded Linux (BeagleBone). 4 | 5 | Youtube: https://youtu.be/HslZT-8ifrM 6 | 7 | MIT license, check LICENSE file for more information 8 | -------------------------------------------------------------------------------- /Plot-Real-Time-Graphs-Qt-Example/Qt_Test/mainwindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mainwindow.h 3 | * 4 | * Created on : Dec 10, 2017 5 | * Author : Vinay Divakar 6 | * website : www.deeplyemebedded.org 7 | */ 8 | 9 | #ifndef MAINWINDOW_H 10 | #define MAINWINDOW_H 11 | 12 | /* Includes */ 13 | #include 14 | #include 15 | 16 | namespace Ui { 17 | class MainWindow; 18 | } 19 | 20 | class MainWindow : public QMainWindow 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | explicit MainWindow(QWidget *parent = 0); 26 | ~MainWindow(); 27 | 28 | private slots: 29 | 30 | void on_pushButton_released(); 31 | 32 | public slots: 33 | void display_data(unsigned long adc_data); 34 | void realtimePlot(); 35 | 36 | 37 | private: 38 | Ui::MainWindow *ui; 39 | unsigned long adc_data_g; 40 | QTimer timer_plot; 41 | }; 42 | 43 | #endif // MAINWINDOW_H 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Vinay Divakar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Plot-Real-Time-Graphs-Qt-Example/Qt_Test/Qt_Test.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-11-11T22:40:25 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | QMAKE_CXXFLAGS += -std=c++11 10 | 11 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport 12 | 13 | TARGET = Qt_Test 14 | target.files = Qt_Test 15 | target.path = /home/debian 16 | INSTALLS+=target 17 | TEMPLATE = app 18 | 19 | # The following define makes your compiler emit warnings if you use 20 | # any feature of Qt which as been marked as deprecated (the exact warnings 21 | # depend on your compiler). Please consult the documentation of the 22 | # deprecated API in order to know how to port your code away from it. 23 | DEFINES += QT_DEPRECATED_WARNINGS 24 | 25 | # You can also make your code fail to compile if you use deprecated APIs. 26 | # In order to do so, uncomment the following line. 27 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 28 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 29 | 30 | 31 | SOURCES += \ 32 | main.cpp \ 33 | mainwindow.cpp \ 34 | spi.cpp \ 35 | ad7190.cpp \ 36 | qcustomplot.cpp 37 | 38 | HEADERS += \ 39 | mainwindow.h \ 40 | spi.h \ 41 | ad7190.h \ 42 | qcustomplot.h 43 | 44 | FORMS += \ 45 | mainwindow.ui 46 | -------------------------------------------------------------------------------- /Plot-Real-Time-Graphs-Qt-Example/Qt_Test/spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | Copyright (c) 2017 DeeplyEmbedded 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | SOFTWARE. 19 | * spi.h 20 | * 21 | * Created on : Nov 12, 2017 22 | * Author : Vinay Divakar 23 | * website : www.deeplyemebedded.org 24 | */ 25 | 26 | #ifndef SPI_H 27 | #define SPI_H 28 | 29 | /* Includes */ 30 | #include 31 | 32 | /* Generic Definitions */ 33 | #define SPIDEV_BYTES_NUM 8 34 | #define SPIDEV_DATA_BITS_NUM 8 35 | #define SPIDEV_DELAY_US 0 36 | #define SPI_SS_HIGH 1 37 | #define SPI_SS_LOW 0 38 | #define SPI_ONE_BYTE 1 39 | 40 | /* No. of bytes per transaction */ 41 | #define NO_OF_BYTES 2 42 | 43 | /*Definitions specific to spidev1.0 */ 44 | #define SPIDEV1_PATH "/dev/spidev1.0" 45 | #define SPIDEV1_BUS_SPEED_HZ 1000000 46 | 47 | 48 | /* Enum SPI Modes*/ 49 | typedef enum{ 50 | SPI_MODE0 = 0, 51 | SPI_MODE1 = 1, 52 | SPI_MODE2 = 2, 53 | SPI_MODE3 = 3 54 | }SPI_MODE; 55 | 56 | /*SPI device configuration structure*/ 57 | typedef struct{ 58 | char* spi_dev_path; 59 | int fd_spi; 60 | unsigned long spi_bytes_num; 61 | unsigned long spi_bus_speedHZ; 62 | unsigned char ss_change; 63 | unsigned short spi_delay_us; 64 | unsigned char spi_data_bits_No; 65 | unsigned char spi_mode; 66 | }SPI_DeviceT, *SPI_DevicePtr; 67 | 68 | class SPI : public QObject 69 | { 70 | Q_OBJECT 71 | public: 72 | explicit SPI(QObject *parent = NULL); 73 | ~SPI(); 74 | 75 | /* SPI API's*/ 76 | int Open_device(char *spi_dev_path, int *fd); 77 | int Set_SPI_mode(int fd, unsigned char spi_mode); 78 | int Set_SPI_bits(int fd, unsigned char bits_per_word); 79 | int Set_SPI_speed(int fd, unsigned long bus_speed_HZ); 80 | void SPI_Config_init(unsigned long spi_bytes_no, unsigned long spi_bus_speed, 81 | unsigned char chip_select, unsigned short spi_delay, 82 | unsigned char spi_bits_No, unsigned char mode_spi, SPI_DevicePtr SPI_devicePtr); 83 | 84 | /* API's to initialize and use spidev1.0 - Configure the Bus as you like*/ 85 | int SPI_DEV1_init(unsigned long spi_bytes_no, unsigned long spi_bus_speed,unsigned char chip_select, unsigned short spi_delay, 86 | unsigned char spi_bits_No, unsigned char mode_spi); 87 | int SPIDEV1_transfer(unsigned char *send, unsigned char *receive, unsigned char bytes_num); 88 | unsigned char SPIDEV1_single_transfer(unsigned char data_byte); 89 | 90 | private: 91 | 92 | signals: 93 | 94 | public slots: 95 | }; 96 | 97 | #endif // SPI_H 98 | -------------------------------------------------------------------------------- /Plot-Real-Time-Graphs-Qt-Example/Qt_Test/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 480 10 | 270 11 | 12 | 13 | 14 | BlankCursor 15 | 16 | 17 | MainWindow 18 | 19 | 20 | 21 | 22 | 23 | 10 24 | 0 25 | 321 26 | 31 27 | 28 | 29 | 30 | 31 | Source Code Pro 32 | 11 33 | 75 34 | true 35 | 36 | 37 | 38 | BlankCursor 39 | 40 | 41 | Powered by: www.deeplyembedded.org 42 | 43 | 44 | false 45 | 46 | 47 | 48 | 49 | 50 | 10 51 | 30 52 | 321 53 | 211 54 | 55 | 56 | 57 | BlankCursor 58 | 59 | 60 | 61 | 62 | 63 | 340 64 | 30 65 | 131 66 | 31 67 | 68 | 69 | 70 | 71 | 27 72 | true 73 | 74 | 75 | 76 | BlankCursor 77 | 78 | 79 | QFrame::NoFrame 80 | 81 | 82 | QFrame::Plain 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 340 92 | 140 93 | 131 94 | 71 95 | 96 | 97 | 98 | BlankCursor 99 | 100 | 101 | Qt::NoFocus 102 | 103 | 104 | PRESS ME 105 | 106 | 107 | 108 | 109 | 110 | 340 111 | 80 112 | 131 113 | 41 114 | 115 | 116 | 117 | 118 | Century Schoolbook L 119 | 13 120 | true 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | QCustomPlot 134 | QWidget 135 |
qcustomplot.h
136 | 1 137 |
138 |
139 | 140 | 141 |
142 | -------------------------------------------------------------------------------- /Plot-Real-Time-Graphs-Qt-Example/Qt_Test/ad7190.h: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | Copyright (c) 2017 DeeplyEmbedded 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | SOFTWARE. 19 | * ad7190.h 20 | * 21 | * Created on : Dec 10, 2017 22 | * Author : Vinay Divakar 23 | * Description : This is a Library for communicating with the AD7190 ADC using the BeagleBone Black. 24 | * website : www.deeplyemebedded.org 25 | */ 26 | 27 | #ifndef AD7190_H 28 | #define AD7190_H 29 | 30 | /* Includes */ 31 | #include 32 | 33 | /* To inherit from SPI */ 34 | #include "spi.h" 35 | 36 | /* Commands to write to specific registers */ 37 | #define COM_WRITE_CONFIG_REG_CMD 0x10 38 | #define COM_WRITE_MODE_REG_CMD 0x08 39 | #define COM_WRITE_GPCON_RED_CMD 0x28 40 | 41 | /* Commands to read from specific registers */ 42 | #define COM_READ_CONFIG_REG_CMD 0x50 43 | #define COM_READ_STATUS_REG_CMD 0x40 44 | #define COM_READ_MODE_REG_CMD 0x48 45 | #define COM_READ_DATA_REG_CMD 0x58 46 | #define COM_READ_GPCON_REG_CMD 0x68 47 | #define COM_READ_ID_REG_CMD 0x60 48 | #define COM_READ_OFFSET_REG_CMD 0x70 49 | #define COM_READ_FULL_SCALE_REG_CMD 0x78 50 | 51 | /* Sampling Rates */ 52 | #define FS_100_HZ 0x30 53 | #define FS_1200_HZ 0x04 54 | #define FS_960_HZ 0x05 55 | #define FS_2400_HZ 0x02 56 | 57 | /* Register settings commands for Configuration Register */ 58 | #define CONFIG_REG_CMD_MSB 0x08 //Gain = 1 and Uni-Polar(0x08) 59 | #define CONFIG_REG_CMD_MID 0x02 60 | 61 | /*May have to change Gain depending on input signal voltage 62 | See Table 19 in AD7190 datasheet for more information*/ 63 | #define CONFIG_REG_CMD_LSB 0x00 64 | 65 | /* Register settings commands for Mode Register */ 66 | #define MODE_REG_CMD_MSB 0x08 67 | #define MODE_REG_CMD_MID 0x00 68 | #define MODE_REG_CMD_LSB FS_100_HZ 69 | 70 | /* Read the data register continously and place the data on DOUT */ 71 | #define COMM_REG_CREAD 0x5C 72 | 73 | /* Generic definitions can be added here */ 74 | #define READ_ADC_DATA_SIZE 3 75 | 76 | 77 | /* Structure Map of AD7190 internal registers 78 | * for read and write operations 79 | */ 80 | typedef struct{ 81 | unsigned char cmd_rd_status_reg; 82 | unsigned char cmd_wr_mode_reg; 83 | unsigned char cmd_rd_mode_reg; 84 | unsigned char cmd_wr_config_reg; 85 | unsigned char cmd_rd_config_reg; 86 | unsigned char cmd_rd_data_reg; 87 | unsigned char cmd_rd_ID_reg; 88 | unsigned char cmd_rd_gpocon_reg; 89 | unsigned char cmd_wr_gpocon_reg; 90 | unsigned char cmd_rd_offset_reg; 91 | unsigned char cmd_rd_full_scale_reg; 92 | }AD7190_REG_T, *AD7190_REG_Ptr; 93 | 94 | /* Enum commands to dump register contents */ 95 | typedef enum{ 96 | DUMP_CONFIG_REG_CONTENTS, 97 | DUMP_MODE_REG_CONTENTS, 98 | DUMP_STATUS_REG_CONTENTS, 99 | DUMP_ID_REG_CONTENTS, 100 | DUMP_CONFIG_AND_MODE_REG_CONTENTS 101 | }REG_DumpT; 102 | 103 | class AD7190 : public SPI 104 | { 105 | Q_OBJECT 106 | private: 107 | AD7190_REG_T ad7190_obj; 108 | void init_AD7190_reg_cmds(AD7190_REG_Ptr ad7190_reg_ptr); 109 | void init_AD7190_cmds(); 110 | 111 | public: 112 | AD7190(); 113 | ~AD7190(); 114 | char AD7190_configure(unsigned char cbyte_2, unsigned char cbyte_1, unsigned char cbyte_0); 115 | char AD7190_mode(unsigned char mbyte_2, unsigned char mbyte_1, unsigned char mbyte_fs); 116 | void AD7190_reset(); 117 | unsigned char AD7190_get_ID(); 118 | unsigned char AD7190_read_status_reg(); 119 | void AD7190_dump_regs(REG_DumpT regs_to_dump); 120 | unsigned long AD7190_read_data(); 121 | 122 | signals: 123 | void new_adc_data(unsigned long adc_data); 124 | 125 | public slots: 126 | void AD7190_init_thread(); 127 | 128 | }; 129 | 130 | #endif // AD7190_H 131 | -------------------------------------------------------------------------------- /Plot-Real-Time-Graphs-Qt-Example/Qt_Test/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * mainwindow.cpp 3 | * 4 | * Created on : Dec 10, 2017 5 | * Author : Vinay Divakar 6 | * website : www.deeplyemebedded.org 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "mainwindow.h" 14 | #include "ui_mainwindow.h" 15 | #include "ad7190.h" 16 | 17 | /* Global objects */ 18 | SPI spi_device1; 19 | 20 | MainWindow::MainWindow(QWidget *parent) : 21 | QMainWindow(parent), 22 | ui(new Ui::MainWindow) 23 | { 24 | ui->setupUi(this); 25 | setWindowFlags(Qt::FramelessWindowHint); 26 | setWindowFlags(Qt::Window | Qt::FramelessWindowHint); 27 | QWSServer::setCursorVisible(false); 28 | this->setStyleSheet("background-color: white;"); 29 | 30 | /* Initialize SPI */ 31 | if (spi_device1.SPI_DEV1_init(SPIDEV_BYTES_NUM, SPIDEV1_BUS_SPEED_HZ, SPI_SS_LOW, 32 | SPIDEV_DELAY_US, SPIDEV_DATA_BITS_NUM, 33 | SPI_MODE3) == -1) 34 | qDebug()<<"(Main)spidev1.0 initialization failed\r\n"; 35 | 36 | else 37 | qDebug()<<"(Main)spidev1.0 initialized - READY\r\n"; 38 | 39 | /* Configure font settings for Label */ 40 | QFont font; 41 | font.setPointSize(21); 42 | font.setItalic(true); 43 | font.setBold(true); 44 | ui->label_adc_data->setFont(font); 45 | ui->label_adc_data->setAlignment(Qt::AlignCenter); 46 | ui->label_adc_data->setStyleSheet("background-color : white; color : green;"); 47 | 48 | /* Configure setup for Thank You Label */ 49 | ui->label_ty->setAlignment(Qt::AlignCenter); 50 | ui->label_ty->setStyleSheet("background-color : white; color : black;"); 51 | 52 | /* Align the intro label appropriately */ 53 | ui->label_intro->setAlignment(Qt::AlignCenter); 54 | ui->label_intro->setStyleSheet("background-color : white; color : black;"); 55 | 56 | /* Thread to continously sample and read the data */ 57 | QThread *thread = new QThread; 58 | AD7190 *ad7190_dev = new AD7190(); 59 | ad7190_dev->moveToThread(thread); 60 | connect(thread,SIGNAL(started()),ad7190_dev,SLOT(AD7190_init_thread())); 61 | connect(ad7190_dev, SIGNAL(new_adc_data(ulong)),this,SLOT(display_data(ulong))); 62 | thread->start(); 63 | 64 | /* Add graph and set the curve line color to green */ 65 | ui->CustomPlot->addGraph(); 66 | ui->CustomPlot->graph(0)->setPen(QPen(Qt::red)); 67 | ui->CustomPlot->graph(0)->setAntialiasedFill(false); 68 | 69 | /* Configure x-Axis as time in secs */ 70 | QSharedPointer timeTicker(new QCPAxisTickerTime); 71 | timeTicker->setTimeFormat("%s"); 72 | ui->CustomPlot->xAxis->setTicker(timeTicker); 73 | ui->CustomPlot->axisRect()->setupFullAxesBox(); 74 | 75 | 76 | /* Configure x and y-Axis to display Labels */ 77 | ui->CustomPlot->xAxis->setTickLabelFont(QFont(QFont().family(),8)); 78 | ui->CustomPlot->yAxis->setTickLabelFont(QFont(QFont().family(),8)); 79 | ui->CustomPlot->xAxis->setLabel("Time(s)"); 80 | ui->CustomPlot->yAxis->setLabel("ADC Raw Counts"); 81 | 82 | /* Make top and right axis visible, but without ticks and label */ 83 | ui->CustomPlot->xAxis2->setVisible(true); 84 | ui->CustomPlot->yAxis->setVisible(true); 85 | ui->CustomPlot->xAxis2->setTicks(false); 86 | ui->CustomPlot->yAxis2->setTicks(false); 87 | ui->CustomPlot->xAxis2->setTickLabels(false); 88 | ui->CustomPlot->yAxis2->setTickLabels(false); 89 | 90 | /* Set up and initialize the graph plotting timer */ 91 | connect(&timer_plot, SIGNAL(timeout()),this,SLOT(realtimePlot())); 92 | timer_plot.start(5); 93 | } 94 | 95 | MainWindow::~MainWindow() 96 | { 97 | delete ui; 98 | } 99 | 100 | /**************************************************************** 101 | * Function Name : display_data 102 | * Description : Displays ADC data on the GUI 103 | * Returns : None 104 | * Params @adc_data: Data to be displayed 105 | ****************************************************************/ 106 | void MainWindow::display_data(unsigned long adc_data) 107 | { 108 | /* Discard the noisy bits */ 109 | adc_data = adc_data/100; 110 | 111 | /* Support the plotter */ 112 | adc_data_g = adc_data; 113 | 114 | /* Prepare to display the data */ 115 | QString adc_data_str = " "; 116 | adc_data_str = QString::number(adc_data); 117 | ui->label_adc_data->setText(adc_data_str); 118 | } 119 | 120 | /**************************************************************** 121 | * Function Name : realtimePlot 122 | * Description : Displays the real time graph on the GUI 123 | * Returns : None 124 | * Params : None 125 | ****************************************************************/ 126 | void MainWindow::realtimePlot() 127 | { 128 | static QTime time(QTime::currentTime()); 129 | double key = time.elapsed()/1000.0; 130 | static double lastPointKey = 0; 131 | if(key - lastPointKey > 0.002) 132 | { 133 | ui->CustomPlot->graph(0)->addData(key, (double)adc_data_g); 134 | lastPointKey = key; 135 | } 136 | 137 | /* make key axis range scroll right with the data at a constant range of 8. */ 138 | ui->CustomPlot->graph(0)->rescaleValueAxis(); 139 | ui->CustomPlot->xAxis->setRange(key, 8, Qt::AlignRight); 140 | ui->CustomPlot->replot(); 141 | } 142 | 143 | /**************************************************************** 144 | * Function Name : on_pushButton_released 145 | * Description : Displays THANK YOU! when pressed and released 146 | * Returns : None 147 | * Params : None 148 | ****************************************************************/ 149 | void MainWindow::on_pushButton_released() 150 | { 151 | ui->label_ty->setText("THANK YOU!"); 152 | } 153 | -------------------------------------------------------------------------------- /Plot-Real-Time-Graphs-Qt-Example/Qt_Test/spi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | Copyright (c) 2017 DeeplyEmbedded 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | * spi.c 22 | * 23 | * Created on : Nov 12, 2017 24 | * Author : Vinay Divakar 25 | * Description : This is an SPI Library for the BeagleBone that consists of the API's to enable 26 | full duplex SPI transactions. 27 | * Note : This Library has been tested to work in all the modes i.e. SPI_MODE0, SPI_MODE1, 28 | * SPI_MODE2 and SPI_MODE3. At present, this Library only supports spidev1.0, however 29 | * it can be extended to support other spidev1.x or spidev2.x as well. 30 | * website : www.deeplyemebedded.org 31 | */ 32 | 33 | /*Custom Libs Includes*/ 34 | #include "spi.h" 35 | 36 | /*Lib Includes*/ 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | /* Qt Includes */ 45 | #include 46 | 47 | /* Enable debug prints */ 48 | //#define DBG 49 | 50 | /* Static Objects */ 51 | static SPI_DeviceT SPI_device1; 52 | static struct spi_ioc_transfer transfer_spidev1; 53 | 54 | SPI::SPI(QObject *parent) : QObject(parent) 55 | { 56 | 57 | } 58 | 59 | SPI::~SPI() 60 | { 61 | 62 | } 63 | 64 | /**************************************************************** 65 | * Function Name : Open_device 66 | * Description : Opens the SPI device to use 67 | * Returns : 0 on success, -1 on failure 68 | * Params @spi_dev_path: Path to the SPI device 69 | * @fd: Variable to store the file handler 70 | ****************************************************************/ 71 | int SPI::Open_device(char *spi_dev_path, int *fd) 72 | { 73 | if((*fd = open(spi_dev_path, O_RDWR))<0) 74 | return -1; 75 | else 76 | return 0; 77 | } 78 | 79 | /**************************************************************** 80 | * Function Name : Set_SPI_mode 81 | * Description : Set the SPI mode of operation 82 | * Returns : 0 on success, -1 on failure 83 | * Params @fd: File handler 84 | * @spi_mode: SPI Mode 85 | ****************************************************************/ 86 | int SPI::Set_SPI_mode(int fd, unsigned char spi_mode) 87 | { 88 | int ret = 0; 89 | if(ioctl(fd, SPI_IOC_WR_MODE, &spi_mode)==-1) 90 | ret = -1; 91 | if(ioctl(fd, SPI_IOC_RD_MODE, &spi_mode)==-1) 92 | ret = -1; 93 | return (ret); 94 | } 95 | 96 | /**************************************************************** 97 | * Function Name : Set_SPI_bits 98 | * Description : Set the No. of bits/transaction 99 | * Returns : 0 on success, -1 on failure 100 | * Params @fd: File handler 101 | * @bits_per_word: No. of bits 102 | ****************************************************************/ 103 | int SPI::Set_SPI_bits(int fd, unsigned char bits_per_word) 104 | { 105 | int ret = 0; 106 | if(ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits_per_word)==-1) 107 | ret = -1; 108 | if(ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits_per_word)==-1) 109 | ret = -1; 110 | return (ret); 111 | } 112 | 113 | /**************************************************************** 114 | * Function Name : Set_SPI_speed 115 | * Description : Set the SPI bus frequency in Hertz(Hz) 116 | * Returns : 0 on success, -1 on failure 117 | * Params @fd: File handler 118 | * @bus_speed_HZ: Bus speed 119 | ****************************************************************/ 120 | int SPI::Set_SPI_speed(int fd, unsigned long bus_speed_HZ) 121 | { 122 | int ret = 0; 123 | if(ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &bus_speed_HZ)==-1) 124 | ret = -1; 125 | if(ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &bus_speed_HZ)==-1) 126 | ret = -1; 127 | return (ret); 128 | } 129 | 130 | /**************************************************************** 131 | * Function Name : SPI_Config_init 132 | * Description : Initialization configuration for the SPI 133 | * device 134 | * Returns : None 135 | * Params @spi_bytes_no: File handler 136 | * @spi_bus_speed: Bus speed 137 | * @chip_select: chip select line 138 | * @spi_delay: delay in us 139 | * @spi_bits_No: No. of bits/transaction 140 | * @mode_spi: SPI Mode 141 | * @SPI_devicePtr: Points to the SPI device 142 | * configuration structure. 143 | ****************************************************************/ 144 | void SPI::SPI_Config_init(unsigned long spi_bytes_no, unsigned long spi_bus_speed, unsigned char chip_select, 145 | unsigned short spi_delay, unsigned char spi_bits_No, unsigned char mode_spi, SPI_DevicePtr SPI_devicePtr) 146 | { 147 | SPI_devicePtr->spi_bytes_num = spi_bytes_no; 148 | SPI_devicePtr->spi_bus_speedHZ = spi_bus_speed; 149 | SPI_devicePtr->ss_change = chip_select; 150 | SPI_devicePtr->spi_delay_us = spi_delay; 151 | SPI_devicePtr->spi_data_bits_No = spi_bits_No; 152 | SPI_devicePtr->spi_mode = mode_spi; 153 | SPI_devicePtr->fd_spi = 0; 154 | SPI_devicePtr->spi_dev_path = NULL; 155 | } 156 | 157 | /**************************************************************** 158 | * Function Name : SPI_DEV_init 159 | * Description : Initialize and set up spidev1.x 160 | * Returns : 0 on success, -1 on failure 161 | * Params : None 162 | ****************************************************************/ 163 | int SPI::SPI_DEV1_init(unsigned long spi_bytes_no, unsigned long spi_bus_speed,unsigned char chip_select, unsigned short spi_delay, 164 | unsigned char spi_bits_No, unsigned char mode_spi) 165 | { 166 | /*Initialize the parameters for spidev1.0 structure */ 167 | SPI_Config_init(spi_bytes_no, spi_bus_speed, chip_select, 168 | spi_delay, spi_bits_No, mode_spi, &SPI_device1); 169 | 170 | /* Assign the path to the spidev1.0 for use */ 171 | SPI_device1.spi_dev_path = (char*)SPIDEV1_PATH; 172 | 173 | /* Open the spidev1.0 device */ 174 | if(Open_device(SPI_device1.spi_dev_path, &SPI_device1.fd_spi) == -1) 175 | { 176 | perror("SPI: Failed to open spidev1.0 |"); 177 | return -1; 178 | } 179 | 180 | /* Set the SPI mode for RD and WR operations */ 181 | if(Set_SPI_mode(SPI_device1.fd_spi, SPI_device1.spi_mode) == -1) 182 | { 183 | perror("SPI: Failed to set SPIMODE |"); 184 | return -1; 185 | } 186 | 187 | /* Set the No. of bits per transaction */ 188 | if(Set_SPI_bits(SPI_device1.fd_spi, SPI_device1.spi_data_bits_No) == -1) 189 | { 190 | perror("SPI: Failed to set No. of bits per word |"); 191 | return -1; 192 | } 193 | 194 | /* Set the SPI bus speed in Hz */ 195 | if(Set_SPI_speed(SPI_device1.fd_spi, SPI_device1.spi_bus_speedHZ) == -1) 196 | { 197 | perror("SPI: Failed to set SPI bus frequency |"); 198 | return -1; 199 | } 200 | 201 | #ifdef DBG 202 | qDebug("(SPI_DEV1_init)SPI device path = %s", SPI_device1.spi_dev_path); 203 | qDebug("(SPI_DEV1_init)SPI Lengtth = %lu", SPI_device1.spi_bytes_num); 204 | qDebug("(SPI_DEV1_init)SPI Hz = %lu", SPI_device1.spi_bus_speedHZ); 205 | qDebug("(SPI_DEV1_init)SPI bits per word = %d", SPI_device1.spi_data_bits_No); 206 | qDebug("(SPI_DEV1_init)SPI delay = %d", SPI_device1.spi_delay_us); 207 | qDebug("(SPI_DEV1_init)SPI Mode = %d", SPI_device1.spi_mode); 208 | qDebug("(SPI_DEV1_init)SPI fd = %d", SPI_device1.fd_spi); 209 | qDebug("(SPI_DEV1_init)SPI ss = %d", SPI_device1.ss_change); 210 | #endif 211 | 212 | /* Initialize the spi_ioc_transfer structure that will be passed to the 213 | * KERNEL to define/configure each SPI Transactions*/ 214 | transfer_spidev1.tx_buf = 0; 215 | transfer_spidev1.rx_buf = 0; 216 | transfer_spidev1.pad = 0; 217 | transfer_spidev1.tx_nbits = 0; 218 | transfer_spidev1.rx_nbits = 0; 219 | transfer_spidev1.len = SPI_device1.spi_bytes_num; 220 | transfer_spidev1.speed_hz = SPI_device1.spi_bus_speedHZ; 221 | transfer_spidev1.delay_usecs = SPI_device1.spi_delay_us; 222 | transfer_spidev1.bits_per_word = SPI_device1.spi_data_bits_No; 223 | transfer_spidev1.cs_change = SPI_device1.ss_change; 224 | 225 | #ifdef DBG 226 | qDebug("(SPI_DEV1_init)transfer_spidev1 tx_buf = %llu", transfer_spidev1.tx_buf); 227 | qDebug("(SPI_DEV1_init)transfer_spidev1 rx_buf = %llu", transfer_spidev1.rx_buf); 228 | qDebug("(SPI_DEV1_init)transfer_spidev1 tx_nbits = %d", transfer_spidev1.tx_nbits); 229 | qDebug("(SPI_DEV1_init)transfer_spidev1 rx_nbits = %d", transfer_spidev1.rx_nbits); 230 | qDebug("(SPI_DEV1_init)transfer_spidev1 pad = %d", transfer_spidev1.pad); 231 | qDebug("(SPI_DEV1_init)transfer_spidev1 len = %d", transfer_spidev1.len); 232 | qDebug("(SPI_DEV1_init)transfer_spidev1 speed_hz = %d", transfer_spidev1.speed_hz); 233 | qDebug("(SPI_DEV1_init)transfer_spidev1 delay_usecs = %d", transfer_spidev1.delay_usecs); 234 | qDebug("(SPI_DEV1_init)transfer_spidev1 bits per word = %d", transfer_spidev1.bits_per_word); 235 | qDebug("(SPI_DEV1_init)transfer_spidev1 cs_change = %d", transfer_spidev1.cs_change); 236 | qDebug("-------------------------------------------------------------------------------------"); 237 | #endif 238 | 239 | return 0; 240 | } 241 | 242 | /**************************************************************** 243 | * Function Name : SPIDEV1_transfer 244 | * Description : Performs a SPI transaction 245 | * Returns : 0 on success, -1 on failure 246 | * Params @send: Points to the buffer containing the data 247 | * to be sent 248 | * @receive: Points to the buffer into which the 249 | * received bytes are stored 250 | * NOTE : Good for multiple transactions 251 | ****************************************************************/ 252 | int SPI::SPIDEV1_transfer(unsigned char *send, unsigned char *receive, unsigned char bytes_num) 253 | { 254 | /* Points to the Tx and Rx buffer */ 255 | transfer_spidev1.tx_buf = (unsigned long)send; 256 | transfer_spidev1.rx_buf = (unsigned long)receive; 257 | 258 | /* Override No. of bytes per transaction */ 259 | transfer_spidev1.len = bytes_num; 260 | 261 | /* Perform a SPI Transaction */ 262 | if (ioctl(SPI_device1.fd_spi, SPI_IOC_MESSAGE(1), &transfer_spidev1)<0) 263 | { 264 | perror("SPI: SPI_IOC_MESSAGE Failed |"); 265 | return -1; 266 | } 267 | return 0; 268 | } 269 | 270 | /**************************************************************** 271 | * Function Name : SPIDEV1_single_transfer 272 | * Description : Performs a single full duplex SPI transaction 273 | * Returns : 0 or data on success, -1 on failure 274 | * Params @data_byte: Points to the address of the variable 275 | * containing the data to be sent. 276 | * NOTE : Good for single transactions 277 | ****************************************************************/ 278 | unsigned char SPI::SPIDEV1_single_transfer(unsigned char data_byte) 279 | { 280 | unsigned char rec_byte = 0; 281 | 282 | #ifdef DBG 283 | qDebug("(SPIDEV1_single_transfer)data_byte = %d", data_byte); 284 | #endif 285 | 286 | /* Override No. of bytes to send and receive one byte */ 287 | transfer_spidev1.len = SPI_ONE_BYTE; 288 | 289 | /* Points to the address of Tx and Rx variable */ 290 | transfer_spidev1.tx_buf = (unsigned long)&data_byte; 291 | transfer_spidev1.rx_buf = (unsigned long)&rec_byte; 292 | 293 | #ifdef DBG 294 | qDebug("(SPIDEV1_single_transfer)SPI device path = %s", SPI_device1.spi_dev_path); 295 | qDebug("(SPIDEV1_single_transfer)SPI Lengtth = %lu", SPI_device1.spi_bytes_num); 296 | qDebug("(SPIDEV1_single_transfer)SPI Hz = %lu", SPI_device1.spi_bus_speedHZ); 297 | qDebug("(SPIDEV1_single_transfer)SPI bits per word = %d", SPI_device1.spi_data_bits_No); 298 | qDebug("(SPIDEV1_single_transfer)SPI delay = %d", SPI_device1.spi_delay_us); 299 | qDebug("(SPIDEV1_single_transfer)SPI Mode = %d", SPI_device1.spi_mode); 300 | qDebug("(SPIDEV1_single_transfer)SPI fd = %d", SPI_device1.fd_spi); 301 | qDebug("(SPIDEV1_single_transfer)SPI ss = %d", SPI_device1.ss_change); 302 | 303 | qDebug("(SPIDEV1_single_transfer)transfer_spidev1 tx_buf = %lu", (unsigned long)transfer_spidev1.tx_buf); 304 | qDebug("(SPIDEV1_single_transfer)transfer_spidev1 rx_buf = %lu", (unsigned long)transfer_spidev1.rx_buf); 305 | qDebug("(SPIDEV1_single_transfer)transfer_spidev1 tx_nbits = %d", transfer_spidev1.tx_nbits); 306 | qDebug("(SPIDEV1_single_transfer)transfer_spidev1 rx_nbits = %d", transfer_spidev1.rx_nbits); 307 | qDebug("(SPIDEV1_single_transfer)transfer_spidev1 pad = %d", transfer_spidev1.pad); 308 | qDebug("(SPIDEV1_single_transfer)transfer_spidev1 len = %d", transfer_spidev1.len); 309 | qDebug("(SPIDEV1_single_transfer)transfer_spidev1 speed_hz = %d", transfer_spidev1.speed_hz); 310 | qDebug("(SPIDEV1_single_transfer)transfer_spidev1 delay_usecs = %d", transfer_spidev1.delay_usecs); 311 | qDebug("(SPIDEV1_single_transfer)transfer_spidev1 bits per word = %d", transfer_spidev1.bits_per_word); 312 | qDebug("(SPIDEV1_single_transfer)transfer_spidev1 cs_change = %d", transfer_spidev1.cs_change); 313 | #endif 314 | 315 | /* Perform an SPI Transaction */ 316 | if (ioctl(SPI_device1.fd_spi, SPI_IOC_MESSAGE(1), &transfer_spidev1)<0) 317 | { 318 | perror("SPI: SPI_IOC_MESSAGE Failed |"); 319 | rec_byte = -1; 320 | } 321 | 322 | return (rec_byte); 323 | } 324 | -------------------------------------------------------------------------------- /Plot-Real-Time-Graphs-Qt-Example/Qt_Test/ad7190.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | Copyright (c) 2017 DeeplyEmbedded 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | SOFTWARE. 19 | * ad7190.cpp 20 | * 21 | * Created on : Dec 10, 2017 22 | * Author : Vinay Divakar 23 | * Description : This is a Library for communicating with the AD7190 ADC using the BeagleBone Black. 24 | * website : www.deeplyemebedded.org 25 | */ 26 | 27 | /* Includes */ 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "ad7190.h" 34 | 35 | /* Debug Utilities */ 36 | #define AD7190_DBG 37 | 38 | /* Constructor will initialize the AD7190 commands */ 39 | AD7190::AD7190() 40 | { 41 | init_AD7190_cmds(); 42 | } 43 | 44 | AD7190::~AD7190() 45 | { 46 | 47 | } 48 | 49 | /**************************************************************** 50 | * Function Name : init_AD7190_reg_cmds 51 | * Description : API to initialize the AD7190 commands structure 52 | * for communication 53 | * Returns : None 54 | * Params @ad7190_reg_ptr: Pointer to commands structure 55 | ****************************************************************/ 56 | void AD7190::init_AD7190_reg_cmds(AD7190_REG_Ptr ad7190_reg_ptr) 57 | { 58 | ad7190_reg_ptr->cmd_rd_ID_reg = COM_READ_ID_REG_CMD; 59 | ad7190_reg_ptr->cmd_rd_config_reg = COM_READ_CONFIG_REG_CMD; 60 | ad7190_reg_ptr->cmd_rd_data_reg = COM_READ_DATA_REG_CMD; 61 | ad7190_reg_ptr->cmd_rd_full_scale_reg = COM_READ_FULL_SCALE_REG_CMD; 62 | ad7190_reg_ptr->cmd_rd_gpocon_reg = COM_READ_GPCON_REG_CMD; 63 | ad7190_reg_ptr->cmd_rd_mode_reg = COM_READ_MODE_REG_CMD; 64 | ad7190_reg_ptr->cmd_rd_offset_reg = COM_READ_OFFSET_REG_CMD; 65 | ad7190_reg_ptr->cmd_rd_status_reg = COM_READ_STATUS_REG_CMD; 66 | ad7190_reg_ptr->cmd_wr_gpocon_reg = COM_WRITE_GPCON_RED_CMD; 67 | ad7190_reg_ptr->cmd_wr_config_reg = COM_WRITE_CONFIG_REG_CMD; 68 | ad7190_reg_ptr->cmd_wr_mode_reg = COM_WRITE_MODE_REG_CMD; 69 | } 70 | 71 | 72 | /**************************************************************** 73 | * Function Name : init_AD7190_cmds 74 | * Description : Initialize the AD7190 commands structure 75 | * for communication 76 | * Returns : None 77 | * Params : None 78 | ****************************************************************/ 79 | void AD7190::init_AD7190_cmds() 80 | { 81 | init_AD7190_reg_cmds(&ad7190_obj); 82 | 83 | #ifdef AD7190_DBG 84 | qDebug("[init_AD7190_cmds]cmd_rd_ID_reg = 0X%x", ad7190_obj.cmd_rd_ID_reg); 85 | qDebug("[init_AD7190_cmds]cmd_rd_config_reg = 0X%x", ad7190_obj.cmd_rd_config_reg); 86 | qDebug("[init_AD7190_cmds]cmd_rd_data_reg = 0X%x", ad7190_obj.cmd_rd_data_reg); 87 | qDebug("[init_AD7190_cmds]cmd_rd_full_scale_reg = 0X%x", ad7190_obj.cmd_rd_full_scale_reg); 88 | qDebug("[init_AD7190_cmds]cmd_rd_gpocon_reg = 0X%x", ad7190_obj.cmd_rd_gpocon_reg); 89 | qDebug("[init_AD7190_cmds]cmd_rd_mode_reg = 0X%x", ad7190_obj.cmd_rd_mode_reg); 90 | qDebug("[init_AD7190_cmds]cmd_rd_offset_reg = 0X%x", ad7190_obj.cmd_rd_offset_reg); 91 | qDebug("[init_AD7190_cmds]cmd_rd_status_reg = 0X%x", ad7190_obj.cmd_rd_status_reg); 92 | qDebug("[init_AD7190_cmds]cmd_wr_gpocon_reg = 0X%x", ad7190_obj.cmd_wr_gpocon_reg); 93 | qDebug("[init_AD7190_cmds]cmd_wr_config_reg = 0X%x", ad7190_obj.cmd_wr_config_reg); 94 | qDebug("[init_AD7190_cmds]cmd_wr_mode_reg = 0X%x", ad7190_obj.cmd_wr_mode_reg); 95 | qDebug("\r\n"); 96 | #endif 97 | 98 | } 99 | 100 | 101 | /**************************************************************** 102 | * Function Name : AD7190_configure 103 | * Description : Configure/Write to the configuration register 104 | * for communication 105 | * Returns : (-1) typecast for error, 0 for success 106 | * Params @cbyte_2: Data to write to Most Significant Byte 107 | * @cbyte_1: Data to write to Middle Byte 108 | * @cbyte_0: Data to write to Least Significant Byte 109 | ****************************************************************/ 110 | char AD7190::AD7190_configure(unsigned char cbyte_2, unsigned char cbyte_1, unsigned char cbyte_0) 111 | { 112 | char check_ret = 0x00; 113 | unsigned char ad7190_id = 0x00; 114 | 115 | ad7190_id = AD7190_get_ID(); 116 | qDebug("Initializing AD7190 ADC Device ID = 0x%x", ad7190_id); 117 | 118 | #ifdef AD7190_DBG 119 | qDebug("[AD7190_configure]cmd_wr_config_reg = 0X%x", ad7190_obj.cmd_wr_config_reg); 120 | #endif 121 | 122 | /* Go to write to configuration register */ 123 | check_ret = SPIDEV1_single_transfer(ad7190_obj.cmd_wr_config_reg); 124 | 125 | /* Write to Most Significant Byte */ 126 | check_ret = SPIDEV1_single_transfer(cbyte_2); 127 | 128 | /* Write to Mid Byte */ 129 | check_ret = SPIDEV1_single_transfer(cbyte_1); 130 | 131 | /* Write to Least Significant Byte */ 132 | check_ret = SPIDEV1_single_transfer(cbyte_0); 133 | 134 | return (check_ret); 135 | } 136 | 137 | 138 | /**************************************************************** 139 | * Function Name : AD7190_mode 140 | * Description : Configure/Write to the mode register 141 | * for communication 142 | * Returns : (-1) typecast for error, 0 for success 143 | * Params @mbyte_2: Data to write to Most Significant Byte 144 | * @mbyte_1: Data to write to Middle Byte 145 | * @mbyte_fs: Data to write to Least Significant Byte 146 | ****************************************************************/ 147 | char AD7190::AD7190_mode(unsigned char mbyte_2, unsigned char mbyte_1, unsigned char mbyte_fs) 148 | { 149 | char check_ret = 0x00; 150 | 151 | #ifdef AD7190_DBG 152 | qDebug("[init_AD7190_cmds]cmd_wr_mode_reg = 0X%x", ad7190_obj.cmd_wr_mode_reg); 153 | #endif 154 | 155 | /* Go to write to configuration register */ 156 | check_ret = SPIDEV1_single_transfer(ad7190_obj.cmd_wr_mode_reg); 157 | 158 | /* Write to Most Significant Byte */ 159 | check_ret = SPIDEV1_single_transfer(mbyte_2); 160 | 161 | /* Write to Mid Byte */ 162 | check_ret = SPIDEV1_single_transfer(mbyte_1); 163 | 164 | /* Write to Least Significant Byte */ 165 | check_ret = SPIDEV1_single_transfer(mbyte_fs); 166 | 167 | return (check_ret); 168 | } 169 | 170 | 171 | /**************************************************************** 172 | * Function Name : AD7190_read_status_reg 173 | * Description : Read the status register 174 | * Returns : Contents of the status register 175 | * Params : None 176 | ****************************************************************/ 177 | unsigned char AD7190::AD7190_read_status_reg() 178 | { 179 | unsigned char status_reg = 0x00; 180 | 181 | SPIDEV1_single_transfer(ad7190_obj.cmd_rd_status_reg); 182 | status_reg = SPIDEV1_single_transfer(0x00); 183 | return (status_reg); 184 | } 185 | 186 | 187 | /**************************************************************** 188 | * Function Name : AD7190_get_ID 189 | * Description : Read the ID register 190 | * Returns : Contents of the ID register 191 | * Params : None 192 | ****************************************************************/ 193 | unsigned char AD7190::AD7190_get_ID() 194 | { 195 | unsigned char ad7190_ID = 0x00; 196 | 197 | SPIDEV1_single_transfer(ad7190_obj.cmd_rd_ID_reg); 198 | ad7190_ID = SPIDEV1_single_transfer(0x00); 199 | return (ad7190_ID); 200 | } 201 | 202 | 203 | /**************************************************************** 204 | * Function Name : AD7190_reset 205 | * Description : Resets the AD7190 206 | * Returns : None 207 | * Params : None 208 | ****************************************************************/ 209 | void AD7190::AD7190_reset() 210 | { 211 | char cnt; 212 | 213 | for(cnt = 0 ; cnt < 5 ; cnt++) 214 | SPIDEV1_single_transfer(0xFF); 215 | } 216 | 217 | 218 | /**************************************************************** 219 | * Function Name : AD7190_read_data 220 | * Description : Read the data register 221 | * Returns : Contents of the data register 222 | * Params : None 223 | ****************************************************************/ 224 | unsigned long AD7190::AD7190_read_data() 225 | { 226 | unsigned char Tx_bytes[2], Rx_bytes[2], reg_status = 0, drdy_bit; 227 | unsigned long adc_data = 0x00; 228 | memset(Tx_bytes, 0xFF, sizeof(Tx_bytes)); 229 | memset(Rx_bytes, 0, sizeof(Rx_bytes)); 230 | drdy_bit = 1; 231 | 232 | reg_status = AD7190_read_status_reg(); 233 | drdy_bit = reg_status & 0x80; 234 | 235 | if (drdy_bit == 0x00) 236 | { 237 | SPIDEV1_single_transfer(ad7190_obj.cmd_rd_data_reg); 238 | if (SPIDEV1_transfer(Tx_bytes, Rx_bytes, READ_ADC_DATA_SIZE) == 0) 239 | { 240 | adc_data = (adc_data | Rx_bytes[0]) << 8; 241 | adc_data = (adc_data | Rx_bytes[1]) << 8; 242 | adc_data = adc_data | Rx_bytes[2]; 243 | } 244 | else 245 | { 246 | printf("(AD7190_read_test)Transaction Failed\r\n"); 247 | adc_data = 0x00; 248 | } 249 | } 250 | else 251 | { 252 | adc_data = 0x00; 253 | } 254 | return (adc_data); 255 | } 256 | 257 | /**************************************************************** 258 | * Function Name : AD7190_init_thread 259 | * Description : API to initialize and start the AD7190 260 | * Returns : None 261 | * Params : None 262 | ****************************************************************/ 263 | void AD7190::AD7190_init_thread() 264 | { 265 | unsigned long adc_raw = 0x00; 266 | 267 | /* Set up the AD7190 */ 268 | AD7190_reset(); 269 | AD7190_configure(CONFIG_REG_CMD_MSB, CONFIG_REG_CMD_MID, CONFIG_REG_CMD_LSB); 270 | AD7190_mode(MODE_REG_CMD_MSB, MODE_REG_CMD_MID, MODE_REG_CMD_LSB); 271 | AD7190_dump_regs(DUMP_CONFIG_AND_MODE_REG_CONTENTS); 272 | 273 | while(1) 274 | { 275 | adc_raw = 0x00; 276 | 277 | /* Read the digitized data */ 278 | adc_raw = AD7190_read_data(); 279 | 280 | /* Check for data validity */ 281 | if(adc_raw != 0x00) 282 | /* emit the new data to the mainwindow thread */ 283 | emit new_adc_data(adc_raw); 284 | } 285 | } 286 | 287 | /**************************************************************** 288 | * Function Name : AD7190_dump_regs 289 | * Description : Dump the contents of the registers 290 | * Returns : None 291 | * Params @regs_to_dump: Registers to dump 292 | ****************************************************************/ 293 | void AD7190::AD7190_dump_regs(REG_DumpT regs_to_dump) 294 | { 295 | unsigned char Tx_bytes[2], Rx_bytes[2], reg_status_id = 0; 296 | unsigned long read_config_mode = 0x00; 297 | memset(Tx_bytes, 0xFF, sizeof(Tx_bytes)); 298 | memset(Rx_bytes, 0, sizeof(Rx_bytes)); 299 | switch(regs_to_dump) 300 | { 301 | case DUMP_CONFIG_REG_CONTENTS: 302 | SPIDEV1_single_transfer(ad7190_obj.cmd_rd_config_reg); 303 | if (SPIDEV1_transfer(Tx_bytes, Rx_bytes, 3) == 0) 304 | { 305 | read_config_mode = (read_config_mode | Rx_bytes[0]) << 8; 306 | read_config_mode = (read_config_mode | Rx_bytes[1]) << 8; 307 | read_config_mode = read_config_mode | Rx_bytes[2]; 308 | qDebug("Dump - Configuration Register = 0X%x",(unsigned int)read_config_mode); 309 | } 310 | else 311 | { 312 | qDebug("(AD7190_dump_regs)Transaction Failed\r\n"); 313 | } 314 | break; 315 | case DUMP_MODE_REG_CONTENTS: 316 | SPIDEV1_single_transfer(ad7190_obj.cmd_rd_mode_reg); 317 | if (SPIDEV1_transfer(Tx_bytes, Rx_bytes, 3) == 0) 318 | { 319 | read_config_mode = (read_config_mode | Rx_bytes[0]) << 8; 320 | read_config_mode = (read_config_mode | Rx_bytes[1]) << 8; 321 | read_config_mode = read_config_mode | Rx_bytes[2]; 322 | qDebug("Dump - Mode Register = 0X%x",(unsigned int)read_config_mode); 323 | } 324 | else 325 | { 326 | qDebug("(AD7190_dump_regs)Transaction Failed\r\n"); 327 | } 328 | break; 329 | case DUMP_STATUS_REG_CONTENTS: 330 | reg_status_id = AD7190_read_status_reg(); 331 | qDebug("Dump - Status Register = 0X%x",reg_status_id); 332 | break; 333 | case DUMP_ID_REG_CONTENTS: 334 | reg_status_id = AD7190_get_ID(); 335 | qDebug("Dump - ID Register = 0X%x",reg_status_id); 336 | break; 337 | case DUMP_CONFIG_AND_MODE_REG_CONTENTS: 338 | default: 339 | SPIDEV1_single_transfer(ad7190_obj.cmd_rd_config_reg); 340 | if (SPIDEV1_transfer(Tx_bytes, Rx_bytes, 3) == 0) 341 | { 342 | read_config_mode = (read_config_mode | Rx_bytes[0]) << 8; 343 | read_config_mode = (read_config_mode | Rx_bytes[1]) << 8; 344 | read_config_mode = read_config_mode | Rx_bytes[2]; 345 | qDebug("Dump - Configuration Register = 0X%x",(unsigned int)read_config_mode); 346 | } 347 | else 348 | { 349 | qDebug("(AD7190_dump_regs)Transaction Failed\r\n"); 350 | } 351 | 352 | memset(Rx_bytes, 0, sizeof(Rx_bytes)); 353 | read_config_mode = 0x00; 354 | 355 | SPIDEV1_single_transfer(ad7190_obj.cmd_rd_mode_reg); 356 | if (SPIDEV1_transfer(Tx_bytes, Rx_bytes, 3) == 0) 357 | { 358 | read_config_mode = (read_config_mode | Rx_bytes[0]) << 8; 359 | read_config_mode = (read_config_mode | Rx_bytes[1]) << 8; 360 | read_config_mode = read_config_mode | Rx_bytes[2]; 361 | qDebug("Dump - Mode Register = 0X%x",(unsigned int)read_config_mode); 362 | } 363 | else 364 | { 365 | qDebug("(AD7190_dump_regs)Transaction Failed\r\n"); 366 | } 367 | break; 368 | } 369 | } 370 | -------------------------------------------------------------------------------- /Plot-Real-Time-Graphs-Qt-Example/Qt_Test/Qt_Test.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {3fa6ded1-cbc4-43d4-9778-ccb3ac11b915} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | BeagleBone 63 | BeagleBone 64 | {63d86feb-a62e-4462-a185-1de797f60632} 65 | 0 66 | 0 67 | 0 68 | 69 | /home/vinaydivakar/build-Qt_Test-BeagleBone-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | false 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | -w 89 | -r 90 | 91 | false 92 | 93 | 94 | 95 | 2 96 | Build 97 | 98 | ProjectExplorer.BuildSteps.Build 99 | 100 | 101 | 102 | true 103 | Make 104 | 105 | Qt4ProjectManager.MakeStep 106 | 107 | -w 108 | -r 109 | 110 | true 111 | clean 112 | 113 | 114 | 1 115 | Clean 116 | 117 | ProjectExplorer.BuildSteps.Clean 118 | 119 | 2 120 | false 121 | 122 | Debug 123 | 124 | Qt4ProjectManager.Qt4BuildConfiguration 125 | 2 126 | true 127 | 128 | 129 | /home/vinaydivakar/build-Qt_Test-BeagleBone-Release 130 | 131 | 132 | true 133 | qmake 134 | 135 | QtProjectManager.QMakeBuildStep 136 | false 137 | 138 | false 139 | false 140 | false 141 | 142 | 143 | true 144 | Make 145 | 146 | Qt4ProjectManager.MakeStep 147 | 148 | -w 149 | -r 150 | 151 | false 152 | 153 | 154 | 155 | 2 156 | Build 157 | 158 | ProjectExplorer.BuildSteps.Build 159 | 160 | 161 | 162 | true 163 | Make 164 | 165 | Qt4ProjectManager.MakeStep 166 | 167 | -w 168 | -r 169 | 170 | true 171 | clean 172 | 173 | 174 | 1 175 | Clean 176 | 177 | ProjectExplorer.BuildSteps.Clean 178 | 179 | 2 180 | false 181 | 182 | Release 183 | 184 | Qt4ProjectManager.Qt4BuildConfiguration 185 | 0 186 | true 187 | 188 | 2 189 | 190 | 191 | 192 | true 193 | Check for free disk space 194 | 195 | RemoteLinux.CheckForFreeDiskSpaceStep 196 | 197 | 198 | 199 | 200 | 201 | / 202 | 5242880 203 | 204 | 205 | true 206 | Upload files via SFTP 207 | 208 | RemoteLinux.DirectUploadStep 209 | 210 | /home/vinaydivakar/build-Qt_Test-BeagleBone-Debug/Qt_Test 211 | 212 | 213 | 192.168.1.123 214 | 215 | 216 | /home/debian 217 | 218 | 219 | 220 | 221 | 222 | 2017-12-10T18:50:40 223 | 224 | false 225 | true 226 | 227 | 2 228 | Deploy 229 | 230 | ProjectExplorer.BuildSteps.Deploy 231 | 232 | 1 233 | Deploy to Remote Linux Host 234 | 235 | DeployToGenericLinux 236 | 237 | 238 | 239 | 240 | true 241 | Check for free disk space 242 | 243 | RemoteLinux.CheckForFreeDiskSpaceStep 244 | 245 | 246 | 247 | 248 | 249 | / 250 | 5242880 251 | 252 | 253 | true 254 | Upload files via SFTP 255 | 256 | RemoteLinux.DirectUploadStep 257 | 258 | 259 | 260 | 261 | 262 | false 263 | true 264 | 265 | 2 266 | Deploy 267 | 268 | ProjectExplorer.BuildSteps.Deploy 269 | 270 | 1 271 | Deploy to Remote Linux Host 272 | Deploy to Remote Linux Host2 273 | DeployToGenericLinux 274 | 275 | 276 | 277 | 278 | true 279 | Check for free disk space 280 | 281 | RemoteLinux.CheckForFreeDiskSpaceStep 282 | 283 | 284 | 285 | 286 | 287 | / 288 | 5242880 289 | 290 | 291 | true 292 | Upload files via SFTP 293 | 294 | RemoteLinux.DirectUploadStep 295 | 296 | 297 | 298 | 299 | 300 | false 301 | true 302 | 303 | 2 304 | Deploy 305 | 306 | ProjectExplorer.BuildSteps.Deploy 307 | 308 | 1 309 | Deploy to Remote Linux Host 310 | Deploy to Remote Linux Host3 311 | DeployToGenericLinux 312 | 313 | 3 314 | 315 | 316 | false 317 | false 318 | 1000 319 | 320 | true 321 | 322 | false 323 | false 324 | false 325 | false 326 | true 327 | 0.01 328 | 10 329 | true 330 | 1 331 | 25 332 | 333 | 1 334 | true 335 | false 336 | true 337 | valgrind 338 | 339 | 0 340 | 1 341 | 2 342 | 3 343 | 4 344 | 5 345 | 6 346 | 7 347 | 8 348 | 9 349 | 10 350 | 11 351 | 12 352 | 13 353 | 14 354 | 355 | 1 356 | 357 | QWS_MOUSE_PROTO=LinuxInput:/dev/input/event2 358 | 359 | Qt_Test (on Remote Device) 360 | 361 | RemoteLinuxRunConfiguration:Qt_Test 362 | -qws 363 | Qt_Test 364 | 1 365 | 366 | false 367 | 368 | 3768 369 | false 370 | true 371 | false 372 | false 373 | true 374 | 375 | 1 376 | 377 | 378 | 379 | ProjectExplorer.Project.TargetCount 380 | 1 381 | 382 | 383 | ProjectExplorer.Project.Updater.FileVersion 384 | 18 385 | 386 | 387 | Version 388 | 18 389 | 390 | 391 | --------------------------------------------------------------------------------