SerialConnect: allow to change line terminator
* It can now be used to send AT commands for example, which need \r instead of \n.
This commit is contained in:
parent
d3b6b9e5f7
commit
534d0e6160
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014, Adrien Destugues, pulkomandy@pulkomandy.tk
|
||||
* Copyright 2012-2015, Adrien Destugues, pulkomandy@pulkomandy.tk
|
||||
* Distributed under the terms of the MIT licence.
|
||||
*/
|
||||
|
||||
@ -116,6 +116,9 @@ SerialWindow::SerialWindow()
|
||||
fDatabitsMenu->SetRadioMode(true);
|
||||
settingsMenu->AddItem(fDatabitsMenu);
|
||||
|
||||
fLineTerminatorMenu = new BMenu("Line terminator");
|
||||
fLineTerminatorMenu->SetRadioMode(true);
|
||||
settingsMenu->AddItem(fLineTerminatorMenu);
|
||||
|
||||
BMessage* message = new BMessage(kMsgSettings);
|
||||
message->AddInt32("parity", B_NO_PARITY);
|
||||
@ -195,6 +198,22 @@ SerialWindow::SerialWindow()
|
||||
fFlowcontrolMenu->AddItem(noFlow);
|
||||
fFlowcontrolMenu->SetTargetForItems(be_app);
|
||||
|
||||
message = new BMessage(kMsgSettings);
|
||||
message->AddString("terminator", "\n");
|
||||
BMenuItem* lf = new BMenuItem("LF (\\n)", message);
|
||||
|
||||
message = new BMessage(kMsgSettings);
|
||||
message->AddString("terminator", "\r");
|
||||
BMenuItem* cr = new BMenuItem("CR (\\r)", message);
|
||||
|
||||
message = new BMessage(kMsgSettings);
|
||||
message->AddString("terminator", "\r\n");
|
||||
BMenuItem* crlf = new BMenuItem("CR/LF (\\r\\n)", message);
|
||||
|
||||
fLineTerminatorMenu->AddItem(lf);
|
||||
fLineTerminatorMenu->AddItem(cr);
|
||||
fLineTerminatorMenu->AddItem(crlf);
|
||||
|
||||
CenterOnScreen();
|
||||
}
|
||||
|
||||
@ -283,6 +302,7 @@ void SerialWindow::MessageReceived(BMessage* message)
|
||||
data_bits dataBits;
|
||||
parity_mode parity;
|
||||
uint32 flowcontrol;
|
||||
BString terminator;
|
||||
|
||||
if (message->FindInt32("databits", (int32*)&dataBits) == B_OK) {
|
||||
for (int i = 0; i < fDatabitsMenu->CountItems(); i++) {
|
||||
@ -341,6 +361,18 @@ void SerialWindow::MessageReceived(BMessage* message)
|
||||
}
|
||||
}
|
||||
|
||||
if (message->FindString("terminator", &terminator) == B_OK) {
|
||||
fTermView->SetLineTerminator(terminator);
|
||||
for (int i = 0; i < fLineTerminatorMenu->CountItems(); i++) {
|
||||
BMenuItem* item = fLineTerminatorMenu->ItemAt(i);
|
||||
BString code;
|
||||
item->Message()->FindString("terminator", &code);
|
||||
|
||||
if (terminator == code)
|
||||
item->SetMarked(true);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014, Adrien Destugues, pulkomandy@pulkomandy.tk
|
||||
* Copyright 2012-2015, Adrien Destugues, pulkomandy@pulkomandy.tk
|
||||
* Distributed under the terms of the MIT licence.
|
||||
*/
|
||||
|
||||
@ -31,6 +31,7 @@ class SerialWindow: public BWindow
|
||||
BMenu* fParityMenu;
|
||||
BMenu* fFlowcontrolMenu;
|
||||
BMenu* fBaudrateMenu;
|
||||
BMenu* fLineTerminatorMenu;
|
||||
BFilePanel* fLogFilePanel;
|
||||
|
||||
static const int kBaudrates[];
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014, Adrien Destugues, pulkomandy@gmail.com
|
||||
* Copyright 2012-2015, Adrien Destugues, pulkomandy@gmail.com
|
||||
* Distributed under the terms of the MIT licence.
|
||||
*/
|
||||
|
||||
@ -184,6 +184,10 @@ TermView::KeyDown(const char* bytes, int32 numBytes)
|
||||
numBytes = 1;
|
||||
bytes = "\x7F";
|
||||
break;
|
||||
case '\n':
|
||||
numBytes = fLineTerminator.Length();
|
||||
bytes = fLineTerminator.String();
|
||||
break;
|
||||
}
|
||||
|
||||
// Send the bytes to the serial port
|
||||
@ -214,6 +218,13 @@ TermView::MessageReceived(BMessage* message)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TermView::SetLineTerminator(BString terminator)
|
||||
{
|
||||
fLineTerminator = terminator;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TermView::PushBytes(const char* bytes, size_t length)
|
||||
{
|
||||
@ -255,6 +266,7 @@ TermView::_Init()
|
||||
background.alpha = 255;
|
||||
|
||||
SetViewColor(background);
|
||||
SetLineTerminator("\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
/*
|
||||
* Copyright 2012-2014, Adrien Destugues, pulkomandy@gmail.com
|
||||
* Copyright 2012-2015, Adrien Destugues, pulkomandy@gmail.com
|
||||
* Distributed under the terms of the MIT licence.
|
||||
*/
|
||||
|
||||
|
||||
#include <String.h>
|
||||
#include <View.h>
|
||||
|
||||
extern "C" {
|
||||
@ -24,6 +25,7 @@ class TermView: public BView
|
||||
void GetPreferredSize(float* width, float* height);
|
||||
void KeyDown(const char* bytes, int32 numBytes);
|
||||
void MessageReceived(BMessage* message);
|
||||
void SetLineTerminator(BString bytes);
|
||||
|
||||
void PushBytes(const char* bytes, const size_t length);
|
||||
|
||||
@ -56,6 +58,8 @@ class TermView: public BView
|
||||
int fFontWidth;
|
||||
int fFontHeight;
|
||||
|
||||
BString fLineTerminator;
|
||||
|
||||
static const VTermScreenCallbacks sScreenCallbacks;
|
||||
|
||||
static const int kDefaultWidth = 80;
|
||||
|
Loading…
Reference in New Issue
Block a user