-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
78 lines (45 loc) · 1.74 KB
/
mainwindow.cpp
File metadata and controls
78 lines (45 loc) · 1.74 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtAndroidExtras/QAndroidJniObject>
#include <QtAndroidExtras/QAndroidJniEnvironment>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->spinBox->setStyleSheet("QSpinBox::up-button {width: 96px;}"
"QSpinBox::down-button {width: 96px;}");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButtonRead_clicked()
{
if (devCount>0)
{
unsigned char value = QAndroidJniObject::callStaticMethod<jshort>("org/qtproject/usbexample/MyFTDIClass","Read_USB", "()S");
ui->lcdNumber->display(value);
ui->lcdNumber->show();
}
}
void MainWindow::on_pushButtonSend_clicked()
{
if (devCount>0)
{
unsigned char sendValue= ui->spinBox->value();
//--------------Show how to handle a byte array via JNI-----------
QAndroidJniEnvironment env;
jbyteArray jBuff = env->NewByteArray(1);
jbyte a[] = {0};
a[0]= (jbyte) sendValue;
env->SetByteArrayRegion(jBuff, 0, 1, a); //SetByteArrayRegion(JNIEnvironment env, int arrayJREF, int startIndex, int length, Address bufAddress)
QAndroidJniObject::callStaticMethod<void>("org/qtproject/usbexample/MyFTDIClass","Write_USB","([B)V", jBuff);
env->DeleteLocalRef(jBuff); // IMPORTANT TO AVOID MEMORY LEAK!
}
}
void MainWindow::on_pushButtonInit_clicked()
{
devCount = QAndroidJniObject::callStaticMethod<jint>("org/qtproject/usbexample/MyFTDIClass","initFTDI", "()I");
ui->labelInit->setText("Devicse found: " + QString::number(devCount) );
}