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;
|
||||
memset(&mii, 0, sizeof(mii));
|
||||
mii.cbSize = sizeof(mii);
|
||||
mii.fMask = MIIM_STRING | MIIM_ID;
|
||||
if (checked)
|
||||
{
|
||||
mii.fMask |= MIIM_STATE;
|
||||
mii.fState = MFS_CHECKED;
|
||||
}
|
||||
mii.fMask = MIIM_STRING | MIIM_ID | MIIM_STATE;
|
||||
mii.fState = checked ? MFS_CHECKED : 0;
|
||||
mii.wID = id;
|
||||
mii.dwTypeData = (CHAR *) itemstr;
|
||||
mii.cch = strlen(mii.dwTypeData);
|
||||
@ -141,8 +137,6 @@ PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
|
||||
m_config.read(config_file);
|
||||
}
|
||||
|
||||
event_start();
|
||||
|
||||
/* Load the application icon */
|
||||
HICON icon = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
|
||||
if (icon == 0)
|
||||
@ -216,6 +210,8 @@ PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
|
||||
cerr << "Warning: Shell_NotifyIcon(): " << GetLastError() << endl;
|
||||
}
|
||||
|
||||
event_start();
|
||||
|
||||
/* begin capturing session notifications */
|
||||
session_notification_enable(m_hWnd);
|
||||
}
|
||||
@ -263,11 +259,20 @@ BOOL PPPC::mainLoop()
|
||||
}
|
||||
break;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
@ -296,16 +301,19 @@ void PPPC::event_start()
|
||||
{
|
||||
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:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||
break;
|
||||
case Config::OFF:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (m_config.entries[i].on_start)
|
||||
{
|
||||
case Config::ON:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||
break;
|
||||
case Config::OFF:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
update_pins();
|
||||
@ -315,16 +323,19 @@ void PPPC::event_exit()
|
||||
{
|
||||
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:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||
break;
|
||||
case Config::OFF:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (m_config.entries[i].on_exit)
|
||||
{
|
||||
case Config::ON:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||
break;
|
||||
case Config::OFF:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
update_pins();
|
||||
@ -334,40 +345,46 @@ void PPPC::event_lock()
|
||||
{
|
||||
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:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||
break;
|
||||
case Config::OFF:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (m_config.entries[i].on_lock)
|
||||
{
|
||||
case Config::ON:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||
break;
|
||||
case Config::OFF:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
update_pins();
|
||||
m_previous_pins = m_pins;
|
||||
update_pins();
|
||||
}
|
||||
|
||||
void PPPC::event_unlock()
|
||||
{
|
||||
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:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||
break;
|
||||
case Config::OFF:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||
break;
|
||||
case Config::PREVIOUS:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin,
|
||||
GET_BIT(m_previous_pins, m_config.entries[i].pin));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (m_config.entries[i].on_unlock)
|
||||
{
|
||||
case Config::ON:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 1);
|
||||
break;
|
||||
case Config::OFF:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin, 0);
|
||||
break;
|
||||
case Config::PREVIOUS:
|
||||
SET_BIT(m_pins, m_config.entries[i].pin,
|
||||
GET_BIT(m_previous_pins, m_config.entries[i].pin));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
update_pins();
|
||||
@ -375,5 +392,12 @@ void PPPC::event_unlock()
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user