SerialConnect: allow custom baudrates from the GUI
This commit is contained in:
parent
3b4f50d3fb
commit
96e59cca3c
68
src/apps/serialconnect/CustomRateWindow.cpp
Normal file
68
src/apps/serialconnect/CustomRateWindow.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2016, Adrien Destugues, pulkomandy@pulkomandy.tk
|
||||
* 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);
|
||||
}
|
28
src/apps/serialconnect/CustomRateWindow.h
Normal file
28
src/apps/serialconnect/CustomRateWindow.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2016, Adrien Destugues, pulkomandy@pulkomandy.tk
|
||||
* 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 ;
|
||||
|
||||
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 ] ;
|
||||
|
||||
Application SerialConnect :
|
||||
CustomRateWindow.cpp
|
||||
SerialApp.cpp
|
||||
SerialWindow.cpp
|
||||
TermView.cpp
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
|
||||
#include "CustomRateWindow.h"
|
||||
#include "SerialWindow.h"
|
||||
|
||||
|
||||
@ -146,6 +147,13 @@ void SerialApp::MessageReceived(BMessage* message)
|
||||
debugger("Invalid BMessage received");
|
||||
return;
|
||||
}
|
||||
case kMsgCustomBaudrate:
|
||||
{
|
||||
// open the custom baudrate selector window
|
||||
CustomRateWindow* window = new CustomRateWindow(fSerialPort.DataRate());
|
||||
window->Show();
|
||||
return;
|
||||
}
|
||||
case kMsgSettings:
|
||||
{
|
||||
int32 baudrate;
|
||||
|
@ -52,11 +52,12 @@ class SerialApp: public BApplication
|
||||
|
||||
|
||||
enum messageConstants {
|
||||
kMsgDataRead = 'dare',
|
||||
kMsgDataWrite = 'dawr',
|
||||
kMsgLogfile = 'logf',
|
||||
kMsgOpenPort = 'open',
|
||||
kMsgSettings = 'stty',
|
||||
kMsgCustomBaudrate = 'cust',
|
||||
kMsgDataRead = 'dard',
|
||||
kMsgDataWrite = 'dawr',
|
||||
kMsgLogfile = 'logf',
|
||||
kMsgOpenPort = 'open',
|
||||
kMsgSettings = 'stty',
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -174,6 +174,10 @@ SerialWindow::SerialWindow()
|
||||
fBaudrateMenu->AddItem(item);
|
||||
}
|
||||
|
||||
message = new BMessage(kMsgCustomBaudrate);
|
||||
BMenuItem* custom = new BMenuItem("custom" B_UTF8_ELLIPSIS, message);
|
||||
fBaudrateMenu->AddItem(custom);
|
||||
|
||||
fBaudrateMenu->SetTargetForItems(be_app);
|
||||
|
||||
message = new BMessage(kMsgSettings);
|
||||
@ -351,13 +355,25 @@ void SerialWindow::MessageReceived(BMessage* message)
|
||||
}
|
||||
|
||||
if (message->FindInt32("baudrate", &baudrate) == B_OK) {
|
||||
for (int i = 0; i < fBaudrateMenu->CountItems(); i++) {
|
||||
BMenuItem* item = fBaudrateMenu->ItemAt(i);
|
||||
int32 code;
|
||||
int i;
|
||||
BMenuItem* item = NULL;
|
||||
for (i = 0; i < fBaudrateMenu->CountItems(); i++) {
|
||||
item = fBaudrateMenu->ItemAt(i);
|
||||
int32 code = 0;
|
||||
item->Message()->FindInt32("baudrate", &code);
|
||||
|
||||
if (baudrate == code)
|
||||
if (baudrate == code) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user