SerialConnect: allow custom baudrates from the GUI
This commit is contained in:
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016, Adrien Destugues, [email protected]
|
||||||
|
* Distributed under terms of the MIT license.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "CustomRateWindow.h"
|
||||||
|
|
||||||
|
#include "SerialApp.h"
|
||||||
|
|
||||||
|
#include <Button.h>
|
||||||
|
#include <Catalog.h>
|
||||||
|
#include <GroupLayoutBuilder.h>
|
||||||
|
#include <Spinner.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define B_TRANSLATION_CONTEXT "Custom baudrate window"
|
||||||
|
|
||||||
|
|
||||||
|
static const uint32 kOkButtonMsg = 'ok';
|
||||||
|
|
||||||
|
CustomRateWindow::CustomRateWindow(int baudrate)
|
||||||
|
: BWindow(BRect(100, 100, 200, 150), B_TRANSLATE("Custom baudrate"),
|
||||||
|
B_FLOATING_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_CLOSE_ON_ESCAPE
|
||||||
|
| B_AUTO_UPDATE_SIZE_LIMITS)
|
||||||
|
{
|
||||||
|
BGroupLayout* layout = new BGroupLayout(B_HORIZONTAL);
|
||||||
|
SetLayout(layout);
|
||||||
|
|
||||||
|
BGroupView* root = new BGroupView(B_VERTICAL);
|
||||||
|
AddChild(root);
|
||||||
|
|
||||||
|
BGroupLayoutBuilder(root)
|
||||||
|
.SetInsets(B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING,
|
||||||
|
B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING)
|
||||||
|
.AddGroup(B_HORIZONTAL)
|
||||||
|
.Add(fSpinner = new BSpinner("spin", B_TRANSLATE("Baudrate:"), NULL))
|
||||||
|
.End()
|
||||||
|
.AddGroup(B_HORIZONTAL)
|
||||||
|
.AddGlue()
|
||||||
|
.Add(new BButton("ok", B_TRANSLATE("Ok"), new BMessage(kOkButtonMsg)))
|
||||||
|
.Add(new BButton("cancel", B_TRANSLATE("Cancel"),
|
||||||
|
new BMessage(B_QUIT_REQUESTED)))
|
||||||
|
.End()
|
||||||
|
.End();
|
||||||
|
|
||||||
|
fSpinner->SetMinValue(50);
|
||||||
|
fSpinner->SetMaxValue(3000000);
|
||||||
|
fSpinner->SetValue(baudrate);
|
||||||
|
|
||||||
|
CenterOnScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CustomRateWindow::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
if (message->what == kOkButtonMsg)
|
||||||
|
{
|
||||||
|
BMessage* settings = new BMessage(kMsgSettings);
|
||||||
|
settings->AddInt32("baudrate", fSpinner->Value());
|
||||||
|
be_app->PostMessage(settings);
|
||||||
|
Quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BWindow::MessageReceived(message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016, Adrien Destugues, [email protected]
|
||||||
|
* Distributed under terms of the MIT license.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CUSTOMRATEWINDOW_H
|
||||||
|
#define CUSTOMRATEWINDOW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
|
||||||
|
class BSpinner;
|
||||||
|
|
||||||
|
|
||||||
|
class CustomRateWindow: public BWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CustomRateWindow(int baudrate);
|
||||||
|
void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BSpinner* fSpinner;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* !CUSTOMRATEWINDOW_H */
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
SubDir HAIKU_TOP src apps serialconnect ;
|
SubDir HAIKU_TOP src apps serialconnect ;
|
||||||
|
|
||||||
SubDirSysHdrs [ FDirName $(HAIKU_TOP) src apps serialconnect libvterm include ] ;
|
SubDirSysHdrs [ FDirName $(HAIKU_TOP) src apps serialconnect libvterm include ] ;
|
||||||
|
SubDirSysHdrs [ FDirName $(HAIKU_TOP) headers private interface ] ;
|
||||||
|
|
||||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps serialconnect libvterm src ] ;
|
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps serialconnect libvterm src ] ;
|
||||||
|
|
||||||
Application SerialConnect :
|
Application SerialConnect :
|
||||||
|
CustomRateWindow.cpp
|
||||||
SerialApp.cpp
|
SerialApp.cpp
|
||||||
SerialWindow.cpp
|
SerialWindow.cpp
|
||||||
TermView.cpp
|
TermView.cpp
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
|
||||||
|
#include "CustomRateWindow.h"
|
||||||
#include "SerialWindow.h"
|
#include "SerialWindow.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -146,6 +147,13 @@ void SerialApp::MessageReceived(BMessage* message)
|
|||||||
debugger("Invalid BMessage received");
|
debugger("Invalid BMessage received");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case kMsgCustomBaudrate:
|
||||||
|
{
|
||||||
|
// open the custom baudrate selector window
|
||||||
|
CustomRateWindow* window = new CustomRateWindow(fSerialPort.DataRate());
|
||||||
|
window->Show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
case kMsgSettings:
|
case kMsgSettings:
|
||||||
{
|
{
|
||||||
int32 baudrate;
|
int32 baudrate;
|
||||||
|
|||||||
@@ -52,11 +52,12 @@ class SerialApp: public BApplication
|
|||||||
|
|
||||||
|
|
||||||
enum messageConstants {
|
enum messageConstants {
|
||||||
kMsgDataRead = 'dare',
|
kMsgCustomBaudrate = 'cust',
|
||||||
kMsgDataWrite = 'dawr',
|
kMsgDataRead = 'dard',
|
||||||
kMsgLogfile = 'logf',
|
kMsgDataWrite = 'dawr',
|
||||||
kMsgOpenPort = 'open',
|
kMsgLogfile = 'logf',
|
||||||
kMsgSettings = 'stty',
|
kMsgOpenPort = 'open',
|
||||||
|
kMsgSettings = 'stty',
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -174,6 +174,10 @@ SerialWindow::SerialWindow()
|
|||||||
fBaudrateMenu->AddItem(item);
|
fBaudrateMenu->AddItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message = new BMessage(kMsgCustomBaudrate);
|
||||||
|
BMenuItem* custom = new BMenuItem("custom" B_UTF8_ELLIPSIS, message);
|
||||||
|
fBaudrateMenu->AddItem(custom);
|
||||||
|
|
||||||
fBaudrateMenu->SetTargetForItems(be_app);
|
fBaudrateMenu->SetTargetForItems(be_app);
|
||||||
|
|
||||||
message = new BMessage(kMsgSettings);
|
message = new BMessage(kMsgSettings);
|
||||||
@@ -351,13 +355,25 @@ void SerialWindow::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (message->FindInt32("baudrate", &baudrate) == B_OK) {
|
if (message->FindInt32("baudrate", &baudrate) == B_OK) {
|
||||||
for (int i = 0; i < fBaudrateMenu->CountItems(); i++) {
|
int i;
|
||||||
BMenuItem* item = fBaudrateMenu->ItemAt(i);
|
BMenuItem* item = NULL;
|
||||||
int32 code;
|
for (i = 0; i < fBaudrateMenu->CountItems(); i++) {
|
||||||
|
item = fBaudrateMenu->ItemAt(i);
|
||||||
|
int32 code = 0;
|
||||||
item->Message()->FindInt32("baudrate", &code);
|
item->Message()->FindInt32("baudrate", &code);
|
||||||
|
|
||||||
if (baudrate == code)
|
if (baudrate == code) {
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == fBaudrateMenu->CountItems() && item != NULL) {
|
||||||
|
// Rate was not found, mark it as "custom".
|
||||||
|
// Since that is the last item in the menu, we still point
|
||||||
|
// to it.
|
||||||
|
item->SetMarked(true);
|
||||||
|
item->Message()->SetInt32("baudrate", baudrate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user