We had a customer ask how he might solve this situation with multiple triggers for an alarm:
"…several conditions may trigger the alarm, and I typically use each of these conditions to set an 'alarm flag.' There needs to be a provision for a supervisory override to a specific alarm condition, essentially disabling this trigger. I plan to do that through another flag set via password protected Display screen."
The first thing that popped in my geeky head went something like this:
nTriggerFlags is a bitmask holding up to 32 (or 64 if you use an int64) different triggers. A bit is set if that trigger happens.
nSuperEnableFlags is also a bitmask, initially set to all 1s meaning the Super has not disabled anything yet = 0xFFFFFFFF (in hex, assuming 32 bits here). Bit gets set back to 1 when we no longer want to override something. Set to 0 to disable the flag.
nAlarmFlags is the triggers w/the super override taken into account
code loops around a few lines like this:
nAlarmFlags = nSuperEnableFlags bitand nTriggerFlags;
// check to see if at least one of the non-disabled triggers has been set
If (nAlarmFlags <> 0) then
<code to sound/ turn off, alarm here>
<delay X period of time> and loop back to top
[/INDENT]He wasn't familiar with the concept of a bitmask, so I promised him a bit more info on those.
Here's a decent video on the topic:
Besides using a bitmask, there are a couple other ways to solve this one. But before I suggest other ways, anyone care to share other ideas or links to good material to explain bitmasks?