-
Notifications
You must be signed in to change notification settings - Fork 8
/
System.C
110 lines (97 loc) · 5.39 KB
/
System.C
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2018 by Laurent Itti, the University of Southern
// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
//
// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details. You should have received a copy of the GNU General Public License along with this program;
// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "System.H"
#include "JeVoisInventor.H"
#include <QFormLayout>
#include <QMessageBox>
// ##############################################################################################################
System::System(JeVoisInventor * inv, Serial * serial, Camera * cam, bool headless, QWidget * parent) :
QWidget(parent),
m_inv(inv),
m_serial(serial),
m_cam(cam),
m_stream(tr("Go Headless")),
m_usbsd(tr("Enable")),
m_date(tr("Set Now")),
m_headless(headless)
{
QFormLayout * lay = new QFormLayout(this);
// Video streaming button:
m_stream.setEnabled(! m_headless); // initial state from preferences
connect(&m_stream, &QPushButton::clicked, [this]() {
if (QMessageBox::question(this, tr("Switch to headless mode?"),
tr("<p>Before you disable video streaming and switch to headless mode, "
"you should add commands to initscript.cfg to load and start a vision module "
"with no video output. For example:</p>"
"<p><tt>setmapping2 YUYV 640 480 30.0 JeVois DemoArUco</tt></p>"
"<p><tt>setpar serout USB</tt></p>"
"<p><tt>streamon</tt></p>"
"<p>Also note that to go headless and run the init script, we "
"will restart the camera and disable the vision module selection menu. "
"To get out of headless operation, you will "
"have to quit and restart the Inventor.</p><p> </p>"
"<p>Switch to headless mode now?</p>")) != QMessageBox::Yes)
return;
m_stream.setEnabled(false);
m_usbsd.setEnabled(false);
m_headless = true;
m_inv->rebootJeVois();
});
lay->addRow(tr("Video streaming:"), &m_stream);
// usbsd toggle:
m_usbsd.setCheckable(true);
m_usbsd.setEnabled(! m_headless); // disable usbsd when headless
connect(&m_usbsd, &QPushButton::toggled, [this](bool checked) {
if (checked)
{
m_stream.setEnabled(false);
m_cam->setStreaming(false);
m_serial->command("usbsd");
QMessageBox::information(this, tr("JeVois microSD exported to host computer"),
tr("The microSD card inside JeVois was exported to your host computer. "
"A new USB flash drive should appear momentarily on your desktop. Video "
"streaming is not possible while the microSD card is exported.<br><br> "
"When you are done, properly eject the virtual flash drive from your desktop "
"and JeVois will restart."), QMessageBox::Ok);
// Freeze the UI
m_inv->enableUI(false);
// Reset m_stream as it will be true after we reboot
m_stream.setChecked(true);
}
});
lay->addRow(tr("Export microSD card inside JeVois to host computer:"), &m_usbsd);
// date/time:
connect(&m_date, &QPushButton::clicked, [this]() {
std::time_t t = std::time(nullptr); char str[100];
std::strftime(str, sizeof(str), "%m%d%H%M%Y.%S", std::localtime(&t));
m_serial->
command("date " + QString(str),
[this](QStringList const & ans) {
if (ans.isEmpty()) return;
QMessageBox::information(this, tr("JeVois date/time set"),
tr("Date and time have been successfully set on JeVois:\n\n") + ans[0] +
tr("\n\nRemember that this will be lost next time JeVois restarts "
"or is powered off, as JeVois has no clock battery."), QMessageBox::Ok);
});
});
lay->addRow(tr("Set current date/time on JeVois:"), &m_date);
}
// ##############################################################################################################
System::~System()
{ }
// ##############################################################################################################
bool System::isHeadless() const
{ return m_headless; }