key states naming convention

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to define the 4 different key states:

1. the key changes from release to pressed
2. the key was held down
3. the key changes from pressed to released
4. the key was in the released state

English is not my native language.
Which naming would be clearly to understand?

enum key_states { PRESS, DOWN, RELEASE, UP };

or:

enum key_states { PRESS_ACTION, PRESSED_STATE, RELEASE_ACTION, RELEASED_STATE };

or other suggestions?

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well the PS/2 interface would call that:

1) "make"
2) "repeat"
3) "break"
4) no name for this

(2) only so called because what happens when a key is held is that the controller repeatedly sends more "make" codes and the keyboard repeat rate (usually something like 50ms)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PRESS, DOWN, RELEASE, UP

or

PRESS, CLOSED, RELEASE, OPEN

Just my opinion. Probably UP is less ambiguous than OPEN, as OPEN could be an action.

Or, to align with Cliff,

MAKE, MADE, BREAK, BROKEN. :D

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HI Danni,

As you are probably realising "English As She Is Spoke" is an ambiguous language, so a word like 'up' can imply both that the key is up or that it is moving up... your number 2 suggestions are unambiguous, but I would suggest a mix of the two that may be more reader friendly:

Key_pressed
Key_down
Key_released
Key_up

If you have no fears of using longer names:

Key_has_been_pressed
Key_is_down
Key_has_been_released
Key_is_up

or to be formal but very precise

Key_change_down
Key_static_down
Key_change_up
Key_static_up

(perhaps you need the new quantum AVR which will hold all four key states in one qbit)

Cheers,

Joey

Last Edited: Fri. Aug 12, 2011 - 10:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

up and down could also be ambiguous. If you have a switch ( that is also a key itself) is in the UP position, but closed.

You could use the actual level on the key. Like HIGH and LOW. This would then also give you the state of the actual IO line.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RIGHT_NOW_IT_IS_POSSIBLE_FOR_ELECTRONS_TO_FLOW_THROUGH_THE_SWITCH_ALTHOUGH_THAT_WAS_NOT_THE_CASE_THE_LAST_TIME_I_CHECKED, RIGHT_NOW_IT_IS_POSSIBLE_FOR_ELECTRONS_TO_FLOW_THROUGH_THE_SWITCH_WHICH_WAS_ALSO_THE_CASE_THE_LAST_TIME_I_CHECKED,
RIGHT_NOW_IT_IS_NOT_POSSIBLE_FOR_ELECTRONS_TO_FLOW_THROUGH_THE_SWITCH_ALTHOUGH_IT_WAS_BEFORE,
RIGHT_NOW_IT_IS_NOT_POSSIBLE_FOR_ELECTRONS_TO_FLOW_THROUGH_THE_SWITCH_WHICH_I_NOTICED_WAS_ALSO_THE_CASE_WHEN_I_CHECKED_LAST_TIME

Of course one should probably make mention of the debouncing parameters, also, but I don't want to risk Repetitive Underscore Injury.

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

are you sure that the compiler will understand this?
might be that the names are too long and will be truncated.....
that would give a mess.....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1) RISING -- logical rising edge on the signal
2) MADE (I'd use HELD for being MADE for a long duration, such as key held down for 1+ second)
3) FALLING -- logical falling edge on the signal
4)

About 1) and 3) -- I almost always use positive logic inside my program, inverting any active-low signals before debouncing and other processing.

About 2) and 4) -- I use a "current state" bit along with a "rising edge" bit (and a "falling edge" bit when needed by the app) so each bit is either on/made--or not.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We are all wrong, of course.

The correct answer is "It doesn't matter as long as you comment the code properly".

Cheers,

Joey

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

    falling edge low state
    rising edge
    high state

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would vote for the high, low, rising, falling suggestion. Maybe more formally as:

STATE_LOW
STATE_RISING
STATE_HIGH
STATE_FALLING

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually I find the terminology from PC keyboards best. But it only defines three of those four. As already said above, my vote is like this:
1) make
2) repeat
3) break
4) hmm, depressed?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I always called the edge condition an onshot or an offshot. I guess a oneshot would be either edge, also useful.

char sw;      //state
char swl;     //last pass
char swonos;  //switch 'going on'
char swoffos; //switch 'going off'

  sw=(PINA & 0x01)==0; //switch state
  swonos=sw && !swl;   //look for on edge
  swoffos= !sw && swl; //look for off edge
  swl=sw;              //remember last pass

  if(swonos) //etc

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

STATE_LOW
STATE_RISING
STATE_HIGH
STATE_FALLING

Gets my vote for best clarity.