2013-02-04 13:53:45 +00:00
/*
Copyright 2013 Jun Wako < wakojun @ gmail . com >
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef ACTION_MACRO_H
# define ACTION_MACRO_H
# include <stdint.h>
2014-06-16 15:57:59 +00:00
# include "progmem.h"
2013-02-04 13:53:45 +00:00
2014-06-16 15:57:59 +00:00
# define MACRO_NONE 0
# define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })
# define MACRO_GET(p) pgm_read_byte(p)
2013-02-25 06:30:37 +00:00
2013-02-04 13:53:45 +00:00
typedef uint8_t macro_t ;
2013-03-19 15:28:13 +00:00
# ifndef NO_ACTION_MACRO
2013-05-20 13:42:29 +00:00
void action_macro_play ( const macro_t * macro_p ) ;
2013-03-19 15:28:13 +00:00
# else
# define action_macro_play(macro)
# endif
2013-02-04 13:53:45 +00:00
2013-07-22 22:45:25 +00:00
/* Macro commands
* code ( 0x04 - 73 ) // key down(1byte)
* code ( 0x04 - 73 ) | 0x80 // key up(1byte)
* { KEY_DOWN , code ( 0x04 - 0xff ) } // key down(2bytes)
* { KEY_UP , code ( 0x04 - 0xff ) } // key up(2bytes)
* WAIT // wait milli-seconds
* INTERVAL // set interval between macro commands
* END // stop macro execution
*
* Ideas ( Not implemented ) :
* modifiers
* system usage
* consumer usage
* unicode usage
* function call
* conditionals
* loop
*/
2013-02-04 13:53:45 +00:00
enum macro_command_id {
/* 0x00 - 0x03 */
END = 0x00 ,
2013-07-22 22:45:25 +00:00
KEY_DOWN ,
KEY_UP ,
/* 0x04 - 0x73 (reserved for keycode down) */
2013-02-04 13:53:45 +00:00
2013-07-22 22:45:25 +00:00
/* 0x74 - 0x83 */
2013-02-04 13:53:45 +00:00
WAIT = 0x74 ,
INTERVAL ,
2013-07-22 22:45:25 +00:00
/* 0x84 - 0xf3 (reserved for keycode up) */
2013-02-04 13:53:45 +00:00
2013-07-22 22:45:25 +00:00
/* 0xf4 - 0xff */
2013-02-04 13:53:45 +00:00
} ;
2013-07-22 22:45:25 +00:00
/* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed
* if keycode between 0x04 and 0x73
* keycode / ( keycode | 0x80 )
* else
* { KEY_DOWN , keycode } / { KEY_UP , keycode }
*/
# define DOWN(key) KEY_DOWN, (key)
# define UP(key) KEY_UP, (key)
# define TYPE(key) DOWN(key), UP(key)
2013-02-04 13:53:45 +00:00
# define WAIT(ms) WAIT, (ms)
# define INTERVAL(ms) INTERVAL, (ms)
2013-07-22 22:45:25 +00:00
/* key down */
2013-02-04 13:53:45 +00:00
# define D(key) DOWN(KC_##key)
2013-07-22 22:45:25 +00:00
/* key up */
2013-02-04 13:53:45 +00:00
# define U(key) UP(KC_##key)
2013-07-22 22:45:25 +00:00
/* key type */
2013-02-04 13:53:45 +00:00
# define T(key) TYPE(KC_##key)
2013-07-22 22:45:25 +00:00
/* wait */
2013-02-04 13:53:45 +00:00
# define W(ms) WAIT(ms)
2013-07-22 22:45:25 +00:00
/* interval */
2013-02-04 13:53:45 +00:00
# define I(ms) INTERVAL(ms)
2013-07-22 22:45:25 +00:00
/* for backward comaptibility */
# define MD(key) DOWN(KC_##key)
# define MU(key) UP(KC_##key)
2013-02-04 13:53:45 +00:00
# endif /* ACTION_MACRO_H */