Skip to content

Commit

Permalink
Integrated a CW mode combo box
Browse files Browse the repository at this point in the history
  • Loading branch information
bubnikv committed Nov 14, 2017
1 parent 4124174 commit ad4b61d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Config.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#define EXTIO_EXPORTS 1
#define HWNAME "ExtIO_Omnia-0.1"
#define HWNAME "ExtIO_Omnia-0.2"
#define HWMODEL "ExtIO_Omnia"
#define SETTINGS_IDENTIFIER "ExtIO_Omnia-0.1"
#define SETTINGS_IDENTIFIER "ExtIO_Omnia-0.2"
// 5.3ms latency
#define EXT_BLOCKLEN (512) /* only multiples of 512 */
#define ZEROS_TO_MUTE (32)
Expand Down
4 changes: 4 additions & 0 deletions ExtIO_Omnia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ long EXTIO_API GetHWSR(void)
// extern "C" char EXTIO_API GetMode(void);
extern "C" void EXTIO_API ModeChanged(char mode)
{
char buf[2048];
sprintf(buf, "Mode changed: %c\n", mode);
OutputDebugStringA(buf);
g_UIHooks.show_my_panel(mode == 'C');
}

// extern "C" void EXTIO_API IFLimitsChanged(long low, long high);
Expand Down
43 changes: 34 additions & 9 deletions UIHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define ID_CWKEYER_TEXT (ID_UIHOOKS_FIRST + 1)
#define ID_CWKEYER_MODE (ID_UIHOOKS_FIRST + 2)

static int keyer_modes[] = { IAMBIC_SKEY, 0, IAMBIC_MODE_B };
static wchar_t *keyer_mode_names[] = { L"Straight Key", L"Iambic A", L"Iambic B" };

static UIHooks *g_uihooks = nullptr;
extern Cat g_Cat;

Expand Down Expand Up @@ -52,6 +55,13 @@ void UIHooks::destroy()
this->hwndButton2 = nullptr;
}

void UIHooks::show_my_panel(bool show)
{
this->my_panel_shown = show;
::ShowWindow(this->hwndMyPanel, show ? SW_SHOW : SW_HIDE);
m_layout_invalid = true;
}

void UIHooks::show_secondary_waterfall(bool show)
{
this->secondary_waterfall_show = show;
Expand Down Expand Up @@ -199,6 +209,15 @@ LRESULT CALLBACK UIHooks::MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l
// ::MessageBoxA(g_uihooks->hwndMainFrame, "Button2 pressed", "Test", 0);
// Toggle visibility of the secondary waterfall controls.
g_uihooks->show_waterfall_controls(!g_uihooks->waterfall_controls_shown);
} else if ((HWND)lParam == g_uihooks->hwndKeyerMode) {
if (HIWORD(wParam) == CBN_SELCHANGE) {
DWORD mode = SendMessage(g_uihooks->hwndKeyerMode, CB_GETCURSEL, 0, 0);
if (mode < 0)
mode = 0;
else if (mode >= 3)
mode = 2;
g_Cat.set_cw_keyer_mode(keyer_modes[mode]);
}
}
break;
case WM_HSCROLL:
Expand Down Expand Up @@ -277,7 +296,7 @@ bool UIHooks::create_my_panel()
this->hwndButton1 = ::CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed
L"MsgBox", // Button text
WS_VISIBLE | WS_CHILD, // Styles
/* WS_VISIBLE | */ WS_CHILD, // Styles
10, // x position
10, // y position
100, // Button width
Expand All @@ -289,7 +308,7 @@ bool UIHooks::create_my_panel()
this->hwndButton2 = ::CreateWindow(
L"BUTTON", // Predefined class; Unicode assumed
L"Hide", // Button text
WS_VISIBLE | WS_CHILD, // Styles
/* WS_VISIBLE | */ WS_CHILD, // Styles
10, // x position
35, // y position
100, // Button width
Expand All @@ -298,22 +317,27 @@ bool UIHooks::create_my_panel()
nullptr, // No menu.
wc.hInstance,
nullptr); // Pointer not needed.
int x = 10;
int w = 200;
this->hwndKeyerSpeedTrackBar = CreateWindowEx(0, TRACKBAR_CLASS, L"Trackbar",
WS_CHILD | WS_VISIBLE /* | TBS_AUTOTICKS | TBS_ENABLESELRANGE */,
120, 10, 200, 40, this->hwndMyPanel, (HMENU)ID_CWKEYER_TRACKBAR, wc.hInstance, nullptr);
x, 10, w, 40, this->hwndMyPanel, (HMENU)ID_CWKEYER_TRACKBAR, wc.hInstance, nullptr);
x += w + 10;
w = 100;
this->hwndKeyerSpeedText = CreateWindow(L"STATIC", L"teststring", WS_CHILD | WS_VISIBLE,
340, 10, 100, 40, this->hwndMyPanel, (HMENU)(ID_CWKEYER_TEXT), wc.hInstance, nullptr);
x, 10, w, 40, this->hwndMyPanel, (HMENU)(ID_CWKEYER_TEXT), wc.hInstance, nullptr);
x += w + 10;
w = 80;
this->hwndKeyerMode = CreateWindow(WC_COMBOBOX, L"",
CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE,
460, 10, 80, 40, this->hwndMyPanel, (HMENU)(ID_CWKEYER_MODE), wc.hInstance, nullptr);
x, 10, w, 40, this->hwndMyPanel, (HMENU)(ID_CWKEYER_MODE), wc.hInstance, nullptr);

SendMessage(this->hwndKeyerSpeedTrackBar, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(5, 45));
SendMessage(this->hwndKeyerSpeedTrackBar, TBM_SETPAGESIZE, 0, (LPARAM)5);
this->set_keyer_speed(18);

wchar_t *modes[] = { L"Straight Key", L"Iambic A", L"Iambic B" };
for (int i = 0; i < 3; ++ i)
::SendMessage(this->hwndKeyerMode, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)modes[i]);
::SendMessage(this->hwndKeyerMode, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)keyer_mode_names[i]);
::SendMessage(this->hwndKeyerMode, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);

this->update_layout();
Expand All @@ -339,7 +363,8 @@ void UIHooks::update_layout()
::ScreenToClient(this->hwndLower, (LPPOINT)&rectRight.left);
::ScreenToClient(this->hwndLower, (LPPOINT)&rectRight.right);
DWORD width = clientRect.right - rectLeft.right - 1;
DWORD height = (clientRect.bottom - rectLeft.top) / 2;
DWORD height = clientRect.bottom - rectLeft.top;
height -= (this->my_panel_shown ? 50 : 1);
// ::MoveWindow(this->hwndLowerRight, rectLeft.right, waterfall_controls_shown ? rectLeft.top : (rectLeft.top - 100), width, waterfall_controls_shown ? height : (height + 200), TRUE);
if (this->waterfall_controls_shown)
::MoveWindow(this->hwndLowerRight, rectLeft.right, rectLeft.top, width, height, TRUE);
Expand All @@ -353,7 +378,7 @@ void UIHooks::update_layout()
::MoveWindow(this->hwndLowerRight, rectLeft.right, rectLeft.top, width, height + (r.bottom - r.top) - 5, TRUE);
}
// ::MoveWindow(this->hwndSecondaryWaterfall, rectLeft.right, waterfall_controls_shown ? rectLeft.top : (rectLeft.top - 100), width, waterfall_controls_shown ? height : (height + 200), TRUE);
::SetWindowPos(this->hwndMyPanel, HWND_TOP, rectLeft.right, rectLeft.top + height, width, height - 1, SWP_SHOWWINDOW);
::SetWindowPos(this->hwndMyPanel, my_panel_shown ? HWND_TOP : 0, rectLeft.right, rectLeft.top + height, width, height - 1, my_panel_shown ? SWP_SHOWWINDOW : SWP_HIDEWINDOW);
g_uihooks->m_layout_invalid = false;
}
}
Expand Down
2 changes: 2 additions & 0 deletions UIHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class UIHooks

void show_secondary_waterfall(bool show);
void show_waterfall_controls(bool show);
void show_my_panel(bool show);

void set_keyer_speed(unsigned int speed);

Expand Down Expand Up @@ -54,6 +55,7 @@ class UIHooks

bool secondary_waterfall_show = true;
bool waterfall_controls_shown = true;
bool my_panel_shown = false;

private:
static BOOL CALLBACK EnumTopLevelWindowsProc(HWND hwnd, LPARAM lparam);
Expand Down
12 changes: 12 additions & 0 deletions cat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ bool Cat::set_cw_keyer_speed(int wpm)
return retval == 1;
}

bool Cat::set_cw_keyer_mode(int mode)
{
// OK1IAK, Command 0x66:
// Set keyer mode.
unsigned char umode = (unsigned char)mode + 0x80;
int retval = libusb_control_transfer(m_libusb_device_handle,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
0x66 /* REQUEST_SET_CW_KEYER_MODE */, 0x700 + 0x55, 0,
&umode, 1, 500);
return retval == 1;
}

/*
void Cat::start()
{
Expand Down
6 changes: 6 additions & 0 deletions cat.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
#define USBDEV_SHARED_PRODUCT 0x05DC // OBDEV PID
#define VENDOR_NAME_OBDEV "www.obdev.at"

#define IAMBIC_MODE_B (1 << 0)
#define IAMBIC_SKEY (1 << 1)
#define IAMBIC_AUTOSPACE (1 << 2)
#define IAMBIC_RST_N (1 << 7)

class Cat {
public:
Cat() {}
Expand All @@ -43,6 +48,7 @@ class Cat {
// Set the CW keyer speed in Words per Minute.
// Limited to <5, 45>
bool set_cw_keyer_speed(int wpm);
bool set_cw_keyer_mode(int mode);

private:
int findPeaberryDevice();
Expand Down

0 comments on commit ad4b61d

Please sign in to comment.