implement button press/release with double check using coroutine
coroutine.h@0:54509830df20, 2016-08-28 (annotated)
- Committer:
- mintisan
- Date:
- Sun Aug 28 12:50:45 2016 +0000
- Revision:
- 0:54509830df20
implement button press/release with double check using coroutine
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mintisan | 0:54509830df20 | 1 | #ifndef COROUTINE_H_ |
mintisan | 0:54509830df20 | 2 | #define COROUTINE_H_ |
mintisan | 0:54509830df20 | 3 | |
mintisan | 0:54509830df20 | 4 | #ifdef __cplushplus |
mintisan | 0:54509830df20 | 5 | extern "C"{ |
mintisan | 0:54509830df20 | 6 | #endif |
mintisan | 0:54509830df20 | 7 | |
mintisan | 0:54509830df20 | 8 | /** |
mintisan | 0:54509830df20 | 9 | * C coroutine |
mintisan | 0:54509830df20 | 10 | * https://github.com/mintisan/mintisan.github.io/wiki/C#coroutine |
mintisan | 0:54509830df20 | 11 | */ |
mintisan | 0:54509830df20 | 12 | |
mintisan | 0:54509830df20 | 13 | #define cr_start() \ |
mintisan | 0:54509830df20 | 14 | static int __s = 0; \ |
mintisan | 0:54509830df20 | 15 | switch(__s){ \ |
mintisan | 0:54509830df20 | 16 | case 0: |
mintisan | 0:54509830df20 | 17 | |
mintisan | 0:54509830df20 | 18 | // '\' doesn't count for one line in C |
mintisan | 0:54509830df20 | 19 | #define cr_yield(condition) do{ \ |
mintisan | 0:54509830df20 | 20 | __s = __LINE__ ; \ |
mintisan | 0:54509830df20 | 21 | case __LINE__: \ |
mintisan | 0:54509830df20 | 22 | if(condition) \ |
mintisan | 0:54509830df20 | 23 | return; \ |
mintisan | 0:54509830df20 | 24 | }while(0) |
mintisan | 0:54509830df20 | 25 | |
mintisan | 0:54509830df20 | 26 | #define cr_end() \ |
mintisan | 0:54509830df20 | 27 | } __s = 0; |
mintisan | 0:54509830df20 | 28 | |
mintisan | 0:54509830df20 | 29 | |
mintisan | 0:54509830df20 | 30 | #ifdef __cplushplus |
mintisan | 0:54509830df20 | 31 | } |
mintisan | 0:54509830df20 | 32 | #endif |
mintisan | 0:54509830df20 | 33 | |
mintisan | 0:54509830df20 | 34 | #endif |