include/basics.h
Go to the documentation of this file.
00001 #ifndef _BASICS_H_
00002 #define _BASICS_H_
00003 
00004 #include CONFIG_HEADER
00005 
00006 #include <stdint.h>
00007 #include <stdbool.h>
00008
00023 #define FRONT                   0x01
00024 #define FORWARD                         FRONT
00025 #define LEFT                    0x02
00026 #define RIGHT                   0x08
00027 #define BACK                    0x10
00028 #define BACKWARD                        BACK
00029 
00030 #define ANYDIR          (FRONT | BACK | LEFT | RIGHT)
00031 #define FRONT_LEFT      (FRONT | LEFT)
00032 #define FRONT_RIGHT     (FRONT | RIGHT)
00033 #define FRONT_BACK      (FRONT | BACK)
00034 #define LEFT_RIGHT      (LEFT | RIGHT)
00035 #define LEFT_BACK       (LEFT | BACK)
00036 #define FRONT_LEFT_RIGHT (FRONT | LEFT | RIGHT)
00037 #define LEFT_RIGHT_BACK (LEFT | RIGHT | BACK)
00038 #define RIGHT_BACK_FRONT (RIGHT | BACK | FRONT)
00039 
00040 /* this is no "real" direction */
00041 #define OFF                     0x00
00042 #define NODIR                   OFF
00043 
00046 /* Turning without moving forward */
00047 #define TURN                    0x20
00048 #define LEFT_TURN               0x22
00049 #define RIGHT_TURN              0x28
00050 
00051 /* Speeds */
00052 #define SLOW                    1
00053 #define MEDIUM                  2
00054 #define FAST                    3
00055 
00060 #define BROADCAST               0
00061 #define ANY_SOURCE              BROADCAST
00062 #define ANY_DEST                BROADCAST
00063 #define RC_SOURCE               16
00064 
00072 #define abs(x) ((x >= 0) ? (x) : (-x))
00073 
00075 #define GET_BIT(arr, bit)               ((arr[(bit)>>3] >> ((bit) & 0x07)) & 0x01)
00076 
00077 #define SET_BIT_COND(arr, bit, val)     ((arr[(bit)>>3] |= ((val) << ((bit) & 0x07))))
00078 
00079 #define SET_BIT(arr, bit)               SET_BIT_COND(arr, bit, 1)
00080 
00081 #define CLEAR_BIT_COND(arr, bit, val)   ((arr[(bit)>>3] &= ~((val) << ((bit) & 0x07))))
00082 
00083 #define CLEAR_BIT(arr, bit)             CLEAR_BIT_COND(arr, bit, 1)
00084 
00085 #define CHANGE_BIT(arr, bit, val)       do { CLEAR_BIT(arr, bit); SET_BIT_COND(arr, bit, val); } while (0)
00086 
00089 extern uint8_t dirs[4];
00090
00091 typedef signed char int8;
00092 typedef uint8_t uint8;
00093 typedef uint16_t uint16;
00094 typedef uint32_t uint32;
00095
00096 uint8_t opposite_dir(uint8_t);
00097 uint8_t turn_dir(uint8_t);
00098
00102 uint8_t id(void);
00103
00106 uint8_t get_user_switches(void);
00107
00110 uint8_t get_user_switch1(void);
00111
00114 uint8_t get_user_switch2(void);
00115
00117 void init_all(void);
00118
00119 #endif // _BASICS_H_