Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vimba
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kr69sugu
vimba
Commits
4539f88e
Commit
4539f88e
authored
Feb 22, 2024
by
am0ebe
Browse files
Options
Downloads
Patches
Plain Diff
console: interpret user input as number, line or single char! => fix set duration, fix setcam ID -1
parent
b94a5984
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cmd/console.cpp
+76
-68
76 additions, 68 deletions
src/cmd/console.cpp
src/cmd/console.h
+10
-6
10 additions, 6 deletions
src/cmd/console.h
src/core.cpp
+1
-0
1 addition, 0 deletions
src/core.cpp
with
87 additions
and
74 deletions
src/cmd/console.cpp
+
76
−
68
View file @
4539f88e
...
...
@@ -11,6 +11,8 @@
#include
<iostream>
#include
<math.h>
Console
::
Console
()
:
QObject
()
{};
// Private constructor to prevent instantiation
Console
*
Console
::
getInstance
()
{
static
Console
*
instance
=
new
Console
;
// Static local variable ensures single instance
return
instance
;
...
...
@@ -20,36 +22,26 @@ void Console::listenKeys()
{
// listen to keyevents in endless loop
/* This is an expensive or blocking operation, why we use threaded approach to not block main event loop! */
std
::
string
l
in
e
;
std
::
string
in
put
;
forever
{
std
::
getline
(
std
::
cin
,
line
);
emit
keyPressed
(
line
[
0
]);
if
(
line
[
0
]
==
'q'
)
break
;
}
std
::
getline
(
std
::
cin
,
input
);
if
(
!
input
.
empty
()
&&
input
.
find_first_not_of
(
"0123456789"
)
==
std
::
string
::
npos
)
{
emit
numberEntered
(
std
::
stoi
(
input
));
// Number
}
// read line from cin
QString
Console
::
getLine
()
else
if
(
input
.
size
()
==
1
)
{
std
::
string
line
;
std
::
getline
(
std
::
cin
,
line
);
// emit lineEntered(QString::fromStdString(line));
return
QString
::
fromStdString
(
line
);
emit
keyPressed
(
input
[
0
]);
// Single char (excluding single digits)
if
(
input
[
0
]
==
'q'
)
break
;
}
// read number from cin
int
Console
::
getNumber
()
else
{
int
number
;
std
::
cin
>>
number
;
// emit numberEntered(number);
return
number
;
emit
lineEntered
(
QString
::
fromStdString
(
input
));
// Line
}
}
}
void
Console
::
error
(
const
int
&
errCode
)
{
...
...
@@ -113,13 +105,17 @@ void Console::printHelp()
// ###############################
// Controller
Controller
::
Controller
()
Controller
::
Controller
()
:
getDur
(
false
)
{
auto
console
=
Console
::
getInstance
();
console
->
moveToThread
(
&
thread
);
connect
(
&
thread
,
&
QThread
::
finished
,
console
,
&
QObject
::
deleteLater
);
connect
(
this
,
&
Controller
::
operate
,
console
,
&
Console
::
listenKeys
);
connect
(
console
,
&
Console
::
keyPressed
,
this
,
&
Controller
::
keyPress
);
connect
(
console
,
&
Console
::
keyPressed
,
this
,
&
Controller
::
onKeyPressed
);
connect
(
console
,
&
Console
::
lineEntered
,
this
,
&
Controller
::
onLineEntered
);
connect
(
console
,
&
Console
::
numberEntered
,
this
,
&
Controller
::
onNumberEntered
);
QTimer
::
singleShot
(
0
,
this
,
SIGNAL
(
operate
()));
thread
.
start
();
...
...
@@ -132,17 +128,11 @@ Controller::~Controller()
// qDebug().noquote() << __FUNCTION__ << "():" << __LINE__ << ": ";
}
void
Controller
::
k
eyPress
(
const
QChar
&
key
)
void
Controller
::
onK
eyPress
ed
(
const
QChar
&
key
)
{
auto
console
=
Console
::
getInstance
();
qDebug
().
noquote
()
<<
__FUNCTION__
<<
": "
<<
key
;
if
(
key
.
isDigit
()
)
{
emit
cam
(
key
.
digitValue
()
-
1
);
}
else
{
int
dur
;
switch
(
key
.
unicode
())
{
// XXX add new func
...
...
@@ -152,8 +142,7 @@ void Controller::keyPress(const QChar& key)
case
'd'
:
console
->
print
(
"Enter duration in seconds: "
);
dur
=
console
->
getNumber
();
// XXX not thread safe? + interferes with forever loop?
emit
setDuration
(
dur
);
getDur
=
true
;
break
;
case
'c'
:
...
...
@@ -185,4 +174,23 @@ void Controller::keyPress(const QChar& key)
break
;
}
}
void
Controller
::
onLineEntered
(
const
QString
&
)
{
// qDebug().noquote() << "Line entered: " << line;
}
void
Controller
::
onNumberEntered
(
int
number
)
{
// qDebug().noquote() << "Number entered: " << number;
if
(
getDur
)
{
emit
setDuration
(
number
);
getDur
=
false
;
}
else
{
emit
cam
(
number
-
1
);
}
}
This diff is collapsed.
Click to expand it.
src/cmd/console.h
+
10
−
6
View file @
4539f88e
...
...
@@ -18,12 +18,11 @@ public:
Console
&
operator
=
(
const
Console
&
)
=
delete
;
private:
Console
()
:
QObject
(){};
//// Private constructor to prevent instantiation
Console
()
;
public
slots
:
void
listenKeys
();
QString
getLine
();
int
getNumber
();
void
error
(
const
QString
&
,
const
int
&
);
void
error
(
const
int
&
);
void
print
(
const
QString
&
);
...
...
@@ -35,8 +34,8 @@ public slots:
signals:
void
keyPressed
(
const
QChar
&
key
);
//
void lineEntered(const QString&);
//
void numberEntered(const int&);
void
lineEntered
(
const
QString
&
);
void
numberEntered
(
const
int
&
);
};
...
...
@@ -51,7 +50,9 @@ class Controller : public QObject
~
Controller
();
public
slots
:
void
keyPress
(
const
QChar
&
);
void
onKeyPressed
(
const
QChar
&
);
void
onLineEntered
(
const
QString
&
line
);
void
onNumberEntered
(
int
number
);
signals:
// to UI
...
...
@@ -71,4 +72,7 @@ class Controller : public QObject
// void storeSettings();
// ... more signals here, new func XXX
private:
bool
getDur
;
};
This diff is collapsed.
Click to expand it.
src/core.cpp
+
1
−
0
View file @
4539f88e
...
...
@@ -204,5 +204,6 @@ void Core::stopRecording()
void
Core
::
setDuration
(
int
dur
)
{
qDebug
()
<<
__LINE__
<<
"-"
<<
__PRETTY_FUNCTION__
<<
""
;
_recDuration
=
seconds
(
dur
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment