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:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2014, Adrien Destugues, [email protected]
|
* Copyright 2012-2015, Adrien Destugues, [email protected]
|
||||||
* Distributed under the terms of the MIT licence.
|
* Distributed under the terms of the MIT licence.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -116,6 +116,9 @@ SerialWindow::SerialWindow()
|
|||||||
fDatabitsMenu->SetRadioMode(true);
|
fDatabitsMenu->SetRadioMode(true);
|
||||||
settingsMenu->AddItem(fDatabitsMenu);
|
settingsMenu->AddItem(fDatabitsMenu);
|
||||||
|
|
||||||
|
fLineTerminatorMenu = new BMenu("Line terminator");
|
||||||
|
fLineTerminatorMenu->SetRadioMode(true);
|
||||||
|
settingsMenu->AddItem(fLineTerminatorMenu);
|
||||||
|
|
||||||
BMessage* message = new BMessage(kMsgSettings);
|
BMessage* message = new BMessage(kMsgSettings);
|
||||||
message->AddInt32("parity", B_NO_PARITY);
|
message->AddInt32("parity", B_NO_PARITY);
|
||||||
@@ -195,6 +198,22 @@ SerialWindow::SerialWindow()
|
|||||||
fFlowcontrolMenu->AddItem(noFlow);
|
fFlowcontrolMenu->AddItem(noFlow);
|
||||||
fFlowcontrolMenu->SetTargetForItems(be_app);
|
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();
|
CenterOnScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,6 +302,7 @@ void SerialWindow::MessageReceived(BMessage* message)
|
|||||||
data_bits dataBits;
|
data_bits dataBits;
|
||||||
parity_mode parity;
|
parity_mode parity;
|
||||||
uint32 flowcontrol;
|
uint32 flowcontrol;
|
||||||
|
BString terminator;
|
||||||
|
|
||||||
if (message->FindInt32("databits", (int32*)&dataBits) == B_OK) {
|
if (message->FindInt32("databits", (int32*)&dataBits) == B_OK) {
|
||||||
for (int i = 0; i < fDatabitsMenu->CountItems(); i++) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2014, Adrien Destugues, [email protected]
|
* Copyright 2012-2015, Adrien Destugues, [email protected]
|
||||||
* Distributed under the terms of the MIT licence.
|
* Distributed under the terms of the MIT licence.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@ class SerialWindow: public BWindow
|
|||||||
BMenu* fParityMenu;
|
BMenu* fParityMenu;
|
||||||
BMenu* fFlowcontrolMenu;
|
BMenu* fFlowcontrolMenu;
|
||||||
BMenu* fBaudrateMenu;
|
BMenu* fBaudrateMenu;
|
||||||
|
BMenu* fLineTerminatorMenu;
|
||||||
BFilePanel* fLogFilePanel;
|
BFilePanel* fLogFilePanel;
|
||||||
|
|
||||||
static const int kBaudrates[];
|
static const int kBaudrates[];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2014, Adrien Destugues, [email protected]
|
* Copyright 2012-2015, Adrien Destugues, [email protected]
|
||||||
* Distributed under the terms of the MIT licence.
|
* Distributed under the terms of the MIT licence.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -184,6 +184,10 @@ TermView::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
numBytes = 1;
|
numBytes = 1;
|
||||||
bytes = "\x7F";
|
bytes = "\x7F";
|
||||||
break;
|
break;
|
||||||
|
case '\n':
|
||||||
|
numBytes = fLineTerminator.Length();
|
||||||
|
bytes = fLineTerminator.String();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the bytes to the serial port
|
// Send the bytes to the serial port
|
||||||
@@ -214,6 +218,13 @@ TermView::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TermView::SetLineTerminator(BString terminator)
|
||||||
|
{
|
||||||
|
fLineTerminator = terminator;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermView::PushBytes(const char* bytes, size_t length)
|
TermView::PushBytes(const char* bytes, size_t length)
|
||||||
{
|
{
|
||||||
@@ -255,6 +266,7 @@ TermView::_Init()
|
|||||||
background.alpha = 255;
|
background.alpha = 255;
|
||||||
|
|
||||||
SetViewColor(background);
|
SetViewColor(background);
|
||||||
|
SetLineTerminator("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2014, Adrien Destugues, [email protected]
|
* Copyright 2012-2015, Adrien Destugues, [email protected]
|
||||||
* Distributed under the terms of the MIT licence.
|
* Distributed under the terms of the MIT licence.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -24,6 +25,7 @@ class TermView: public BView
|
|||||||
void GetPreferredSize(float* width, float* height);
|
void GetPreferredSize(float* width, float* height);
|
||||||
void KeyDown(const char* bytes, int32 numBytes);
|
void KeyDown(const char* bytes, int32 numBytes);
|
||||||
void MessageReceived(BMessage* message);
|
void MessageReceived(BMessage* message);
|
||||||
|
void SetLineTerminator(BString bytes);
|
||||||
|
|
||||||
void PushBytes(const char* bytes, const size_t length);
|
void PushBytes(const char* bytes, const size_t length);
|
||||||
|
|
||||||
@@ -56,6 +58,8 @@ class TermView: public BView
|
|||||||
int fFontWidth;
|
int fFontWidth;
|
||||||
int fFontHeight;
|
int fFontHeight;
|
||||||
|
|
||||||
|
BString fLineTerminator;
|
||||||
|
|
||||||
static const VTermScreenCallbacks sScreenCallbacks;
|
static const VTermScreenCallbacks sScreenCallbacks;
|
||||||
|
|
||||||
static const int kDefaultWidth = 80;
|
static const int kDefaultWidth = 80;
|
||||||
|
|||||||
Reference in New Issue
Block a user