promt improved
This commit is contained in:
parent
24688ff183
commit
e0a4be7685
BIN
driver/cli
BIN
driver/cli
Binary file not shown.
|
@ -108,14 +108,18 @@ void finish(int)
|
||||||
|
|
||||||
void view_back(int)
|
void view_back(int)
|
||||||
{
|
{
|
||||||
win_stack.pop_back();
|
if(win_stack.size())
|
||||||
|
{
|
||||||
|
delete win_stack.back();
|
||||||
|
win_stack.pop_back();
|
||||||
|
}
|
||||||
if(win_stack.size())
|
if(win_stack.size())
|
||||||
win_stack.back()->repaint();
|
win_stack.back()->repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void input(int)
|
void input(int)
|
||||||
{
|
{
|
||||||
std::function<void(int)> nextCall;
|
call_t nextCall;
|
||||||
int key;
|
int key;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -136,7 +140,7 @@ void show_info(int)
|
||||||
{
|
{
|
||||||
ViewInfo* view = new ViewInfo();
|
ViewInfo* view = new ViewInfo();
|
||||||
view->setTitle("Info");
|
view->setTitle("Info");
|
||||||
view->setText("Informationen zu Board 15 Famulus Edition\nEs war einmal");
|
view->setText("Informationen zu Board 15 Famulus Edition\nEs war einmal...");
|
||||||
view->setLabelClose("[ Zurueck ]");
|
view->setLabelClose("[ Zurueck ]");
|
||||||
view->repaint();
|
view->repaint();
|
||||||
|
|
||||||
|
@ -184,7 +188,10 @@ void write_digital_output0(int)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
uint8_t port = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
|
int d = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
|
||||||
|
if(d > 255 || 0 > d)
|
||||||
|
throw std::invalid_argument("bad value");
|
||||||
|
uint8_t port = static_cast<uint8_t>(d);
|
||||||
|
|
||||||
B15F& drv = B15F::getInstance();
|
B15F& drv = B15F::getInstance();
|
||||||
drv.digitalWrite0(port);
|
drv.digitalWrite0(port);
|
||||||
|
@ -200,7 +207,10 @@ void write_digital_output1(int)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
uint8_t port = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
|
int d = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
|
||||||
|
if(d > 255 || 0 > d)
|
||||||
|
throw std::invalid_argument("bad value");
|
||||||
|
uint8_t port = static_cast<uint8_t>(d);
|
||||||
|
|
||||||
B15F& drv = B15F::getInstance();
|
B15F& drv = B15F::getInstance();
|
||||||
drv.digitalWrite1(port);
|
drv.digitalWrite1(port);
|
||||||
|
@ -300,6 +310,42 @@ void show_analog_output1(int)
|
||||||
input(0);
|
input(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void stop_selftest(int)
|
||||||
|
{
|
||||||
|
B15F& drv = B15F::getInstance();
|
||||||
|
drv.discard();
|
||||||
|
}
|
||||||
|
|
||||||
|
void start_selftest(int)
|
||||||
|
{
|
||||||
|
B15F& drv = B15F::getInstance();
|
||||||
|
drv.activateSelfTestMode();
|
||||||
|
|
||||||
|
ViewInfo* view = new ViewInfo();
|
||||||
|
view->setTitle("Selbsttest aktiv");
|
||||||
|
view->setText("Das B15 befindet sich jetzt im Selbsttestmodus.\n \nSelbsttest:\nZu Beginn geht der Reihe nach jede LED von BA0 bis BA1 an.\nDanach leuchten die LEDs an AA0 und AA1 kurz auf.\nZum Schluss spiegelt in einer Endlosschleife:\n* BA0 Port BE0\n* BA1 die DIP-Schalter S7\n* AA0 ADC0\n* AA1 ADC1");
|
||||||
|
view->setLabelClose("[ Selbsttest Beenden ]");
|
||||||
|
view->setCall(&stop_selftest);
|
||||||
|
view->repaint();
|
||||||
|
|
||||||
|
win_stack.push_back(view);
|
||||||
|
input(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void show_selftest(int)
|
||||||
|
{
|
||||||
|
ViewInfo* view = new ViewInfo();
|
||||||
|
view->setTitle("Selbsttest");
|
||||||
|
view->setText("Bitte entfernen Sie jetzt alle Draehte von den Anschlussklemmen und bestaetigen\nmit Enter.");
|
||||||
|
view->setLabelClose("[ Weiter ]");
|
||||||
|
view->setCall(&start_selftest);
|
||||||
|
view->repaint();
|
||||||
|
|
||||||
|
win_stack.push_back(view);
|
||||||
|
input(0);
|
||||||
|
}
|
||||||
|
|
||||||
void show_main(int)
|
void show_main(int)
|
||||||
{
|
{
|
||||||
ViewSelection* view = new ViewSelection();
|
ViewSelection* view = new ViewSelection();
|
||||||
|
@ -309,6 +355,7 @@ void show_main(int)
|
||||||
view->addChoice("[ Digitale Ausgabe BE1 ]", &show_digital_output1);
|
view->addChoice("[ Digitale Ausgabe BE1 ]", &show_digital_output1);
|
||||||
view->addChoice("[ Analoge Ausgabe AA0 ]", &show_analog_output0);
|
view->addChoice("[ Analoge Ausgabe AA0 ]", &show_analog_output0);
|
||||||
view->addChoice("[ Analoge Ausgabe AA1 ]", &show_analog_output1);
|
view->addChoice("[ Analoge Ausgabe AA1 ]", &show_analog_output1);
|
||||||
|
view->addChoice("[ Selbsttest des B15 ]", &show_selftest);
|
||||||
view->addChoice("[ Informationen ]", &show_info);
|
view->addChoice("[ Informationen ]", &show_info);
|
||||||
view->addChoice("", nullptr);
|
view->addChoice("", nullptr);
|
||||||
view->addChoice("[ Beenden ]", &finish);
|
view->addChoice("[ Beenden ]", &finish);
|
||||||
|
|
|
@ -55,8 +55,6 @@ void B15F::init()
|
||||||
|
|
||||||
void B15F::reconnect()
|
void B15F::reconnect()
|
||||||
{
|
{
|
||||||
std::cout << PRE << "Verbindung unterbrochen, stelle Verbindung neu her: " << std::flush;
|
|
||||||
|
|
||||||
uint8_t tries = RECONNECT_TRIES;
|
uint8_t tries = RECONNECT_TRIES;
|
||||||
while(tries--)
|
while(tries--)
|
||||||
{
|
{
|
||||||
|
@ -228,6 +226,8 @@ uint16_t B15F::analogRead(uint8_t channel)
|
||||||
usart.writeByte(RQ_ADC);
|
usart.writeByte(RQ_ADC);
|
||||||
usart.writeByte(channel);
|
usart.writeByte(channel);
|
||||||
uint16_t adc = usart.readInt();
|
uint16_t adc = usart.readInt();
|
||||||
|
if(adc > 1023)
|
||||||
|
throw DriverException("Bad ADC data detected");
|
||||||
delay_us(1);
|
delay_us(1);
|
||||||
return adc;
|
return adc;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset
|
||||||
buffer_a[i] = usart.readInt();
|
buffer_a[i] = usart.readInt();
|
||||||
buffer_b[i] = usart.readInt();
|
buffer_b[i] = usart.readInt();
|
||||||
if(buffer_a[i] > 1023 || buffer_b[i] > 1023)
|
if(buffer_a[i] > 1023 || buffer_b[i] > 1023)
|
||||||
std::cout << PRE << "bad data detected" << std::endl;
|
throw DriverException("Bad ADC data detected");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t aw = usart.readByte();
|
uint8_t aw = usart.readByte();
|
||||||
|
|
BIN
driver/main
BIN
driver/main
Binary file not shown.
|
@ -13,6 +13,10 @@ View::View()
|
||||||
keypad(win, TRUE);
|
keypad(win, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
View::~View()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void View::setWinContext(WINDOW* win)
|
void View::setWinContext(WINDOW* win)
|
||||||
{
|
{
|
||||||
View::win = win;
|
View::win = win;
|
||||||
|
|
|
@ -11,11 +11,13 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
extern std::string ERR_MSG;
|
extern std::string ERR_MSG;
|
||||||
|
typedef std::function<void(int)> call_t;
|
||||||
|
|
||||||
class View
|
class View
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
View(void);
|
View(void);
|
||||||
|
virtual ~View(void);
|
||||||
|
|
||||||
static void setWinContext(WINDOW* win);
|
static void setWinContext(WINDOW* win);
|
||||||
static WINDOW* getWinContext(void);
|
static WINDOW* getWinContext(void);
|
||||||
|
@ -26,14 +28,14 @@ public:
|
||||||
virtual void repaint(void);
|
virtual void repaint(void);
|
||||||
|
|
||||||
virtual void draw(void) = 0;
|
virtual void draw(void) = 0;
|
||||||
virtual std::function<void(int)> keypress(int& key) = 0;
|
virtual call_t keypress(int& key) = 0;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int width, height;
|
int width, height;
|
||||||
int start_x = 0, start_y = 0;
|
int start_x = 0, start_y = 0;
|
||||||
std::string title;
|
std::string title;
|
||||||
std::vector<std::function<void(int)>> calls;
|
std::vector<call_t> calls;
|
||||||
|
|
||||||
static WINDOW* win;
|
static WINDOW* win;
|
||||||
constexpr static int KEY_ENT = 10;
|
constexpr static int KEY_ENT = 10;
|
||||||
|
|
|
@ -15,7 +15,7 @@ void ViewInfo::setLabelClose(std::string label)
|
||||||
this->label_close = label;
|
this->label_close = label;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewInfo::setCall(std::function<void(int)> call)
|
void ViewInfo::setCall(call_t call)
|
||||||
{
|
{
|
||||||
calls[0] = call;
|
calls[0] = call;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ void ViewInfo::draw()
|
||||||
wattroff(win, A_REVERSE);
|
wattroff(win, A_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<void(int)> ViewInfo::keypress(int& key)
|
call_t ViewInfo::keypress(int& key)
|
||||||
{
|
{
|
||||||
switch(key)
|
switch(key)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,9 +9,9 @@ public:
|
||||||
ViewInfo(void);
|
ViewInfo(void);
|
||||||
virtual void setText(std::string text);
|
virtual void setText(std::string text);
|
||||||
virtual void setLabelClose(std::string label);;
|
virtual void setLabelClose(std::string label);;
|
||||||
virtual void setCall(std::function<void(int)> call);
|
virtual void setCall(call_t call);
|
||||||
virtual void draw(void) override;
|
virtual void draw(void) override;
|
||||||
virtual std::function<void(int)> keypress(int& key) override;
|
virtual call_t keypress(int& key) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string text;
|
std::string text;
|
||||||
|
|
|
@ -4,7 +4,7 @@ ViewMonitor::ViewMonitor() : t_worker(&ViewMonitor::worker, this)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<void(int)> ViewMonitor::keypress(int& key)
|
call_t ViewMonitor::keypress(int& key)
|
||||||
{
|
{
|
||||||
switch(key)
|
switch(key)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,7 @@ class ViewMonitor : public ViewInfo
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ViewMonitor(void);
|
ViewMonitor(void);
|
||||||
virtual std::function<void(int)> keypress(int& key) override;
|
virtual call_t keypress(int& key) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string fancyDigitalString(uint8_t& b);
|
std::string fancyDigitalString(uint8_t& b);
|
||||||
|
|
|
@ -2,12 +2,18 @@
|
||||||
|
|
||||||
void ViewPromt::draw()
|
void ViewPromt::draw()
|
||||||
{
|
{
|
||||||
|
curs_set(2); // show cursor
|
||||||
|
|
||||||
int li = text_offset_y;
|
int li = text_offset_y;
|
||||||
|
int ci = 0;
|
||||||
for(std::string line : str_split(message + input, "\n"))
|
for(std::string line : str_split(message + input, "\n"))
|
||||||
mvwprintw(win, li++, text_offset_x, "%s", line.c_str());
|
{
|
||||||
|
mvwprintw(win, ++li, text_offset_x, "%s", line.c_str());
|
||||||
|
ci = line.length() + text_offset_x;
|
||||||
|
}
|
||||||
|
|
||||||
button_offset_x = (width - label_cancel.length() - sep.length() - label_confirm.length()) / 2;
|
button_offset_x = (width - label_cancel.length() - sep.length() - label_confirm.length()) / 2;
|
||||||
button_offset_y = height - text_offset_y + 1;
|
button_offset_y = height - text_offset_y;
|
||||||
|
|
||||||
if(selection == 0)
|
if(selection == 0)
|
||||||
{
|
{
|
||||||
|
@ -25,6 +31,7 @@ void ViewPromt::draw()
|
||||||
mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str());
|
mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str());
|
||||||
wattroff(win, A_REVERSE);
|
wattroff(win, A_REVERSE);
|
||||||
}
|
}
|
||||||
|
wmove(win, li, ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewPromt::setMessage(std::string message)
|
void ViewPromt::setMessage(std::string message)
|
||||||
|
@ -99,7 +106,8 @@ std::function<void(int)> ViewPromt::keypress(int& key)
|
||||||
if(selection == 0) // exit
|
if(selection == 0) // exit
|
||||||
key = -1; // do return from view
|
key = -1; // do return from view
|
||||||
else
|
else
|
||||||
ret = call_confirm;
|
ret = call_confirm;
|
||||||
|
curs_set(0); // hide cursor again
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -108,6 +116,7 @@ std::function<void(int)> ViewPromt::keypress(int& key)
|
||||||
if(key >= ' ' && key <= '~')
|
if(key >= ' ' && key <= '~')
|
||||||
input += (char) key;
|
input += (char) key;
|
||||||
|
|
||||||
repaint();
|
if(key != KEY_ENT)
|
||||||
|
repaint();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,10 @@ class ViewPromt : public View
|
||||||
public:
|
public:
|
||||||
virtual void draw(void) override;
|
virtual void draw(void) override;
|
||||||
virtual void setMessage(std::string message);
|
virtual void setMessage(std::string message);
|
||||||
virtual void setConfirm(std::string name, std::function<void(int)> call);
|
virtual void setConfirm(std::string name, call_t call);
|
||||||
virtual void setCancel(std::string name, bool cancelable);
|
virtual void setCancel(std::string name, bool cancelable);
|
||||||
virtual std::string getInput(void);
|
virtual std::string getInput(void);
|
||||||
virtual std::function<void(int)> keypress(int& key) override;
|
virtual call_t keypress(int& key) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
size_t selection = 1;
|
size_t selection = 1;
|
||||||
|
@ -22,11 +22,11 @@ protected:
|
||||||
std::string label_confirm = "[ OK ]";
|
std::string label_confirm = "[ OK ]";
|
||||||
std::string sep = " ";
|
std::string sep = " ";
|
||||||
std::string label_cancel = "[ Cancel ]";
|
std::string label_cancel = "[ Cancel ]";
|
||||||
std::function<void(int)> call_confirm = nullptr;
|
call_t call_confirm = nullptr;
|
||||||
bool cancelable = true;
|
bool cancelable = true;
|
||||||
int button_offset_x = 0, button_offset_y = 0;
|
int button_offset_x = 0, button_offset_y = 0;
|
||||||
constexpr static int text_offset_x = 2;
|
constexpr static int text_offset_x = 2;
|
||||||
constexpr static int text_offset_y = 3;
|
constexpr static int text_offset_y = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VIEW_PROMT_H
|
#endif // VIEW_PROMT_H
|
||||||
|
|
|
@ -13,15 +13,15 @@ void ViewSelection::draw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewSelection::addChoice(std::string name, std::function<void(int)> call)
|
void ViewSelection::addChoice(std::string name, call_t call)
|
||||||
{
|
{
|
||||||
choices.push_back(name);
|
choices.push_back(name);
|
||||||
calls.push_back(call);
|
calls.push_back(call);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<void(int)> ViewSelection::keypress(int& key)
|
call_t ViewSelection::keypress(int& key)
|
||||||
{
|
{
|
||||||
std::function<void(int)> ret = nullptr;
|
call_t ret = nullptr;
|
||||||
switch(key)
|
switch(key)
|
||||||
{
|
{
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
|
|
|
@ -9,8 +9,8 @@ class ViewSelection : public View
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void draw(void) override;
|
virtual void draw(void) override;
|
||||||
virtual void addChoice(std::string name, std::function<void(int)> call);
|
virtual void addChoice(std::string name, call_t call);
|
||||||
virtual std::function<void(int)> keypress(int& key) override;
|
virtual call_t keypress(int& key) override;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue