Current ESP32 SDK does not support "std::optional"
This commit is contained in:
parent
7649ab6b29
commit
6190a3e562
6 changed files with 10 additions and 11 deletions
|
@ -34,14 +34,14 @@ uint8_t console::get_char()
|
|||
void console::operator()()
|
||||
{
|
||||
while(!*terminate) {
|
||||
auto c = wait_for_char(500);
|
||||
int c = wait_for_char(500);
|
||||
|
||||
if (c.has_value() == false)
|
||||
if (c == -1)
|
||||
continue;
|
||||
|
||||
if (c == 3)
|
||||
*terminate = true;
|
||||
else
|
||||
buffer.push_back(c.value());
|
||||
buffer.push_back(c);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
|
@ -16,7 +15,7 @@ private:
|
|||
std::vector<char> buffer;
|
||||
|
||||
protected:
|
||||
virtual std::optional<char> wait_for_char(const int timeout) = 0;
|
||||
virtual int wait_for_char(const int timeout) = 0;
|
||||
|
||||
public:
|
||||
console(std::atomic_bool *const terminate);
|
||||
|
|
|
@ -25,14 +25,14 @@ console_ncurses::~console_ncurses()
|
|||
endwin();
|
||||
}
|
||||
|
||||
std::optional<char> console_ncurses::wait_for_char(const int timeout)
|
||||
int console_ncurses::wait_for_char(const int timeout)
|
||||
{
|
||||
struct pollfd fds[] = { { STDIN_FILENO, POLLIN, timeout } };
|
||||
|
||||
if (poll(fds, 1, 0) == 1 && fds[0].revents)
|
||||
return getch();
|
||||
|
||||
return { };
|
||||
return -1;
|
||||
}
|
||||
|
||||
void console_ncurses::put_char(const char c)
|
||||
|
|
|
@ -11,7 +11,7 @@ private:
|
|||
NEWWIN *w_main { nullptr };
|
||||
|
||||
protected:
|
||||
std::optional<char> wait_for_char(const int timeout) override;
|
||||
int wait_for_char(const int timeout) override;
|
||||
|
||||
public:
|
||||
console_ncurses(std::atomic_bool *const terminate);
|
||||
|
|
|
@ -25,14 +25,14 @@ console_posix::~console_posix()
|
|||
error_exit(true, "~console_posix: tcsetattr failed");
|
||||
}
|
||||
|
||||
std::optional<char> console_posix::wait_for_char(const int timeout)
|
||||
int console_posix::wait_for_char(const int timeout)
|
||||
{
|
||||
struct pollfd fds[] = { { STDIN_FILENO, POLLIN, timeout } };
|
||||
|
||||
if (poll(fds, 1, 0) == 1 && fds[0].revents)
|
||||
return getchar();
|
||||
|
||||
return { };
|
||||
return -1;
|
||||
}
|
||||
|
||||
void console_posix::put_char(const char c)
|
||||
|
|
|
@ -9,7 +9,7 @@ private:
|
|||
struct termios org_tty_opts { 0 };
|
||||
|
||||
protected:
|
||||
std::optional<char> wait_for_char(const int timeout) override;
|
||||
int wait_for_char(const int timeout) override;
|
||||
|
||||
public:
|
||||
console_posix(std::atomic_bool *const terminate);
|
||||
|
|
Loading…
Add table
Reference in a new issue