added logic to handle manual:on and manual:off modes and update menu checkboxes when user changes modes
git-svn-id: http://apu.dw.local/svnusers/JoshHoltrop/pppc/trunk@64 8131a0b2-b21c-1c47-bd6a-f003126495bd
This commit is contained in:
parent
7fec0f3be8
commit
e9c85c729e
128
pppc.cc
128
pppc.cc
@ -117,12 +117,8 @@ void updateMenuInfo(HMENU hMenu, int index, const CHAR * itemstr, WORD id, bool
|
|||||||
MENUITEMINFO mii;
|
MENUITEMINFO mii;
|
||||||
memset(&mii, 0, sizeof(mii));
|
memset(&mii, 0, sizeof(mii));
|
||||||
mii.cbSize = sizeof(mii);
|
mii.cbSize = sizeof(mii);
|
||||||
mii.fMask = MIIM_STRING | MIIM_ID;
|
mii.fMask = MIIM_STRING | MIIM_ID | MIIM_STATE;
|
||||||
if (checked)
|
mii.fState = checked ? MFS_CHECKED : 0;
|
||||||
{
|
|
||||||
mii.fMask |= MIIM_STATE;
|
|
||||||
mii.fState = MFS_CHECKED;
|
|
||||||
}
|
|
||||||
mii.wID = id;
|
mii.wID = id;
|
||||||
mii.dwTypeData = (CHAR *) itemstr;
|
mii.dwTypeData = (CHAR *) itemstr;
|
||||||
mii.cch = strlen(mii.dwTypeData);
|
mii.cch = strlen(mii.dwTypeData);
|
||||||
@ -141,8 +137,6 @@ PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
|
|||||||
m_config.read(config_file);
|
m_config.read(config_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
event_start();
|
|
||||||
|
|
||||||
/* Load the application icon */
|
/* Load the application icon */
|
||||||
HICON icon = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
|
HICON icon = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
|
||||||
if (icon == 0)
|
if (icon == 0)
|
||||||
@ -216,6 +210,8 @@ PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
|
|||||||
cerr << "Warning: Shell_NotifyIcon(): " << GetLastError() << endl;
|
cerr << "Warning: Shell_NotifyIcon(): " << GetLastError() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event_start();
|
||||||
|
|
||||||
/* begin capturing session notifications */
|
/* begin capturing session notifications */
|
||||||
session_notification_enable(m_hWnd);
|
session_notification_enable(m_hWnd);
|
||||||
}
|
}
|
||||||
@ -263,11 +259,20 @@ BOOL PPPC::mainLoop()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
switch (LOWORD(msg.wParam)) /* menu entry index */
|
|
||||||
{
|
{
|
||||||
case 0: /* exit */
|
int menu_index = LOWORD(msg.wParam);
|
||||||
|
if (menu_index == 0)
|
||||||
|
{
|
||||||
running = false;
|
running = false;
|
||||||
break;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int config_index = ((menu_index >> 8) & 0xFF) - 1;
|
||||||
|
int mode_index = ((menu_index) & 0xFF) - 1;
|
||||||
|
m_modes[config_index] = (ConfigEntryMode) mode_index;
|
||||||
|
updateConfigMenus(config_index);
|
||||||
|
update_pins();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -296,16 +301,19 @@ void PPPC::event_start()
|
|||||||
{
|
{
|
||||||
for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
|
for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
|
||||||
{
|
{
|
||||||
switch (m_config.entries[i].on_start)
|
if (m_modes[i] == AUTO)
|
||||||
{
|
{
|
||||||
case Config::ON:
|
switch (m_config.entries[i].on_start)
|
||||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
{
|
||||||
break;
|
case Config::ON:
|
||||||
case Config::OFF:
|
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
break;
|
||||||
break;
|
case Config::OFF:
|
||||||
default:
|
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_pins();
|
update_pins();
|
||||||
@ -315,16 +323,19 @@ void PPPC::event_exit()
|
|||||||
{
|
{
|
||||||
for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
|
for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
|
||||||
{
|
{
|
||||||
switch (m_config.entries[i].on_exit)
|
if (m_modes[i] == AUTO)
|
||||||
{
|
{
|
||||||
case Config::ON:
|
switch (m_config.entries[i].on_exit)
|
||||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
{
|
||||||
break;
|
case Config::ON:
|
||||||
case Config::OFF:
|
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
break;
|
||||||
break;
|
case Config::OFF:
|
||||||
default:
|
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_pins();
|
update_pins();
|
||||||
@ -334,40 +345,46 @@ void PPPC::event_lock()
|
|||||||
{
|
{
|
||||||
for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
|
for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
|
||||||
{
|
{
|
||||||
switch (m_config.entries[i].on_lock)
|
if (m_modes[i] == AUTO)
|
||||||
{
|
{
|
||||||
case Config::ON:
|
switch (m_config.entries[i].on_lock)
|
||||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
{
|
||||||
break;
|
case Config::ON:
|
||||||
case Config::OFF:
|
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
break;
|
||||||
break;
|
case Config::OFF:
|
||||||
default:
|
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_pins();
|
|
||||||
m_previous_pins = m_pins;
|
m_previous_pins = m_pins;
|
||||||
|
update_pins();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PPPC::event_unlock()
|
void PPPC::event_unlock()
|
||||||
{
|
{
|
||||||
for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
|
for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
|
||||||
{
|
{
|
||||||
switch (m_config.entries[i].on_unlock)
|
if (m_modes[i] == AUTO)
|
||||||
{
|
{
|
||||||
case Config::ON:
|
switch (m_config.entries[i].on_unlock)
|
||||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
{
|
||||||
break;
|
case Config::ON:
|
||||||
case Config::OFF:
|
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
break;
|
||||||
break;
|
case Config::OFF:
|
||||||
case Config::PREVIOUS:
|
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||||
SET_BIT(m_pins, m_config.entries[i].pin,
|
break;
|
||||||
GET_BIT(m_previous_pins, m_config.entries[i].pin));
|
case Config::PREVIOUS:
|
||||||
break;
|
SET_BIT(m_pins, m_config.entries[i].pin,
|
||||||
default:
|
GET_BIT(m_previous_pins, m_config.entries[i].pin));
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_pins();
|
update_pins();
|
||||||
@ -375,5 +392,12 @@ void PPPC::event_unlock()
|
|||||||
|
|
||||||
void PPPC::update_pins()
|
void PPPC::update_pins()
|
||||||
{
|
{
|
||||||
|
for (int sz = m_config.num_entries(), i = 0; i < sz; i++)
|
||||||
|
{
|
||||||
|
if (m_modes[i] == MANUAL_OFF)
|
||||||
|
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||||
|
else if (m_modes[i] == MANUAL_ON)
|
||||||
|
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||||
|
}
|
||||||
pport_write(m_pins);
|
pport_write(m_pins);
|
||||||
}
|
}
|
||||||
|
2
pppc.h
2
pppc.h
@ -11,7 +11,7 @@
|
|||||||
class PPPC
|
class PPPC
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ConfigEntryMode { AUTO, MANUAL_OFF, MANUAL_ON };
|
enum ConfigEntryMode { AUTO = 0, MANUAL_OFF = 1, MANUAL_ON = 2 };
|
||||||
static const char * ConfigEntryCaptions[3];
|
static const char * ConfigEntryCaptions[3];
|
||||||
|
|
||||||
PPPC(HINSTANCE hInstance, const char * config_file = NULL);
|
PPPC(HINSTANCE hInstance, const char * config_file = NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user