├── .gitignore ├── .travis.yml ├── API ├── arrow_icons.xbm ├── ev3.c ├── ev3_array.c ├── ev3_bluetooth.c ├── ev3_button.c ├── ev3_button.core.c ├── ev3_button.led.c ├── ev3_button.lejos.c ├── ev3_button.nxc.c ├── ev3_command.c ├── ev3_lcd.c ├── ev3_output.c ├── ev3_sound.c ├── ev3_timer.c ├── ev3_timer.private.h ├── ev3_timer.ts.c ├── inputs │ ├── ev3_input.c │ ├── ev3_input.h │ ├── ev3_input_analog.c │ ├── ev3_input_analog.h │ ├── ev3_input_iic.c │ ├── ev3_input_iic.h │ ├── ev3_input_uart.c │ └── ev3_input_uart.h ├── large_font.xbm ├── large_icons.xbm ├── libev3api.pc.in ├── menu_icons.xbm ├── normal_font.xbm ├── normal_icons.xbm ├── sensors │ ├── c4ev3_compatibility.c │ ├── ev3_color.c │ ├── ev3_color.h │ ├── ev3_gyro.c │ ├── ev3_gyro.h │ ├── ev3_ir.c │ ├── ev3_ir.h │ ├── ev3_sensors.c │ ├── ev3_sensors.h │ ├── ev3_touch.c │ ├── ev3_touch.h │ ├── ev3_ultrasonic.c │ ├── ht_color.c │ ├── ht_color.h │ ├── ht_compass.c │ ├── ht_compass.h │ ├── ht_ir_v2.c │ ├── ht_ir_v2.h │ ├── nxt_sound.c │ ├── nxt_sound.h │ ├── nxt_temperature.c │ ├── nxt_temperature.h │ ├── pixy_cam.c │ ├── utility.c │ └── utility.h ├── small_font.xbm ├── small_icons.xbm └── tiny_font.xbm ├── LICENSE ├── Makefile ├── README.md ├── commands.pdf ├── contrib ├── bluetooth │ ├── bluetooth.c │ ├── bluetooth.h │ ├── bnep.h │ ├── cmtp.h │ ├── hci.h │ ├── hci_lib.h │ ├── hidp.h │ ├── l2cap.h │ ├── rfcomm.h │ ├── sco.h │ ├── sdp.h │ └── sdp_lib.h └── lms2012 │ ├── ev3_analog.h │ ├── ev3_basictypes.h │ ├── ev3_iic.h │ ├── ev3_typedata.h │ └── ev3_uart.h ├── examples ├── compatibility │ ├── ev3_color │ │ ├── ambient.c │ │ ├── color.c │ │ ├── reflect.c │ │ └── rgb.c │ ├── ev3_gyro │ │ ├── angle.c │ │ └── rate.c │ ├── ev3_touch.c │ └── ev3_ultrasonic.c ├── ev3_color.c ├── ev3_gyro.c ├── ev3_ir │ ├── proximity.c │ ├── remote.c │ └── seek.c ├── ev3_touch.c ├── ev3_ultrasonic │ ├── distance.c │ └── presence.c ├── ht_color │ ├── color.c │ └── rgb.c ├── ht_compass.c ├── ht_ir.c ├── nxt_sound.c ├── nxt_temperature.c └── pixy_cam.c ├── include ├── ev3.h ├── ev3_array.h ├── ev3_bluetooth.h ├── ev3_button.core.h ├── ev3_button.h ├── ev3_button.led.h ├── ev3_button.lejos.h ├── ev3_button.nxc.h ├── ev3_command.h ├── ev3_constants.h ├── ev3_lcd.h ├── ev3_output.h ├── ev3_sensors │ ├── c4ev3_compatibility.h │ ├── ev3_color.h │ ├── ev3_gyro.h │ ├── ev3_ir.h │ ├── ev3_sensors.h │ ├── ev3_touch.h │ ├── ev3_ultrasonic.h │ ├── ht_color.h │ ├── ht_compass.h │ ├── ht_ir_v2.h │ ├── nxt_sound.h │ ├── nxt_temperature.h │ └── pixy_cam.h ├── ev3_sound.h └── ev3_timer.h └── projects └── make ├── .gitignore ├── Makefile ├── README.md ├── common-config.mk ├── example ├── Makefile ├── main.c ├── main.h └── project-config.mk └── program-makefile.mk /.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | .DS_Store 3 | /.objs 4 | /.deps 5 | /installed 6 | /api-config.mk 7 | *.a 8 | *.pc 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | dist: trusty 3 | os: linux 4 | sudo: required 5 | 6 | git: 7 | depth: 5 8 | 9 | 10 | before_install: 11 | - wget -c http://www.codesourcery.com/sgpp/lite/arm/portal/package4571/public/arm-none-linux-gnueabi/arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 12 | - tar xjf arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 13 | - export PATH="$PWD/arm-2009q1/bin:$PATH" 14 | - sudo apt-get install -y libc6-i386 15 | 16 | before_script: 17 | - test ! -e API/libev3api.a || (echo "libev3api.a shouldn't be part of version control! Aborting..."; false) 18 | 19 | script: 20 | - make PREFIX=arm-none-linux-gnueabi- CFLAGS="-Wall -Wextra -Wno-unused-parameter -Wno-pointer-sign -fdata-sections -ffunction-sections" 21 | 22 | after_script: 23 | - make PREFIX=arm-none-linux-gnueabi- CFLAGS="-Os -Wl,--gc-sections" example 24 | - nm -g libev3api.a | tee symbols 25 | - grep InitEV3 symbols || (echo "libev3api.a doesn't contain symbols! Aborting..." && false) 26 | - nm -g a.out 27 | - nm -g a.out | grep InitEV3 || (echo "The InitEV3 constructor has not been included!! Aborting..." && false) 28 | -------------------------------------------------------------------------------- /API/arrow_icons.xbm: -------------------------------------------------------------------------------- 1 | #define arrow_icons_width 8 2 | #define arrow_icons_height 36 3 | static unsigned char arrow_icons_bits[] = { 4 | 0x00, 0x00, 0x08, 0x2A, 0x1C, 0x3E, 0x1C, 0x2A, 0x08, 0x00, 0x00, 0x00, 5 | 0x00, 0x00, 0x40, 0x60, 0x70, 0x78, 0x7C, 0x78, 0x70, 0x60, 0x40, 0x00, 6 | 0x00, 0x00, 0x04, 0x0C, 0x1C, 0x3C, 0x7C, 0x3C, 0x1C, 0x0C, 0x04, 0x00, 7 | }; 8 | -------------------------------------------------------------------------------- /API/ev3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 2 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see 35 | 36 | //////////////////////////////////////////////////////////////// 37 | // PRIVATE FUNCTIONS 38 | 39 | /*! 40 | * \brief Round the given number up to a nearest 32bit power of two. 41 | * \param v Number to round up. 42 | * \return Rounded number. 43 | * \remark see https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 44 | */ 45 | static 46 | size_t roundUpToNearestPowerOfTwo(size_t v) 47 | { 48 | v--; 49 | v |= v >> 1; 50 | v |= v >> 2; 51 | v |= v >> 4; 52 | v |= v >> 8; 53 | v |= v >> 16; 54 | v++; 55 | return v; 56 | } 57 | 58 | 59 | //////////////////////////////////////////////////////////////// 60 | // IMPLEMENTATION OF PUBLIC API 61 | 62 | bool CArrayInit(DynamicCArray *array, size_t elem_size, size_t elem_alignment, size_t initial_capacity) 63 | { 64 | *array = DYNAMIC_CARRAY_INITIALIZER(elem_size, elem_alignment); 65 | 66 | return CArrayEnsureCapacity(array, initial_capacity); 67 | } 68 | 69 | void CArrayFree(DynamicCArray *array) 70 | { 71 | free(array->elements); 72 | array->elements = NULL; 73 | array->capacity = 0; 74 | array->count = 0; 75 | } 76 | 77 | void *CArrayAccess(DynamicCArray *array, size_t index) 78 | { 79 | if (index >= array->count) 80 | return NULL; 81 | 82 | return array->elements + (index * array->element_stride); 83 | } 84 | 85 | bool CArrayEnsureFreeCapacity(DynamicCArray *array, size_t minReserve) 86 | { 87 | return CArrayEnsureCapacity(array, array->count + minReserve); 88 | } 89 | 90 | bool CArrayEnsureCapacity(DynamicCArray *array, size_t minCapacity) 91 | { 92 | if (array->capacity < minCapacity) 93 | return CArrayChangeCapacity(array, roundUpToNearestPowerOfTwo(minCapacity)); 94 | return true; 95 | } 96 | 97 | bool CArrayChangeCapacity(DynamicCArray *array, size_t newCapacity) 98 | { 99 | if (newCapacity == 0) 100 | { 101 | CArrayFree(array); 102 | return true; 103 | } 104 | 105 | size_t totalSize = array->element_stride * newCapacity; 106 | void *memory = realloc(array->elements, totalSize); 107 | if (memory == NULL) 108 | return false; 109 | 110 | array->elements = memory; 111 | array->capacity = newCapacity; 112 | if (array->count > array->capacity) 113 | array->count = array->capacity; 114 | 115 | return true; 116 | } 117 | 118 | void *CArrayStackPush(DynamicCArray *array) 119 | { 120 | if (!CArrayEnsureFreeCapacity(array, 1)) 121 | return NULL; 122 | 123 | array->count++; 124 | return CArrayAccess(array, array->count - 1); 125 | } 126 | 127 | bool CArrayStackPop(DynamicCArray *array) 128 | { 129 | if (array->count > 0) 130 | { 131 | array->count--; 132 | return true; 133 | } 134 | return false; 135 | } 136 | 137 | void *CArrayInsert(DynamicCArray *array, size_t index, size_t count) 138 | { 139 | if (index > array->count) 140 | return NULL; 141 | 142 | if (!CArrayEnsureFreeCapacity(array, count)) 143 | return NULL; 144 | 145 | void *shiftPrev = array->elements + (index * array->element_stride); 146 | void *shiftNext = shiftPrev + array->element_stride * count; 147 | size_t shiftLen = array->count - index + count; 148 | 149 | memmove(shiftNext, shiftPrev, shiftLen); 150 | 151 | array->count += count; 152 | return shiftPrev; 153 | } 154 | 155 | bool CArrayRemove(DynamicCArray *array, size_t index, size_t count) 156 | { 157 | if (index + count - 1 >= array->count) 158 | return false; 159 | 160 | if (array->elements == NULL) 161 | return false; // prevent UB in memmove 162 | 163 | void *shiftNext = array->elements + (index * array->element_stride); 164 | void *shiftPrev = shiftNext + array->element_stride * count; 165 | size_t shiftLen = array->count - index; 166 | 167 | memmove(shiftNext, shiftPrev, shiftLen); 168 | 169 | array->count -= count; 170 | return true; 171 | } 172 | 173 | bool CArrayMirror(DynamicCArray *destination, DynamicCArray *source) 174 | { 175 | if (destination->element_stride != source->element_stride) 176 | return false; 177 | 178 | if (!CArrayEnsureCapacity(destination, source->count)) 179 | return false; 180 | 181 | destination->count = source->count; 182 | 183 | if (destination->count == 0) 184 | return true; 185 | 186 | if (destination->elements == NULL || source->elements == NULL) 187 | return false; // prevent UB in memcpy 188 | 189 | memcpy(destination->elements, 190 | source->elements, 191 | source->element_stride * destination->count); 192 | 193 | return true; 194 | } 195 | -------------------------------------------------------------------------------- /API/ev3_button.c: -------------------------------------------------------------------------------- 1 | /** \file ev3_button.c 2 | * \brief Implementation of the button module 3 | * 4 | * License: 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see 31 | #include "ev3.h" 32 | #include "ev3_button.led.h" 33 | 34 | 35 | //////////////////////////////////////////////////////////////////////////////// 36 | // DATA STRUCTURES 37 | 38 | typedef struct 39 | { 40 | pthread_mutex_t lock; 41 | 42 | LEDPattern currentPattern; 43 | bool warningActive; 44 | bool initialized; 45 | } LEDs; 46 | 47 | static LEDs leds = { 48 | .lock = PTHREAD_MUTEX_INITIALIZER, 49 | .currentPattern = LEDPattern_Off, 50 | .warningActive = false, 51 | .initialized = false, 52 | }; 53 | 54 | //////////////////////////////////////////////////////////////////////////////// 55 | // PRIVATE FUNCTION DECLARATIONS 56 | 57 | /*! 58 | * \brief Upload new LED pattern to the kernel. 59 | * 60 | * The value to set will be taken from the global button module memory. 61 | * 62 | * \return Whether the operation succeeded or not. 63 | */ 64 | static bool btnRefreshLeds(void); 65 | 66 | //////////////////////////////////////////////////////////////////////////////// 67 | // IMPLEMENTATION 68 | 69 | bool LedInitialized(void) 70 | { 71 | pthread_mutex_lock(&leds.lock); 72 | bool retval = leds.initialized; 73 | pthread_mutex_unlock(&leds.lock); 74 | return retval; 75 | } 76 | 77 | bool LedInit(void) 78 | { 79 | pthread_mutex_lock(&leds.lock); 80 | 81 | if (leds.initialized) 82 | goto success; 83 | 84 | if (!ButtonCoreInit()) 85 | goto failure; 86 | 87 | leds.warningActive = false; 88 | leds.currentPattern = LEDPattern_PulsingGreen; 89 | if (!btnRefreshLeds()) 90 | goto failure; 91 | 92 | success: 93 | leds.initialized = true; 94 | pthread_mutex_unlock(&leds.lock); 95 | return true; 96 | 97 | failure: 98 | pthread_mutex_unlock(&leds.lock); 99 | LedExit(); 100 | return false; 101 | } 102 | 103 | bool LedExit(void) 104 | { 105 | bool success; 106 | pthread_mutex_lock(&leds.lock); 107 | 108 | if (leds.initialized) 109 | success = ButtonCoreSetLEDs(LEDPattern_SteadyGreen); 110 | else 111 | success = true; 112 | 113 | leds.initialized = false; 114 | 115 | pthread_mutex_unlock(&leds.lock); 116 | return success; 117 | } 118 | 119 | LEDPattern LedPattern() 120 | { 121 | LEDPattern retval = LEDPattern_Off; 122 | 123 | pthread_mutex_lock(&leds.lock); 124 | if (leds.initialized) 125 | retval = leds.currentPattern; 126 | pthread_mutex_unlock(&leds.lock); 127 | 128 | return retval; 129 | } 130 | 131 | bool SetLedPattern(LEDPattern newPattern) 132 | { 133 | bool success = false; 134 | 135 | if (newPattern < LEDPattern_Off || newPattern > LEDPattern_PulsingOrange) 136 | return false; 137 | 138 | pthread_mutex_lock(&leds.lock); 139 | if (leds.initialized) 140 | { 141 | if (leds.currentPattern != newPattern) 142 | { 143 | leds.currentPattern = newPattern; 144 | success = btnRefreshLeds(); 145 | } 146 | else 147 | { 148 | success = true; 149 | } 150 | } 151 | pthread_mutex_unlock(&leds.lock); 152 | 153 | return success; 154 | } 155 | 156 | bool LedWarning() 157 | { 158 | bool retval = false; 159 | 160 | pthread_mutex_lock(&leds.lock); 161 | if (leds.initialized) 162 | retval = leds.warningActive; 163 | pthread_mutex_unlock(&leds.lock); 164 | 165 | return retval; 166 | } 167 | 168 | bool SetLedWarning(bool doWarn) 169 | { 170 | bool success = false; 171 | 172 | pthread_mutex_lock(&leds.lock); 173 | if (leds.initialized) 174 | { 175 | if (leds.warningActive != doWarn) 176 | { 177 | leds.warningActive = doWarn; 178 | success = btnRefreshLeds(); 179 | } 180 | else 181 | { 182 | success = true; 183 | } 184 | } 185 | pthread_mutex_unlock(&leds.lock); 186 | 187 | return success; 188 | } 189 | 190 | bool btnRefreshLeds(void) 191 | { 192 | LEDPattern patternToUpload = leds.currentPattern; 193 | if (leds.warningActive) 194 | { 195 | switch (patternToUpload) 196 | { 197 | case LEDPattern_Off: 198 | patternToUpload = LEDPattern_Off; 199 | break; 200 | default: // fallthrough 201 | case LEDPattern_SteadyGreen: // fallthrough 202 | case LEDPattern_SteadyRed: // fallthrough 203 | case LEDPattern_SteadyOrange: 204 | patternToUpload = LEDPattern_SteadyOrange; 205 | break; 206 | case LEDPattern_FlashingGreen: // fallthrough 207 | case LEDPattern_FlashingRed: // fallthrough 208 | case LEDPattern_FlashingOrange: 209 | patternToUpload = LEDPattern_FlashingOrange; 210 | break; 211 | case LEDPattern_PulsingGreen: // fallthrough 212 | case LEDPattern_PulsingRed: // fallthrough 213 | case LEDPattern_PulsingOrange: 214 | patternToUpload = LEDPattern_PulsingOrange; 215 | break; 216 | } 217 | } 218 | return ButtonCoreSetLEDs(patternToUpload); 219 | } 220 | -------------------------------------------------------------------------------- /API/ev3_command.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 2 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see 22 | 23 | static void ms2ts(struct timespec *ts, unsigned long ms) 24 | { 25 | ts->tv_sec = ms / 1000; 26 | ts->tv_nsec = (ms % 1000) * 1000000; 27 | } 28 | 29 | void Wait(unsigned long ms) 30 | { 31 | struct timespec delay; 32 | ms2ts(&delay, ms); 33 | while (nanosleep(&delay, &delay)); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /API/ev3_timer.private.h: -------------------------------------------------------------------------------- 1 | /** \file ev3_timer.private.h 2 | * \brief Private declarations of the ev3_timer module 3 | * 4 | * This file contains implementation-internal declarations 5 | * that are not safe to use by user programs. For that purpose, 6 | * please see the ev3_timer.h header. 7 | * 8 | * License: 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | //////////////////////////////////////////////////////////////// 57 | // MACROS 58 | 59 | //! initial capacity of each callback queue 60 | #define INITIAL_CALLBACKS 4 61 | #define TERMINATOR UINT32_MAX 62 | 63 | //////////////////////////////////////////////////////////////// 64 | // GLOBAL DATA 65 | 66 | //! Unified array of multiple callbacks for one time interval. 67 | typedef struct 68 | { 69 | //! Array of functions. 70 | DynamicCArray functions; 71 | //! Kernel-provided timer object that we can call epoll() on. 72 | int timerFD; 73 | //! Whether the timer is currently enabled. 74 | bool running; 75 | } CallbackBlock; 76 | 77 | //! Structure for the timer module data. 78 | struct TimerControlBlock 79 | { 80 | //! Millisecond timer slots. 81 | unsigned long long msTimers[NUM_MS_TIMERS]; 82 | //! Microsecond timer slots. 83 | unsigned long long usTimers[NUM_US_TIMERS]; 84 | //! Centisecond timer slots. 85 | unsigned long long csTimers[NUM_CS_TIMERS]; 86 | 87 | //! Periodic callbacks 88 | CallbackBlock callbacksFor[ti_count]; 89 | 90 | //! Waiter/callback caller thread; statically initialized 91 | pthread_t waiterThread; 92 | //! Shared mutex, statically initialized 93 | pthread_mutex_t mutex; 94 | //! Waiter epoll fd 95 | int epollFD; 96 | //! Eventfd for terminating the looping thread 97 | int stopFD; 98 | 99 | //! Stores whether the module is currently initialized. 100 | bool initialized; 101 | }; 102 | 103 | //! Global data of the timer module. 104 | extern struct TimerControlBlock tcb; 105 | 106 | 107 | //////////////////////////////////////////////////////////////// 108 | // PRIVATE FUNCTIONS SHARED BETWEEN MODULES 109 | 110 | /*! 111 | * \brief Initialize timer slot arrays. 112 | */ 113 | void tmInitTimestampSlots(void); 114 | 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | #endif 120 | -------------------------------------------------------------------------------- /API/inputs/ev3_input.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "contrib/lms2012/ev3_analog.h" 3 | #include "ev3_input.h" 4 | #include "ev3_input_uart.h" 5 | #include "ev3_input_analog.h" 6 | #include "ev3_input_iic.h" 7 | 8 | 9 | DEVCON devCon; 10 | 11 | static bool ev3SensorsInitialized; 12 | 13 | bool InputInit() { 14 | if (ev3SensorsInitialized) { 15 | return false; 16 | } 17 | ANALOG * analogSensors = initEV3AnalogInput(); 18 | if (analogSensors == NULL) { 19 | return false; 20 | } 21 | bool uartInitialized = initEV3UARTInput(analogSensors); 22 | bool iicInitialized = initEV3IICInput(); 23 | if (!uartInitialized || !iicInitialized) { 24 | InputExit(); 25 | return false; 26 | } 27 | ev3SensorsInitialized = true; 28 | return true; 29 | } 30 | 31 | void InputExit(){ 32 | exitEV3AnalogInput(); 33 | exitEV3UARTInput(); 34 | exitEV3IICInput(); 35 | ev3SensorsInitialized = false; 36 | } 37 | -------------------------------------------------------------------------------- /API/inputs/ev3_input.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_INPUT_H 2 | #define EV3_API_EV3_INPUT_H 3 | 4 | #include 5 | 6 | bool InputInit(void); 7 | 8 | void InputExit(void); 9 | 10 | 11 | 12 | #endif //EV3_API_EV3_INPUT_H 13 | -------------------------------------------------------------------------------- /API/inputs/ev3_input_analog.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "ev3_input_analog.h" 10 | 11 | 12 | static int analogFile; 13 | static ANALOG * analogSensors; 14 | static bool ev3AnalogInputInitialized; 15 | 16 | ANALOG * initEV3AnalogInput(){ 17 | if (ev3AnalogInputInitialized) { 18 | return NULL; 19 | } 20 | analogFile = open("/dev/lms_analog", O_RDWR | O_SYNC); 21 | if (analogFile == -1) { 22 | return NULL; 23 | } 24 | analogSensors = (ANALOG*) mmap(0, sizeof(ANALOG), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, analogFile, 0); 25 | if (analogSensors == MAP_FAILED) { 26 | close(analogFile); 27 | return NULL; 28 | } 29 | ev3AnalogInputInitialized = true; 30 | return analogSensors; 31 | } 32 | 33 | DATA16 readNewDumbSensor(int sensorPort) { 34 | return analogSensors->InPin6[sensorPort]; 35 | } 36 | 37 | DATA16 readOldDumbSensor(int sensorPort) { 38 | return analogSensors->InPin1[sensorPort]; 39 | } 40 | 41 | void exitEV3AnalogInput(){ 42 | if (!ev3AnalogInputInitialized) { 43 | return; 44 | } 45 | munmap(analogSensors, sizeof(ANALOG)); 46 | analogSensors = NULL; 47 | close(analogFile); 48 | analogFile = 0; 49 | ev3AnalogInputInitialized = false; 50 | } 51 | -------------------------------------------------------------------------------- /API/inputs/ev3_input_analog.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_INPUT_ANALOG_H 2 | #define EV3_API_EV3_INPUT_ANALOG_H 3 | 4 | #include 5 | #include "contrib/lms2012/ev3_analog.h" 6 | #include "contrib/lms2012/ev3_basictypes.h" 7 | 8 | ANALOG * initEV3AnalogInput(void); 9 | 10 | DATA16 readNewDumbSensor(int port); 11 | 12 | DATA16 readOldDumbSensor(int port); 13 | 14 | void exitEV3AnalogInput(void); 15 | 16 | #endif //EV3_API_EV3_INPUT_ANALOG_H 17 | -------------------------------------------------------------------------------- /API/inputs/ev3_input_iic.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "contrib/lms2012/ev3_iic.h" 11 | #include "ev3_constants.h" 12 | #include "ev3_command.h" 13 | #include "ev3_input_iic.h" 14 | #include "ev3_input.h" 15 | 16 | #define IIC_SENSOR_TYPE 100 17 | #define IIC_SENSOR_BYTE_MODE 0 18 | 19 | static bool ev3IICInputInitialized; 20 | static int iicFile; 21 | static IIC* iicSensors; 22 | static int ev3IICDeviceAddresses[NUM_INPUTS]; 23 | 24 | extern DEVCON devCon; 25 | 26 | bool initEV3IICInput() { 27 | if (ev3IICInputInitialized) { 28 | return false; 29 | } 30 | iicFile = open("/dev/lms_iic", O_RDWR | O_SYNC); 31 | if (iicFile == -1) { 32 | return false; 33 | } 34 | iicSensors = (IIC*)mmap(0, sizeof(IIC), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, iicFile, 0); 35 | if (iicSensors == MAP_FAILED) { 36 | close(iicFile); 37 | return false; 38 | } 39 | ev3IICInputInitialized = true; 40 | return true; 41 | } 42 | 43 | 44 | bool initIICPort(int port, int deviceAddress) { 45 | ev3IICDeviceAddresses[port] = deviceAddress; 46 | devCon.Connection[port] = CONN_NXT_IIC; 47 | devCon.Type[port] = IIC_SENSOR_TYPE; 48 | devCon.Mode[port] = IIC_SENSOR_BYTE_MODE; 49 | ioctl(iicFile, IIC_SET_CONN, &devCon); 50 | return true; 51 | } 52 | 53 | int readFromIIC(int port, int registerAddress, DATA8 * buffer, int length) { 54 | DATA8 request[1] = { registerAddress }; 55 | writeToIIC(port, request, 1, 1, 0, length); 56 | Wait(1); 57 | return readFromIICSharedMemory(port, buffer, length); 58 | } 59 | 60 | 61 | int readFromIICSharedMemory(int sensorPort, DATA8 * buffer, int length) { 62 | if (!ev3IICInputInitialized) { 63 | return -1; 64 | } 65 | uint16_t slot = iicSensors->Actual[sensorPort]; 66 | DATA8 * data = iicSensors->Raw[sensorPort][slot]; 67 | int toRead = length > IIC_DATA_LENGTH ? IIC_DATA_LENGTH : length; 68 | memcpy(buffer, data, toRead); 69 | return toRead; 70 | } 71 | 72 | void writeToIIC(int port, DATA8 * toWrite, int toWriteLength, int repeatTimes, int repeatInterval, int responseLength) { 73 | static IICDAT IicDat; 74 | IicDat.Port = port; 75 | IicDat.Time = repeatInterval; 76 | IicDat.Repeat = repeatTimes; 77 | IicDat.RdLng = -responseLength; 78 | 79 | // the first byte of data is the length of data to send 80 | IicDat.WrLng = toWriteLength + 1; 81 | IicDat.WrData[0] = ev3IICDeviceAddresses[port]; 82 | 83 | int i; 84 | for (i = 0; i < toWriteLength; i++) { 85 | IicDat.WrData[i + 1] = toWrite[i]; 86 | } 87 | 88 | IicDat.Result = -1; 89 | while (IicDat.Result) { 90 | ioctl(iicFile, IIC_SETUP, &IicDat); 91 | } 92 | } 93 | 94 | void startPollingFromIIC(int sensorPort, int registerAddress, int pollDelay) { 95 | DATA8 request[] = {registerAddress}; 96 | Wait(pollDelay); 97 | writeToIIC(sensorPort, request, 1, 0, pollDelay, 1); 98 | } 99 | 100 | void exitEV3IICInput() { 101 | if (!ev3IICInputInitialized) { 102 | return; 103 | } 104 | munmap(iicSensors, sizeof(IIC)); 105 | iicSensors = NULL; 106 | close(iicFile); 107 | iicFile = 0; 108 | ev3IICInputInitialized = false; 109 | } 110 | -------------------------------------------------------------------------------- /API/inputs/ev3_input_iic.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_INPUT_IIC_H 2 | #define EV3_API_EV3_INPUT_IIC_H 3 | 4 | #include 5 | #include "contrib/lms2012/ev3_basictypes.h" 6 | 7 | bool initEV3IICInput(void); 8 | 9 | bool initIICPort(int port, int deviceAddress); 10 | 11 | /** 12 | * Reads data from IIC sensor. 13 | * @param port port to which the sensor is connected 14 | * @param registerAddress address of the first register to read. IF length > 1, 15 | * registers will be read one after the other 16 | * @param buffer buffer to which bytes will be written. The size of this buffer 17 | * must be at least 'length' long 18 | * @param length how many bytes to read 19 | * @return number of bytes read, -1 in case of error 20 | */ 21 | int readFromIIC(int port, int registerAddress, DATA8 * buffer, int length); 22 | 23 | /** 24 | * Read values, received from IIC device, from shared memory. 25 | * You need to call this function to get the read value from the sensor after calling writeToIIC or startPollingFromIIC. 26 | * @param sensorPort port to which the sensor is connected 27 | * @param buffer buffer to which bytes will be written. The size of this buffer 28 | * must be at least 'length' long 29 | * @param length how many bytes to read 30 | * @return bytes read count, -1 in case of error 31 | */ 32 | int readFromIICSharedMemory(int port, DATA8 * buffer, int length); 33 | 34 | /** 35 | * Writes to IIC device connected to sensor port 36 | * @param port port to which the sensor is connected 37 | * @param toWrite data to write to the sensor 38 | * @param toWriteLength how many bytes to send to the sensor 39 | * @param repeatTimes how many times send the message. If 0 the message is sent 40 | * every 'repeatInterval' milliseconds infinitely. 41 | * @param repeatInterval delay between consecutive writings 42 | * @param responseLength number of bytes that will be read from the IIC device 43 | * and copied to shared memory 44 | */ 45 | void writeToIIC(int port, DATA8 *toWrite, int toWriteLength, int repeatTimes, int repeatInterval, int responseLength); 46 | 47 | /** 48 | * Start to continuously send an IIC message to ask for data. The data from the sensor can be 49 | * read using readFromIICSharedMemory 50 | * @param sensorPort 51 | * @param registerAddress 52 | * @param pollDelay 53 | */ 54 | void startPollingFromIIC(int port, int registerAddress, int pollDelay); 55 | 56 | void exitEV3IICInput(void); 57 | 58 | #endif //EV3_API_EV3_INPUT_IIC_H 59 | -------------------------------------------------------------------------------- /API/inputs/ev3_input_uart.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "contrib/lms2012/ev3_uart.h" 12 | #include "ev3_command.h" 13 | #include "ev3_constants.h" 14 | #include "ev3_input_uart.h" 15 | 16 | static bool ev3UARTInputInitialized; 17 | static int uartFile; 18 | static UART * uartSensors; 19 | 20 | extern DEVCON devCon; 21 | 22 | bool initEV3UARTInput(ANALOG * analogSensors) { 23 | uartFile = open("/dev/lms_uart", O_RDWR | O_SYNC); 24 | if (uartFile == -1) { 25 | return false; 26 | } 27 | uartSensors = (UART*)mmap(0, sizeof(UART), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, uartFile, 0); 28 | if (uartSensors == MAP_FAILED) { 29 | close(uartFile); 30 | return false; 31 | } 32 | ev3UARTInputInitialized = true; 33 | 34 | int i; 35 | for (i = 0; i < NUM_INPUTS; i++) { 36 | devCon.Connection[i] = analogSensors->InConn[i]; 37 | devCon.Type[i] = TYPE_KEEP; 38 | devCon.Mode[i] = MODE_KEEP; 39 | } 40 | return true; 41 | } 42 | 43 | 44 | bool setUARTSensorMode(int port, DATA8 sensorType, DATA8 sensorMode) { 45 | /** 46 | * Procedure to set UART mode inspired by pxt: pxt-ev3/libs/core/input.ts 47 | */ 48 | 49 | // update the persisted global state of connections 50 | devCon.Connection[port] = CONN_INPUT_UART; 51 | devCon.Type[port] = sensorType; 52 | devCon.Mode[port] = sensorMode; 53 | 54 | bool portChanged = true; 55 | // note: The while loop is necessary for the case when this UART was 56 | // deinitialized. In that case, the kernel does not take 57 | // account of the mode to set the sensor in; it just powers 58 | // up the sensor and sets it to mode 0. Therefore, to also 59 | // set the correct mode, a second syscall round has to be made. 60 | while (portChanged) { 61 | // note: This write here is necessary even though the kernel does 62 | // the same operation to its shared memory. For some reason 63 | // the change does not take effect immediately but only 64 | // after some time. To prevent erroneous continuation, 65 | // the flag is removed here as well. 66 | // + a similar code can be found in the lms2012 VM. 67 | // + adding volatile to uartSensors didn't make a difference 68 | // (and lms2012 VM does not use it as well) 69 | // + using msync() also didn't seem to make a difference 70 | uartSensors->Status[port] &= ~UART_DATA_READY; 71 | // send the request to the kernel 72 | ioctl(uartFile, UART_SET_CONN, &devCon); 73 | 74 | // wait until the sensor is up (in whatever mode) 75 | waitUartReady(port, &portChanged); 76 | } 77 | 78 | return true; 79 | } 80 | 81 | void waitUartReady(int port, bool *portChanged) { 82 | UARTCTL cmd = { .Port = port }; 83 | 84 | *portChanged = false; 85 | while (true) { 86 | // read current port state 87 | int status = uartSensors->Status[port]; 88 | 89 | // kernel has gone through sensor initialization sequance 90 | if ((status & UART_PORT_CHANGED) != 0) { 91 | 92 | // signal that the device needs to be configured again 93 | *portChanged = true; 94 | 95 | // clear the flag in the kernel 96 | ioctl(uartFile, UART_CLEAR_CHANGED, &cmd); 97 | // and clear it in userspace as well 98 | // note: the write here is necessary for the same reason 99 | // as the write above for UART_DATA_READY 100 | uartSensors->Status[port] &= ~UART_PORT_CHANGED; 101 | 102 | } else if ((status & UART_DATA_READY) != 0) { 103 | // we're ready, the device has sent some data 104 | break; 105 | } 106 | 107 | // wait until the device is ready 108 | Wait(10); 109 | } 110 | } 111 | 112 | void disableUART(int port) { 113 | // update the persisted global state of connections 114 | devCon.Connection[port] = CONN_NONE; 115 | devCon.Type[port] = TYPE_NONE; 116 | devCon.Mode[port] = MODE_KEEP; 117 | 118 | // bye bye 119 | ioctl(uartFile, UART_SET_CONN, &devCon); 120 | } 121 | 122 | int readFromUART(int sensorPort, DATA8 * buffer, int length) { 123 | if (!ev3UARTInputInitialized) { 124 | return -1; 125 | } 126 | uint16_t slot = uartSensors->Actual[sensorPort]; 127 | DATA8 * data = uartSensors->Raw[sensorPort][slot]; 128 | int toRead = length > UART_DATA_LENGTH 129 | ? UART_DATA_LENGTH 130 | : length; 131 | memcpy(buffer, data, toRead); 132 | return toRead; 133 | } 134 | 135 | bool writeToUART(int port, DATA8 * buffer, int length) { 136 | if (!ev3UARTInputInitialized) { 137 | return -1; 138 | } 139 | int msgLen = length > UART_DATA_LENGTH 140 | ? UART_DATA_LENGTH 141 | : length; 142 | int cmdLen = msgLen + 1; 143 | 144 | // copy message and prepend it with port number 145 | DATA8 cmd[UART_DATA_LENGTH + 1] = {0}; 146 | cmd[0] = port; 147 | memcpy(cmd + 1, buffer, msgLen); 148 | 149 | // copied from lms2012 VM: probably to force confirmation of new data 150 | uartSensors->Status[port] &= ~UART_DATA_READY; 151 | // send the request to kernel 152 | int retval = write(uartFile, cmd, cmdLen); 153 | return retval == cmdLen; 154 | } 155 | 156 | void exitEV3UARTInput() { 157 | if (!ev3UARTInputInitialized) { 158 | return; 159 | } 160 | munmap(uartSensors, sizeof(UART)); 161 | uartSensors = NULL; 162 | close(uartFile); 163 | uartFile = -1; 164 | ev3UARTInputInitialized = false; 165 | } 166 | -------------------------------------------------------------------------------- /API/inputs/ev3_input_uart.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_INPUT_UART_H 2 | #define EV3_API_EV3_INPUT_UART_H 3 | 4 | #include 5 | #include "contrib/lms2012/ev3_analog.h" 6 | #include "contrib/lms2012/ev3_basictypes.h" 7 | 8 | bool initEV3UARTInput(ANALOG * analogSensors); 9 | 10 | /** 11 | * Sets the mode of a Lego UART sensor 12 | * @param port porto to which the sensor is connected 13 | * @param sensorType constant from firmware that identifies sensor type 14 | * @param sensorMode constant from firmware that identifies sensor mode 15 | * @return 16 | */ 17 | bool setUARTSensorMode(int port, DATA8 sensorType, DATA8 sensorMode); 18 | 19 | /** 20 | * Disable UART on this port. 21 | * @param port On which port to disable the UART. 22 | */ 23 | void disableUART(int port); 24 | 25 | /** 26 | * Read data form UART sensor 27 | * @param port port to which the sensor is connected 28 | * @param buffer buffer to which bytes will be written. The size of this buffer 29 | * must be at least 'length' long 30 | * @param length how many bytes to read 31 | * @return -1 in case of error 32 | */ 33 | int readFromUART(int port, DATA8 * buffer, int length); 34 | 35 | /** 36 | * Write a direct message to the UART device. 37 | * @param port Port to write the message to. 38 | * @param buffer Message to write. 39 | * @param length Message length (max UART_DATA_LENGTH). 40 | */ 41 | bool writeToUART(int port, DATA8 * buffer, int length); 42 | 43 | void exitEV3UARTInput(void); 44 | 45 | /** 46 | * Wait until the device connected to this port is up and ready. 47 | * @param port Port that the device is plugged to. 48 | * @param portChanged Whether the kernel has signalled a UART_PORT_CHANGED 49 | * flag, therefore necessitating port reconfiuration. 50 | */ 51 | void waitUartReady(int port, bool *portChanged); 52 | 53 | #endif //EV3_API_EV3_INPUT_UART_H 54 | -------------------------------------------------------------------------------- /API/libev3api.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@PREFIX@ 2 | includedir=@INCDIR@ 3 | libdir=@LIBDIR@ 4 | 5 | Name: EV3-API 6 | Description: EV3-API for Programming the LEGO Mindstorms EV3 in C 7 | URL: https://github.com/c4ev3/EV3-API 8 | Version: 1.0.0 9 | Cflags: -I${includedir} 10 | Libs: -L${libdir} -lev3api 11 | -------------------------------------------------------------------------------- /API/menu_icons.xbm: -------------------------------------------------------------------------------- 1 | #define menu_icons_width 16 2 | #define menu_icons_height 132 3 | static unsigned char menu_icons_bits[] = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x2A, 0x00, 0x1C, 0x00, 0x3E, 5 | 0x00, 0x1C, 0x00, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 6 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0E, 0x2A, 0x11, 0x1C, 0x11, 7 | 0xBE, 0x3F, 0x9C, 0x31, 0xAA, 0x3B, 0x88, 0x31, 0x80, 0x31, 0x00, 0x1F, 8 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x11, 0x00, 0x11, 9 | 0x80, 0x3F, 0x80, 0x31, 0x80, 0x3B, 0x80, 0x31, 0x80, 0x31, 0x00, 0x1F, 10 | 0xFC, 0x07, 0x02, 0x08, 0x02, 0x08, 0x02, 0x08, 0x02, 0x08, 0x02, 0x08, 11 | 0x06, 0x0C, 0xF8, 0x03, 0xFC, 0x07, 0x56, 0x0D, 0xAB, 0x1A, 0xFF, 0x1F, 12 | 0x00, 0x03, 0xF0, 0x03, 0x08, 0x04, 0x08, 0x04, 0x08, 0x04, 0x08, 0x04, 13 | 0xF8, 0x07, 0x58, 0x07, 0xB8, 0x06, 0x58, 0x07, 0xF8, 0x07, 0xF0, 0x03, 14 | 0xF8, 0x03, 0x08, 0x02, 0x08, 0x02, 0x0C, 0x06, 0x0C, 0x06, 0xFC, 0x07, 15 | 0x54, 0x04, 0xE4, 0x04, 0x44, 0x04, 0x04, 0x04, 0xF8, 0x03, 0xF8, 0x03, 16 | 0x00, 0x00, 0x08, 0x0E, 0x18, 0x1B, 0x29, 0x1B, 0x4A, 0x18, 0x2C, 0x0C, 17 | 0x18, 0x06, 0x2C, 0x06, 0x4A, 0x00, 0x29, 0x06, 0x18, 0x06, 0x08, 0x00, 18 | 0x00, 0x00, 0x00, 0xF0, 0x00, 0xE0, 0xC0, 0xF0, 0x20, 0xBB, 0x10, 0x1C, 19 | 0x90, 0xFF, 0x50, 0x40, 0x30, 0x20, 0x10, 0x10, 0xF0, 0x0F, 0x00, 0x00, 20 | 0x00, 0x00, 0xFF, 0x07, 0x01, 0x04, 0x01, 0x04, 0x01, 0x04, 0x01, 0x04, 21 | 0x01, 0x04, 0x01, 0x04, 0x01, 0x04, 0x01, 0x04, 0xFF, 0x07, 0x00, 0x00, 22 | 0x00, 0x00, 0xFF, 0x07, 0x01, 0x04, 0x01, 0x05, 0x81, 0x05, 0xC5, 0x04, 23 | 0x6D, 0x04, 0x39, 0x04, 0x11, 0x04, 0x01, 0x04, 0xFF, 0x07, 0x00, 0x00, 24 | 0x00, 0x00, 0xFF, 0x07, 0x01, 0x04, 0x8D, 0x05, 0xD9, 0x04, 0x71, 0x04, 25 | 0x71, 0x04, 0xD9, 0x04, 0x8D, 0x05, 0x01, 0x04, 0xFF, 0x07, 0x00, 0x00, 26 | }; 27 | -------------------------------------------------------------------------------- /API/normal_font.xbm: -------------------------------------------------------------------------------- 1 | #define normal_font_width 128 2 | #define normal_font_height 54 3 | static unsigned char normal_font_bits[] = { 4 | 0x00, 0x10, 0x48, 0x48, 0x10, 0x80, 0x1C, 0x20, 0x20, 0x08, 0x00, 0x00, 5 | 0x00, 0x00, 0x00, 0x40, 0x00, 0x10, 0x48, 0x48, 0xF8, 0x4E, 0x22, 0x20, 6 | 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x40, 0x00, 0x10, 0x24, 0xFC, 7 | 0x14, 0x2A, 0x22, 0x10, 0x08, 0x20, 0x54, 0x10, 0x00, 0x00, 0x00, 0x20, 8 | 0x00, 0x10, 0x00, 0x28, 0x1C, 0x2E, 0x22, 0x00, 0x08, 0x20, 0x38, 0x10, 9 | 0x00, 0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x28, 0x70, 0x10, 0x9C, 0x00, 10 | 0x08, 0x20, 0x54, 0xFE, 0x00, 0x7C, 0x00, 0x10, 0x00, 0x10, 0x00, 0x7E, 11 | 0x90, 0xE8, 0xA2, 0x00, 0x08, 0x20, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10, 12 | 0x00, 0x10, 0x00, 0x24, 0x90, 0xA8, 0x42, 0x00, 0x08, 0x20, 0x00, 0x10, 13 | 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x24, 0x7C, 0xE4, 0x42, 0x00, 14 | 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x10, 0x08, 0x00, 0x10, 0x00, 0x00, 15 | 0x10, 0x02, 0xBC, 0x00, 0x20, 0x08, 0x00, 0x00, 0x18, 0x00, 0x10, 0x08, 16 | 0x78, 0x10, 0x78, 0x78, 0x40, 0xF8, 0x70, 0xFC, 0x78, 0x78, 0x00, 0x00, 17 | 0x00, 0x00, 0x00, 0x38, 0x84, 0x1C, 0x84, 0x84, 0x60, 0x08, 0x08, 0x80, 18 | 0x84, 0x84, 0x00, 0x00, 0x80, 0x00, 0x04, 0x44, 0x84, 0x10, 0x84, 0x80, 19 | 0x50, 0x08, 0x04, 0x40, 0x84, 0x84, 0x10, 0x10, 0x60, 0xFE, 0x18, 0x40, 20 | 0x84, 0x10, 0x80, 0x80, 0x48, 0x08, 0x7C, 0x40, 0x84, 0x84, 0x10, 0x10, 21 | 0x18, 0x00, 0x60, 0x20, 0x84, 0x10, 0x40, 0x70, 0x44, 0x78, 0x84, 0x20, 22 | 0x78, 0x84, 0x00, 0x00, 0x04, 0x00, 0x80, 0x10, 0x84, 0x10, 0x30, 0x80, 23 | 0xFC, 0x80, 0x84, 0x20, 0x84, 0xF8, 0x00, 0x00, 0x18, 0xFE, 0x60, 0x10, 24 | 0x84, 0x10, 0x08, 0x80, 0x40, 0x80, 0x84, 0x10, 0x84, 0x80, 0x10, 0x10, 25 | 0x60, 0x00, 0x18, 0x10, 0x84, 0x10, 0x04, 0x84, 0x40, 0x84, 0x84, 0x10, 26 | 0x84, 0x40, 0x10, 0x10, 0x80, 0x00, 0x04, 0x00, 0x78, 0x7C, 0xFC, 0x78, 27 | 0x40, 0x78, 0x78, 0x08, 0x78, 0x38, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 28 | 0x38, 0x10, 0x3C, 0x78, 0x3E, 0xFC, 0xFC, 0x78, 0x82, 0x38, 0x38, 0x84, 29 | 0x04, 0xC6, 0x86, 0x38, 0x44, 0x10, 0x44, 0x84, 0x42, 0x04, 0x04, 0x84, 30 | 0x82, 0x10, 0x20, 0x44, 0x04, 0xC6, 0x86, 0x44, 0x82, 0x28, 0x44, 0x02, 31 | 0x82, 0x04, 0x04, 0x02, 0x82, 0x10, 0x20, 0x24, 0x04, 0xAA, 0x8A, 0x82, 32 | 0xBA, 0x28, 0x44, 0x02, 0x82, 0x04, 0x04, 0x02, 0x82, 0x10, 0x20, 0x14, 33 | 0x04, 0xAA, 0x8A, 0x82, 0xB2, 0x44, 0x7C, 0x02, 0x82, 0xFC, 0x7C, 0x02, 34 | 0xFE, 0x10, 0x20, 0x0C, 0x04, 0xAA, 0x92, 0x82, 0xAA, 0x44, 0x84, 0x02, 35 | 0x82, 0x04, 0x04, 0xE2, 0x82, 0x10, 0x20, 0x14, 0x04, 0x92, 0xA2, 0x82, 36 | 0x72, 0x7C, 0x84, 0x02, 0x82, 0x04, 0x04, 0x82, 0x82, 0x10, 0x20, 0x24, 37 | 0x04, 0x92, 0xA2, 0x82, 0x04, 0x82, 0x84, 0x84, 0x42, 0x04, 0x04, 0x84, 38 | 0x82, 0x10, 0x20, 0x44, 0x04, 0x92, 0xC2, 0x44, 0xF8, 0x82, 0x7C, 0x78, 39 | 0x3E, 0xFC, 0x04, 0xF8, 0x82, 0x38, 0x1C, 0x84, 0xFC, 0x82, 0xC2, 0x38, 40 | 0x7C, 0x38, 0x3E, 0x7C, 0xFE, 0x82, 0x82, 0x82, 0x82, 0x82, 0xFE, 0x38, 41 | 0x08, 0x38, 0x10, 0x00, 0x84, 0x44, 0x42, 0x82, 0x10, 0x82, 0x82, 0x92, 42 | 0x82, 0x44, 0x80, 0x08, 0x08, 0x20, 0x28, 0x00, 0x84, 0x82, 0x42, 0x02, 43 | 0x10, 0x82, 0x82, 0x92, 0x44, 0x44, 0x40, 0x08, 0x10, 0x20, 0x44, 0x00, 44 | 0x84, 0x82, 0x42, 0x02, 0x10, 0x82, 0x44, 0x92, 0x28, 0x28, 0x20, 0x08, 45 | 0x10, 0x20, 0x82, 0x00, 0x84, 0x82, 0x22, 0x7C, 0x10, 0x82, 0x44, 0xAA, 46 | 0x10, 0x28, 0x10, 0x08, 0x20, 0x20, 0x00, 0x00, 0x7C, 0x92, 0x1E, 0x80, 47 | 0x10, 0x82, 0x28, 0xAA, 0x28, 0x10, 0x08, 0x08, 0x20, 0x20, 0x00, 0x00, 48 | 0x04, 0x64, 0x22, 0x80, 0x10, 0x82, 0x28, 0xAA, 0x44, 0x10, 0x04, 0x08, 49 | 0x20, 0x20, 0x00, 0x00, 0x04, 0x78, 0x42, 0x82, 0x10, 0x44, 0x10, 0x44, 50 | 0x82, 0x10, 0x02, 0x08, 0x40, 0x20, 0x00, 0x00, 0x04, 0xC0, 0x82, 0x7C, 51 | 0x10, 0x38, 0x10, 0x44, 0x82, 0x10, 0xFE, 0x38, 0x40, 0x38, 0x00, 0xFE, 52 | 0x10, 0x00, 0x04, 0x00, 0x80, 0x00, 0x70, 0x00, 0x04, 0x00, 0x00, 0x04, 53 | 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x00, 0x80, 0x00, 0x08, 0x00, 54 | 0x04, 0x10, 0x20, 0x04, 0x10, 0x00, 0x00, 0x00, 0x20, 0x78, 0x04, 0x78, 55 | 0x80, 0x78, 0x08, 0xF8, 0x04, 0x00, 0x00, 0x44, 0x10, 0x4A, 0x74, 0x78, 56 | 0x00, 0x80, 0x74, 0x84, 0xF8, 0x84, 0x3C, 0x84, 0x74, 0x10, 0x30, 0x24, 57 | 0x10, 0xB6, 0x8C, 0x84, 0x00, 0x80, 0x8C, 0x04, 0x84, 0x84, 0x08, 0x84, 58 | 0x8C, 0x10, 0x20, 0x14, 0x10, 0x92, 0x84, 0x84, 0x00, 0xF8, 0x84, 0x04, 59 | 0x84, 0xFC, 0x08, 0xC4, 0x84, 0x10, 0x20, 0x0C, 0x10, 0x92, 0x84, 0x84, 60 | 0x00, 0x84, 0x84, 0x04, 0x84, 0x04, 0x08, 0xB8, 0x84, 0x10, 0x20, 0x14, 61 | 0x10, 0x92, 0x84, 0x84, 0x00, 0x84, 0x84, 0x84, 0xC4, 0x84, 0x08, 0x80, 62 | 0x84, 0x10, 0x20, 0x24, 0x10, 0x92, 0x84, 0x84, 0x00, 0xF8, 0x7C, 0x78, 63 | 0xB8, 0x78, 0x08, 0x78, 0x84, 0x10, 0x1C, 0x44, 0x10, 0x92, 0x84, 0x78, 64 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 65 | 0x10, 0x08, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 66 | 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x32, 0x00, 0x74, 0xF8, 0x68, 0x78, 67 | 0x3C, 0x84, 0x84, 0x92, 0x44, 0x84, 0x7C, 0x10, 0x10, 0x10, 0x00, 0x00, 68 | 0x8C, 0x84, 0x18, 0x04, 0x08, 0x84, 0x84, 0x92, 0x44, 0x48, 0x40, 0x10, 69 | 0x10, 0x10, 0x00, 0x00, 0x84, 0xC4, 0x08, 0x04, 0x08, 0x84, 0x48, 0xAA, 70 | 0x28, 0x48, 0x20, 0x08, 0x10, 0x20, 0x00, 0x00, 0x7C, 0xB8, 0x08, 0x38, 71 | 0x08, 0x84, 0x48, 0xAA, 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 72 | 0x04, 0x80, 0x08, 0x40, 0x08, 0x84, 0x48, 0xAA, 0x28, 0x30, 0x08, 0x10, 73 | 0x10, 0x10, 0x00, 0x00, 0x04, 0x80, 0x08, 0x40, 0x08, 0xC4, 0x30, 0x44, 74 | 0x44, 0x10, 0x04, 0x10, 0x10, 0x10, 0x00, 0x92, 0x04, 0x80, 0x08, 0x3C, 75 | 0x30, 0xB8, 0x30, 0x44, 0x44, 0x08, 0x7C, 0x20, 0x10, 0x08, 0x00, 0x92, 76 | }; 77 | -------------------------------------------------------------------------------- /API/sensors/c4ev3_compatibility.c: -------------------------------------------------------------------------------- 1 | #include "ev3_sensors.h" 2 | #include "ev3_sensors/c4ev3_compatibility.h" 3 | 4 | // 5 | // PRIVATE DECLARATIONS 6 | // 7 | 8 | static bool initializeAllSensors(void); 9 | 10 | static void initializeBackCompatibilityIfNeeded(void); 11 | 12 | static int readEV3IrSensorSeekForBackCompatibility(int port); 13 | 14 | // 15 | // GLOBAL DATA 16 | // 17 | 18 | static int sensorModeNames[NUM_INPUTS] = {NO_SEN}; 19 | static int ev3IrSensorChannel[NUM_INPUTS]; 20 | static SensorHandler * sensorModeHandlersByModeName[100]; 21 | 22 | // 23 | // IMPLEMENTATION 24 | // 25 | 26 | 27 | int SetAllSensorMode(int name_1, int name_2, int name_3, int name_4) { 28 | sensorModeNames[IN_1] = name_1; 29 | sensorModeNames[IN_2] = name_2; 30 | sensorModeNames[IN_3] = name_3; 31 | sensorModeNames[IN_4] = name_4; 32 | if (!initializeAllSensors()) { 33 | return -1; 34 | } 35 | return 0; 36 | } 37 | 38 | static bool initializeAllSensors(void) { 39 | initializeBackCompatibilityIfNeeded(); 40 | SensorHandler * handlers[4]; 41 | for (int i = 0; i < NUM_INPUTS; i++) { 42 | int modeName = sensorModeNames[i]; 43 | if (modeName == NO_SEN) { 44 | handlers[i] = NULL; 45 | } else { 46 | handlers[i] = sensorModeHandlersByModeName[modeName]; 47 | } 48 | } 49 | return SetAllSensors(handlers[0],handlers[1],handlers[2],handlers[3]); 50 | } 51 | 52 | 53 | static bool backCompatibilityInitialized = false; 54 | 55 | static void initializeBackCompatibilityIfNeeded(void) { 56 | if (backCompatibilityInitialized) { 57 | return; 58 | } 59 | 60 | sensorModeHandlersByModeName[TOUCH_PRESS] = EV3Touch; 61 | sensorModeHandlersByModeName[COL_REFLECT] = EV3Color; 62 | sensorModeHandlersByModeName[COL_AMBIENT] = EV3Color; 63 | sensorModeHandlersByModeName[COL_COLOR] = EV3Color; 64 | sensorModeHandlersByModeName[COL_COLOR_RGB] = EV3Color; 65 | sensorModeHandlersByModeName[US_DIST_CM] = EV3Ultrasonic; 66 | sensorModeHandlersByModeName[US_DIST_MM] = EV3Ultrasonic; 67 | sensorModeHandlersByModeName[US_DIST_IN] = EV3Ultrasonic; 68 | sensorModeHandlersByModeName[GYRO_ANG] = EV3Gyro; 69 | sensorModeHandlersByModeName[GYRO_RATE] = EV3Gyro; 70 | sensorModeHandlersByModeName[IR_PROX] = EV3Ir; 71 | sensorModeHandlersByModeName[IR_SEEK] = EV3Ir; 72 | sensorModeHandlersByModeName[IR_REMOTE] = EV3Ir; 73 | sensorModeHandlersByModeName[NXT_TEMP_C] = NXTTemperature; 74 | sensorModeHandlersByModeName[NXT_TEMP_F] = NXTTemperature; 75 | sensorModeHandlersByModeName[HT_DIR_DC] = HTIrV2; 76 | sensorModeHandlersByModeName[HT_DIR_AC] = HTIrV2; 77 | sensorModeHandlersByModeName[HT_DIR_DALL] = HTIrV2; 78 | sensorModeHandlersByModeName[HT_DIR_AALL] = HTIrV2; 79 | sensorModeHandlersByModeName[HT_COMP] = HTCompass; 80 | 81 | backCompatibilityInitialized = true; 82 | } 83 | 84 | int ReadSensor(int port) { 85 | int modeName = sensorModeNames[port]; 86 | switch (modeName) { 87 | case TOUCH_PRESS: 88 | return ReadEV3TouchSensor(port); 89 | case COL_REFLECT: 90 | return ReadEV3ColorSensorReflectedLight(port); 91 | case COL_AMBIENT: 92 | return ReadEV3ColorSensorAmbientLight(port); 93 | case COL_COLOR: 94 | return ReadEV3ColorSensorColor(port); 95 | case COL_COLOR_RGB: { 96 | #define RGB_TO_8BIT(x) (((x) >> 2) & 0xFF) 97 | 98 | RGB colors = {0}; 99 | int retval = ReadEV3ColorSensorColorRGB(port, &colors); 100 | 101 | if (retval < 0) 102 | return INT_MIN; 103 | 104 | return (RGB_TO_8BIT(colors.red) << 16) 105 | | (RGB_TO_8BIT(colors.green) << 8) 106 | | (RGB_TO_8BIT(colors.blue) << 0); 107 | } 108 | case US_DIST_CM: 109 | return ReadEV3UltrasonicSensorDistance(port, EV3_ULTRASONIC_CM); 110 | case US_DIST_MM: 111 | return ReadEV3UltrasonicSensorDistance(port, EV3_ULTRASONIC_MM); 112 | case US_DIST_IN: 113 | return ReadEV3UltrasonicSensorDistance(port, EV3_ULTRASONIC_IN); 114 | case GYRO_ANG: 115 | return ReadEV3GyroSensorAngle(port, EV3GyroInterleavedAngle); 116 | case GYRO_RATE: 117 | return ReadEV3GyroSensorRate(port, EV3GyroInterleavedRate); 118 | case IR_PROX: 119 | return ReadEV3IrSensorProximity(port); 120 | case IR_SEEK: 121 | return readEV3IrSensorSeekForBackCompatibility(port); 122 | case IR_REMOTE: 123 | return ReadEV3IrSensorRemote(port, ev3IrSensorChannel[port]); 124 | case NXT_TEMP_C: 125 | return ReadNXTTemperatureSensor(port, NXT_TEMPERATURE_C); 126 | case NXT_TEMP_F: 127 | return ReadNXTTemperatureSensor(port, NXT_TEMPERATURE_F); 128 | case HT_DIR_DC: 129 | return ReadHTIrV2Sensor(port, Modulated); 130 | case HT_DIR_AC: 131 | return ReadHTIrV2Sensor(port, Unmodulated); 132 | case HT_DIR_DALL: 133 | case HT_DIR_AALL: 134 | // to implement HT_DIR_DALL and HT_DIR_AALL, we need to call ReadHTIrV2SensorAll 135 | // and to encode the vector of 5 integers to a single integer. 136 | // TODO: How do we need to encode the value to preserve back-compatibility? 137 | return -1; 138 | case HT_COMP: 139 | return ReadHTCompassSensor(port, HTCompassCompass); 140 | default: 141 | return -1; 142 | } 143 | } 144 | 145 | int readEV3IrSensorSeekForBackCompatibility (int port) { 146 | EV3IrSeekResult result; 147 | ReadEV3IrSensorSeek(port, &result); 148 | int channel = ev3IrSensorChannel[port]; 149 | return result.distances[channel]; 150 | } 151 | 152 | int SetIRBeaconCH(int sensorPort, int channel) { 153 | ev3IrSensorChannel[sensorPort] = channel; 154 | return 0; 155 | } 156 | -------------------------------------------------------------------------------- /API/sensors/ev3_color.c: -------------------------------------------------------------------------------- 1 | #include "inputs/ev3_input_uart.h" 2 | #include "ev3_command.h" 3 | #include "ev3_sensors/ev3_sensors.h" 4 | #include "utility.h" 5 | 6 | // 7 | // PRIVATE DECLARATIONS 8 | // 9 | 10 | static bool initEV3ColorSensor(int port); 11 | 12 | static int readByte(int port, int mode); 13 | 14 | static void setEV3ColorSensorMode(int port, int mode); 15 | 16 | // 17 | // GLOBAL DATA 18 | // 19 | 20 | SensorHandler * EV3Color = &(SensorHandler){ 21 | .Init = initEV3ColorSensor, 22 | .Exit = NULL, 23 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 24 | }; 25 | 26 | // 27 | // IMPLEMENTATION 28 | // 29 | 30 | bool initEV3ColorSensor(int port) { 31 | setEV3ColorSensorMode(port, EV3_COLOR_SENSOR_DEFAULT_MODE); 32 | return true; 33 | } 34 | 35 | int ReadEV3ColorSensorReflectedLight(int port) { 36 | return readByte(port, EV3_COLOR_SENSOR_REFLECT_MODE); 37 | } 38 | 39 | int ReadEV3ColorSensorAmbientLight(int port) { 40 | return readByte(port, EV3_COLOR_SENSOR_AMBIENT_MODE); 41 | } 42 | 43 | Color ReadEV3ColorSensorColor(int port) { 44 | return readByte(port, EV3_COLOR_SENSOR_COLOR_MODE); 45 | } 46 | 47 | int ReadEV3ColorSensorColorRGB(int port, RGB* rgb) { 48 | setEV3ColorSensorMode(port, EV3_COLOR_SENSOR_RAW_COLOR_MODE); 49 | 50 | uint8_t data[8] = {0}; 51 | int retval = readFromUART(port, (DATA8*) data, sizeof(data)); 52 | if (retval < 0) { 53 | return INT_MIN; 54 | } 55 | 56 | rgb->red = data[0] + (data[1] << 8u); 57 | rgb->green = data[2] + (data[3] << 8u); 58 | rgb->blue = data[4] + (data[5] << 8u); 59 | rgb->background = data[6] + (data[7] << 8u); 60 | return 0; 61 | } 62 | 63 | int ReadEV3ColorSensorRawReflectedLight(int port, RawReflect *refraw) { 64 | setEV3ColorSensorMode(port, EV3_COLOR_SENSOR_RAW_REFLECT_MODE); 65 | 66 | uint8_t data[4] = {0}; 67 | int retval = readFromUART(port, (DATA8*) data, sizeof(data)); 68 | if (retval < 0) { 69 | return INT_MIN; 70 | } 71 | 72 | int led_on = data[0] + (data[1] << 8u); 73 | int led_off = data[2] + (data[3] << 8u); 74 | 75 | refraw->reflection = led_off - led_on; // make this similar to COL-REFLECT and RGB-RAW 76 | refraw->background = led_off; // pass this unchanged 77 | return 0; 78 | } 79 | 80 | int readByte(int port, int mode) { 81 | setEV3ColorSensorMode(port, mode); 82 | 83 | DATA8 data = 0; 84 | int retval = readFromUART(port, &data, sizeof(data)); 85 | if (retval < 0) { 86 | return INT_MIN; 87 | } 88 | return data; 89 | } 90 | 91 | void setEV3ColorSensorMode(int port, int mode) { 92 | setUARTSensorHandlerMode(EV3Color, port, EV3_COLOR_SENSOR_TYPE, mode); 93 | } 94 | -------------------------------------------------------------------------------- /API/sensors/ev3_color.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_COLOR_PRIVATE_H 2 | #define EV3_API_EV3_COLOR_PRIVATE_H 3 | 4 | #include "ev3_sensors.h" 5 | 6 | 7 | bool initEV3ColorSensor(int port); 8 | 9 | void exitEV3ColorSensor(int port); 10 | 11 | int getEV3ColorSensorModeFromReadingLightMode(EV3ColorLightReadingMode); 12 | 13 | int readEV3ColorSensorRawValue(int port, int mode); 14 | 15 | void setEV3ColorSensorMode(int port, int mode); 16 | 17 | #endif //EV3_API_EV3_COLOR_H 18 | -------------------------------------------------------------------------------- /API/sensors/ev3_gyro.c: -------------------------------------------------------------------------------- 1 | #include "inputs/ev3_input_uart.h" 2 | #include "ev3_sensors.h" 3 | #include "contrib/lms2012/ev3_basictypes.h" 4 | #include "ev3_command.h" 5 | #include "ev3_sensors/ev3_gyro.h" 6 | #include "utility.h" 7 | #include "limits.h" 8 | 9 | // 10 | // PRIVATE DECLARATIONS 11 | // 12 | 13 | static bool initEV3GyroSensor(int port); 14 | 15 | static int universalRead(int port, int mode, int data_length, int index, int offset); 16 | 17 | static int parseS16(uint8_t *data, int valueNo); 18 | 19 | static int setEV3GyroSoftwareReset(int port); 20 | 21 | static void setEV3GyroSensorMode(int port, int mode); 22 | 23 | // 24 | // GLOBAL DATA 25 | // 26 | 27 | static int ev3GyroSoftwareResetOffset[4][EV3_GYRO_SENSOR_MODES]; 28 | 29 | SensorHandler * EV3Gyro = &(SensorHandler){ 30 | .Init = initEV3GyroSensor, 31 | .Exit = NULL, 32 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 33 | }; 34 | 35 | // 36 | // IMPLEMENTATION 37 | // 38 | 39 | bool initEV3GyroSensor (int port) { 40 | memset(&ev3GyroSoftwareResetOffset[port], 0, EV3_GYRO_SENSOR_MODES * sizeof(int)); 41 | setEV3GyroSensorMode(port, EV3_GYRO_SENSOR_DEFAULT_MODE); 42 | return true; 43 | } 44 | 45 | int ReadEV3GyroSensorAngle(int port, EV3GyroAngleMode mode) { 46 | int data_len; 47 | int target_mode; 48 | int value_index; 49 | 50 | switch (mode) { 51 | case EV3GyroNormalAngle: 52 | data_len = 2; 53 | target_mode = EV3_GYRO_SENSOR_ANGLE_MODE; 54 | value_index = 0; 55 | break; 56 | 57 | case EV3GyroInterleavedAngle: 58 | data_len = 4; 59 | target_mode = EV3_GYRO_SENSOR_ANGLE_AND_RATE_MODE; 60 | value_index = 0; 61 | break; 62 | 63 | case EV3GyroTiltAngle: 64 | data_len = 2; 65 | target_mode = EV3_GYRO_SENSOR_TILT_ANGLE_MODE; 66 | value_index = 0; 67 | break; 68 | 69 | default: 70 | return INT_MIN; 71 | } 72 | 73 | int angle_offset = ev3GyroSoftwareResetOffset[port][target_mode]; 74 | 75 | return universalRead(port, target_mode, data_len, value_index, angle_offset); 76 | } 77 | 78 | int ReadEV3GyroSensorRate(int port, EV3GyroRateMode mode) { 79 | int data_len; 80 | int target_mode; 81 | int value_index; 82 | 83 | switch (mode) { 84 | case EV3GyroNormalRate: 85 | data_len = 2; 86 | target_mode = EV3_GYRO_SENSOR_RATE_MODE; 87 | value_index = 0; 88 | break; 89 | 90 | case EV3GyroFastRate: 91 | data_len = 2; 92 | target_mode = EV3_GYRO_SENSOR_RATE_FAST_MODE; 93 | value_index = 0; 94 | break; 95 | 96 | case EV3GyroInterleavedRate: 97 | data_len = 4; 98 | target_mode = EV3_GYRO_SENSOR_ANGLE_AND_RATE_MODE; 99 | value_index = 1; 100 | break; 101 | 102 | case EV3GyroTiltRate: 103 | data_len = 2; 104 | target_mode = EV3_GYRO_SENSOR_TILT_RATE_MODE; 105 | value_index = 0; 106 | break; 107 | 108 | default: 109 | return INT_MIN; 110 | } 111 | 112 | return universalRead(port, target_mode, data_len, value_index, 0); 113 | } 114 | 115 | int universalRead(int port, int mode, int data_length, int index, int offset) { 116 | uint8_t data[4] = {0}; 117 | 118 | setEV3GyroSensorMode(port, mode); 119 | 120 | int retval = readFromUART(port, (DATA8*) data, data_length); 121 | if (retval != data_length) 122 | return INT_MIN; 123 | 124 | return parseS16(data, index) - offset; 125 | } 126 | 127 | int parseS16(uint8_t *data, int valueNo) { 128 | uint16_t raw = (data[2*valueNo + 0] << 0u) 129 | | (data[2*valueNo + 1] << 8u); 130 | 131 | /** 132 | * Bit trick overview (sign-extension): 133 | * - The if checks for the sign-bit. 134 | * - The and-mask removes the sign bit - that gives us how much bigger is 135 | * the actual value compared to the most negative value. 136 | * - The subtraction just moves the result so that it matches the 137 | * previous value. 138 | */ 139 | if (raw & 0x8000) { 140 | return (int) (raw & 0x7FFF) - 0x8000; 141 | } 142 | return (int) raw; 143 | } 144 | 145 | int ResetEV3GyroSensor(int port, EV3GyroResetStrategy mode) { 146 | 147 | uint8_t resetCmd = 0; 148 | int oldMode = EV3Gyro->currentSensorMode[port]; 149 | 150 | switch (mode) { 151 | case EV3GyroHardwareCommand0x11: // fallthrough 152 | case EV3GyroHardwareCommand0x88: 153 | 154 | if (oldMode != EV3_GYRO_SENSOR_ANGLE_MODE) 155 | setEV3GyroSensorMode(port, EV3_GYRO_SENSOR_ANGLE_MODE); 156 | 157 | resetCmd = mode == EV3GyroHardwareCommand0x11 158 | ? EV3_GYRO_ZERO_ANGLE_COMMAND 159 | : EV3_GYRO_CALIBRATE_COMMAND; 160 | if (! writeToUART(port, (DATA8*) &resetCmd, sizeof(resetCmd))) 161 | return INT_MIN; 162 | 163 | if (oldMode != EV3_GYRO_SENSOR_ANGLE_MODE) 164 | setEV3GyroSensorMode(port, oldMode); 165 | 166 | return 0; 167 | 168 | case EV3GyroHardwareReboot: 169 | disableUART(port); 170 | setEV3GyroSensorMode(port, EV3Gyro->currentSensorMode[port]); 171 | return 0; 172 | 173 | case EV3GyroSoftwareOffset: 174 | return setEV3GyroSoftwareReset(port); 175 | 176 | default: 177 | return INT_MIN; 178 | } 179 | } 180 | 181 | int setEV3GyroSoftwareReset(int port) { 182 | int currentMode = EV3Gyro->currentSensorMode[port]; 183 | 184 | ev3GyroSoftwareResetOffset[port][currentMode] = 0; 185 | 186 | int currentAngle = 0; 187 | switch (currentMode) { 188 | case EV3_GYRO_SENSOR_RATE_MODE: // fallthrough 189 | case EV3_GYRO_SENSOR_RATE_FAST_MODE: // fallthrough 190 | case EV3_GYRO_SENSOR_TILT_RATE_MODE: // fallthrough 191 | default: 192 | return -1; 193 | 194 | case EV3_GYRO_SENSOR_ANGLE_MODE: 195 | currentAngle = ReadEV3GyroSensorAngle(port, EV3GyroNormalAngle); 196 | break; 197 | 198 | case EV3_GYRO_SENSOR_ANGLE_AND_RATE_MODE: 199 | currentAngle = ReadEV3GyroSensorAngle(port, EV3GyroInterleavedAngle); 200 | break; 201 | 202 | case EV3_GYRO_SENSOR_TILT_ANGLE_MODE: 203 | currentAngle = ReadEV3GyroSensorAngle(port, EV3GyroTiltAngle); 204 | break; 205 | } 206 | 207 | ev3GyroSoftwareResetOffset[port][currentMode] = currentAngle; 208 | return 0; 209 | } 210 | 211 | void setEV3GyroSensorMode(int port, int mode) { 212 | setUARTSensorHandlerMode(EV3Gyro, port, EV3_GYRO_SENSOR_TYPE, mode); 213 | } 214 | -------------------------------------------------------------------------------- /API/sensors/ev3_gyro.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_GYRO_PRIVATE_H 2 | #define EV3_API_EV3_GYRO_PRIVATE_H 3 | 4 | #include "ev3_gyro.h" 5 | 6 | 7 | bool initEV3GyroSensor(int port); 8 | 9 | void exitEV3GyroSensor(int port); 10 | 11 | int getAngleFromAngleAndRate(uint64_t angleAndRate); 12 | 13 | int getRateFromAngleAndRate(uint64_t angleAndRate); 14 | 15 | int handleEV3GyroNegativeValue(int value); 16 | 17 | void setEV3GyroSoftwareReset(int port); 18 | 19 | void setEV3GyroSensorMode(int port, int mode); 20 | 21 | 22 | #endif //EV3_API_EV3_GYRO_H 23 | -------------------------------------------------------------------------------- /API/sensors/ev3_ir.c: -------------------------------------------------------------------------------- 1 | #include "inputs/ev3_input_uart.h" 2 | #include "ev3_command.h" 3 | #include "ev3_sensors/ev3_ir.h" 4 | #include "utility.h" 5 | 6 | // 7 | // PRIVATE DECLARATIONS 8 | // 9 | 10 | static bool initEV3IrSensor (int port); 11 | 12 | static void setEV3IrSensorMode(int port, int mode); 13 | 14 | // 15 | // GLOBAL DATA 16 | // 17 | 18 | SensorHandler * EV3Ir = &(SensorHandler){ 19 | .Init = initEV3IrSensor, 20 | .Exit = NULL, 21 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 22 | }; 23 | 24 | // 25 | // IMPLEMENTATION 26 | // 27 | 28 | bool initEV3IrSensor (int port) { 29 | setEV3IrSensorMode(port, EV3_IR_SENSOR_DEFAULT_MODE); 30 | return true; 31 | } 32 | 33 | 34 | int ReadEV3IrSensorSeek (int port, EV3IrSeekResult* result) { 35 | setEV3IrSensorMode(port, EV3_IR_SENSOR_SEEK_MODE); 36 | 37 | /** 38 | * The first byte of data contains the bearing, the second the distance. 39 | * This pattern repeats 4 times, two bytes for every channel. 40 | * When no beacon is found for a channel the distance is set to -128. 41 | */ 42 | DATA8 data[8]; 43 | readFromUART(port, data, sizeof(data) / sizeof(DATA8)); 44 | 45 | int i; 46 | for (i = 0; i < EV3_IR_CHANNELS; i++) { 47 | int direction = data[i * 2]; 48 | int distance = data[(i * 2) + 1]; 49 | if (distance == -128) { 50 | result->directions[i] = 0; 51 | result->distances[i] = 128; 52 | } else { 53 | result->directions[i] = direction; 54 | result->distances[i] = distance; 55 | } 56 | } 57 | return 0; 58 | } 59 | 60 | int ReadEV3IrSensorProximity (int port) { 61 | setEV3IrSensorMode(port, EV3_IR_SENSOR_PROXIMITY_MODE); 62 | 63 | DATA8 data; 64 | readFromUART(port, &data, 1); 65 | return data; 66 | } 67 | 68 | void setEV3IrSensorMode(int port, int mode) { 69 | setUARTSensorHandlerMode(EV3Ir, port, EV3_IR_SENSOR_TYPE, mode); 70 | } 71 | 72 | EV3IrRemoteButton ReadEV3IrSensorRemote (int port, int channel) { 73 | setEV3IrSensorMode(port, EV3_IR_SENSOR_REMOTE_MODE); 74 | DATA8 data[EV3_IR_CHANNELS]; 75 | readFromUART(port, data, EV3_IR_CHANNELS); 76 | return data[channel]; 77 | } 78 | -------------------------------------------------------------------------------- /API/sensors/ev3_ir.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_IR_PRIVATE_H 2 | #define EV3_API_EV3_IR_PRIVATE_H 3 | 4 | #include "ev3_ir.h" 5 | 6 | bool initEV3IrSensor (int port); 7 | 8 | void setEV3IrSensorMode(int port, int mode); 9 | 10 | 11 | #endif //EV3_API_EV3_IR_H 12 | -------------------------------------------------------------------------------- /API/sensors/ev3_sensors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ev3_constants.h" 3 | #include "ev3_sensors.h" 4 | 5 | 6 | static SensorHandler *currentSensorHandlers[NUM_INPUTS]; 7 | 8 | bool SensorsInit() { 9 | return true; 10 | } 11 | 12 | bool SetAllSensors(SensorHandler *port1, SensorHandler *port2, SensorHandler *port3, SensorHandler *port4) { 13 | SensorHandler * sensorHandlers[] = {port1, port2, port3, port4}; 14 | int i; 15 | for (i = 0; i < NUM_INPUTS; i++) { 16 | if (sensorHandlers[i] != NULL) { 17 | bool res = SetSensor(i, sensorHandlers[i]); 18 | if (!res) { 19 | exitSensorsUntilPort(sensorHandlers, i); 20 | return false; 21 | } 22 | } 23 | } 24 | return true; 25 | } 26 | 27 | bool SetSensor(int port, SensorHandler *sensor) { 28 | currentSensorHandlers[port] = sensor; 29 | return currentSensorHandlers[port]->Init(port); 30 | } 31 | 32 | void exitSensorsUntilPort(SensorHandler * sensorHandlers[], int lastPortExcluded) { 33 | for (int i = 0; i < lastPortExcluded; i++) { 34 | if (sensorHandlers[i] != NULL) { 35 | sensorHandlers[i]->Exit(i); 36 | } 37 | } 38 | } 39 | 40 | SensorHandler * GetSensor(int port) { 41 | return currentSensorHandlers[port]; 42 | } 43 | 44 | void SensorsExit () { 45 | int i; 46 | for (i = 0; i < NUM_INPUTS; i++) { 47 | SensorHandler * sensor = currentSensorHandlers[i]; 48 | if (sensor != NULL && sensor->Exit != NULL) { 49 | sensor->Exit(i); 50 | currentSensorHandlers[i] = NULL; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /API/sensors/ev3_sensors.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_SENSORS_PRIVATE_H 2 | #define EV3_API_EV3_SENSORS_PRIVATE_H 3 | 4 | #include 5 | #include 6 | #include "ev3_constants.h" 7 | #include 8 | #include "ev3_sensors/c4ev3_compatibility.h" 9 | 10 | struct SensorHandler { 11 | 12 | /** 13 | * Initializes the sensor handler for the specified port. 14 | * If the initialization fails, the function should return false and clean 15 | * up resources (in order to allow a future call to Init) 16 | * @param port port to which the sensor is connected 17 | * @return true if the initialization was successful 18 | */ 19 | bool (*Init)(int port); 20 | 21 | void (*Exit)(int port); 22 | 23 | /** 24 | * Contains a value for each sensor that represents the mode in which the sensor it's working. 25 | * 26 | * For example take the EV3 ultrasonic sensor: 27 | * the currentSensorMode could have three different values: 28 | * - listen mode 29 | * - distance mode mm 30 | * - distance mode in 31 | * 32 | * Reading the distance in cm is a different reading mode, because the conversion is done from code, it's not a value 33 | * that we receive from the sensor. 34 | */ 35 | int currentSensorMode[NUM_INPUTS]; 36 | }; 37 | 38 | bool SensorsInit (void); 39 | 40 | void SensorsExit (void); 41 | 42 | /** 43 | * Calls Exit on the sensor handler of the sensors connected to port which index 44 | * is less then the specified port. 45 | * @param sensorHandlers 46 | * @param lastPortExcluded 47 | */ 48 | void exitSensorsUntilPort(SensorHandler * sensorHandlers[], int lastPortExcluded); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /API/sensors/ev3_touch.c: -------------------------------------------------------------------------------- 1 | #include "contrib/lms2012/ev3_basictypes.h" 2 | #include "inputs/ev3_input_analog.h" 3 | #include "ev3_sensors.h" 4 | #include "ev3_sensors/ev3_touch.h" 5 | 6 | // 7 | // PRIVATE DECLARATIONS 8 | // 9 | static bool initEV3Touch(int port); 10 | 11 | // 12 | // GLOBAL DATA 13 | // 14 | 15 | SensorHandler * EV3Touch = &(SensorHandler){ 16 | .Init = initEV3Touch, 17 | .Exit = NULL, 18 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 19 | }; 20 | 21 | // 22 | // IMPLEMENTATION 23 | // 24 | 25 | bool initEV3Touch(int port) { 26 | EV3Touch->currentSensorMode[port] = EV3_TOUCH_SENSOR_TOUCH_MODE; 27 | return true; 28 | } 29 | 30 | bool ReadEV3TouchSensor(int sensorPort) { 31 | DATA16 data = readNewDumbSensor(sensorPort); 32 | int temp = data / 256; 33 | return temp != 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /API/sensors/ev3_touch.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_TOUCH_SENSOR_PRIVATE_H 2 | #define EV3_API_EV3_TOUCH_SENSOR_PRIVATE_H 3 | 4 | #include 5 | #include "ev3_touch.h" 6 | 7 | bool initEV3Touch(int port); 8 | 9 | void setEV3UltrasonicSensorMode(int port, int mode); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /API/sensors/ev3_ultrasonic.c: -------------------------------------------------------------------------------- 1 | #include "inputs/ev3_input_uart.h" 2 | #include "ev3_command.h" 3 | #include "ev3_sensors/ev3_ultrasonic.h" 4 | #include "utility.h" 5 | #include 6 | 7 | // 8 | // PRIVATE DECLARATIONS 9 | // 10 | 11 | static bool initEV3UltrasonicSensor (int port); 12 | 13 | static void setEV3UltrasonicSensorMode(int port, int mode); 14 | 15 | static int distanceRead(int port, int mode, int divisor); 16 | 17 | // 18 | // GLOBAL DATA 19 | // 20 | 21 | SensorHandler * EV3Ultrasonic = &(SensorHandler){ 22 | .Init = initEV3UltrasonicSensor, 23 | .Exit = NULL, 24 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 25 | }; 26 | 27 | // 28 | // IMPLEMENTATION 29 | // 30 | 31 | bool initEV3UltrasonicSensor (int port) { 32 | setEV3UltrasonicSensorMode(port, EV3_ULTRASONIC_SENSOR_DISTANCE_MM_MODE); 33 | return true; 34 | } 35 | 36 | 37 | int ReadEV3UltrasonicSensorDistance(int port, EV3UltrasonicDistanceUnit mode) { 38 | switch (mode) { 39 | case EV3_ULTRASONIC_CM: 40 | return distanceRead(port, EV3_ULTRASONIC_SENSOR_DISTANCE_MM_MODE, 10); 41 | case EV3_ULTRASONIC_MM: 42 | return distanceRead(port, EV3_ULTRASONIC_SENSOR_DISTANCE_MM_MODE, 1); 43 | case EV3_ULTRASONIC_IN: 44 | return distanceRead(port, EV3_ULTRASONIC_SENSOR_DISTANCE_IN_MODE, 1); 45 | default: 46 | return INT_MIN; 47 | } 48 | } 49 | 50 | int ReadEV3UltrasonicSensorSingleDistance(int port, EV3UltrasonicDistanceUnit mode) { 51 | switch (mode) { 52 | case EV3_ULTRASONIC_CM: 53 | return distanceRead(port, EV3_ULTRASONIC_SENSOR_SINGLE_MM_MODE, 10); 54 | case EV3_ULTRASONIC_MM: 55 | return distanceRead(port, EV3_ULTRASONIC_SENSOR_SINGLE_MM_MODE, 1); 56 | case EV3_ULTRASONIC_IN: 57 | return distanceRead(port, EV3_ULTRASONIC_SENSOR_SINGLE_IN_MODE, 1); 58 | default: 59 | return INT_MIN; 60 | } 61 | } 62 | 63 | int ReadEV3UltrasonicSensorDcDistance(int port, EV3UltrasonicDistanceUnit mode) { 64 | switch (mode) { 65 | case EV3_ULTRASONIC_CM: 66 | return distanceRead(port, EV3_ULTRASONIC_SENSOR_DC_MM_MODE, 10); 67 | case EV3_ULTRASONIC_MM: 68 | return distanceRead(port, EV3_ULTRASONIC_SENSOR_DC_MM_MODE, 1); 69 | case EV3_ULTRASONIC_IN: 70 | return distanceRead(port, EV3_ULTRASONIC_SENSOR_DC_IN_MODE, 1); 71 | default: 72 | return INT_MIN; 73 | } 74 | } 75 | 76 | int distanceRead(int port, int mode, int divisor) { 77 | setEV3UltrasonicSensorMode(port, mode); 78 | 79 | DATA16 data = 0; 80 | int retval = readFromUART(port, (DATA8 *) &data, sizeof(data)); 81 | if (retval < 0) 82 | return INT_MIN; 83 | 84 | return data / divisor; 85 | } 86 | 87 | int ReadEV3UltrasonicSensorListen(int port) { 88 | setEV3UltrasonicSensorMode(port, EV3_ULTRASONIC_SENSOR_LISTEN_MODE); 89 | 90 | DATA8 data = 0; 91 | int retval = readFromUART(port, &data, sizeof(data)); 92 | 93 | if (retval < 0) 94 | return INT_MIN; 95 | 96 | return data != 0; 97 | } 98 | 99 | int FireEV3UltrasonicSensor(int port) { 100 | uint8_t cmd = EV3_ULTRASONIC_FIRE_COMMAND; 101 | 102 | int retval = writeToUART(port, (DATA8*) &cmd, sizeof(cmd)); 103 | if (retval != sizeof(cmd)) 104 | return INT_MIN; 105 | 106 | return 0; 107 | } 108 | 109 | void setEV3UltrasonicSensorMode(int port, int mode) { 110 | setUARTSensorHandlerMode(EV3Ultrasonic, port, EV3_ULTRASONIC_SENSOR_TYPE, mode); 111 | } 112 | -------------------------------------------------------------------------------- /API/sensors/ht_color.c: -------------------------------------------------------------------------------- 1 | #include "inputs/ev3_input_iic.h" 2 | #include "ev3_sensors.h" 3 | #include "ev3_sensors/ht_color.h" 4 | 5 | 6 | // 7 | // PRIVATE DECLARATIONS 8 | // 9 | 10 | static bool initHTColorSensorV2(int port); 11 | 12 | static int getHTColorSensorV2ModeFromReadingMode(HTColorV2ReadingMode readingMode); 13 | 14 | static int getHTColorSensorV2ModeForMainsFrequency(HTColorV2PowerMainsFrequency frequency); 15 | 16 | static void setHTColorSensorV2Mode(int port, int sensorMode); 17 | 18 | static void writeToHTColorV2ModeRegister(int port, int value); 19 | 20 | static int readHTColorV2RGBA1ByteColor(int port, RGBA* result); 21 | 22 | static int readHTColorV2RGBA2ByteColor(int port, RGBA* result); 23 | 24 | // 25 | // GLOBAL DATA 26 | // 27 | 28 | SensorHandler * HTColorV2 = &(SensorHandler){ 29 | .Init = initHTColorSensorV2, 30 | .Exit = NULL, 31 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 32 | }; 33 | 34 | // 35 | // IMPLEMENTATION 36 | // 37 | 38 | bool initHTColorSensorV2(int port) { 39 | initIICPort(port, HT_COLOR_SENSOR_V2_IIC_ADDRESS); 40 | return true; 41 | } 42 | 43 | 44 | int ReadHTColorSensorV2(int port) { 45 | DATA8 color; 46 | setHTColorSensorV2Mode(port, HT_COLOR_SENSOR_V2_DEFAULT_MODE); 47 | readFromIIC(port, HT_COLOR_SENSOR_V2_COLOR_REGISTER, &color, 1); 48 | return color; 49 | } 50 | 51 | int ReadHTColorSensorV2RGBA(int port, HTColorV2ReadingMode mode, RGBA* result) { 52 | setHTColorSensorV2Mode(port, getHTColorSensorV2ModeFromReadingMode(mode)); 53 | if (mode == HTColorSensorDefaultMode) { 54 | return readHTColorV2RGBA1ByteColor(port, result); 55 | } else { 56 | return readHTColorV2RGBA2ByteColor(port, result); 57 | } 58 | } 59 | 60 | int readHTColorV2RGBA1ByteColor(int port, RGBA* result) { 61 | DATA8 data[4]; 62 | if (readFromIIC(port, HT_COLOR_SENSOR_V2_R_1BYTE_REGISTER, data, 4) < 0) { 63 | return -1; 64 | } 65 | result->red = ((data[0] & 0xff) * 1023) / 255; 66 | result->green = ((data[1] & 0xff) * 1023) / 255; 67 | result->blue = ((data[2] & 0xff) * 1023) / 255; 68 | result->white = ((data[3] & 0xff) * 1023) / 255; 69 | return 0; 70 | } 71 | 72 | int readHTColorV2RGBA2ByteColor(int port, RGBA* result) { 73 | DATA8 data[8]; 74 | if (readFromIIC(port, 0x42, data, 8) < 0) { 75 | return -1; 76 | } 77 | result->red = ((data[0] & 0xff) << 8) | (data[1] & 0xff); 78 | result->green = ((data[2] & 0xff) << 8) | (data[3] & 0xff); 79 | result->blue = ((data[4] & 0xff) << 8) | (data[5] & 0xff); 80 | result->white = ((data[6] & 0xff) << 8) | (data[7] & 0xff); 81 | return 0; 82 | } 83 | 84 | int getHTColorSensorV2ModeFromReadingMode(HTColorV2ReadingMode readingMode) { 85 | if (readingMode == HTColorSensorDefaultMode) { 86 | return HT_COLOR_SENSOR_V2_DEFAULT_MODE; 87 | } else if (readingMode == HTColorSensorPassiveMode) { 88 | return HT_COLOR_SENSOR_V2_PASSIVE_MODE; 89 | } else { 90 | return HT_COLOR_SENSOR_V2_RAW_MODE; 91 | } 92 | } 93 | 94 | void setHTColorSensorV2Mode(int port, int sensorMode) { 95 | if (sensorMode != HTColorV2->currentSensorMode[port]) { 96 | HTColorV2->currentSensorMode[port] = sensorMode; 97 | writeToHTColorV2ModeRegister(port, sensorMode); 98 | } 99 | } 100 | 101 | void SetHTColorV2PowerMainsFrequency(int port, HTColorV2PowerMainsFrequency frequency) { 102 | writeToHTColorV2ModeRegister(port, getHTColorSensorV2ModeForMainsFrequency(frequency)); 103 | } 104 | 105 | int getHTColorSensorV2ModeForMainsFrequency(HTColorV2PowerMainsFrequency frequency) { 106 | return frequency == PowerMains50Hz ? HT_COLOR_SENSOR_V2_50HZ_MODE : HT_COLOR_SENSOR_V2_60HZ_MODE; 107 | } 108 | 109 | void writeToHTColorV2ModeRegister(int port, int value) { 110 | DATA8 request[] = { HT_COLOR_SENSOR_V2_MODE_REGISTER, value }; 111 | writeToIIC(port, request, 2, 1, 0, 0); 112 | } 113 | 114 | -------------------------------------------------------------------------------- /API/sensors/ht_color.h: -------------------------------------------------------------------------------- 1 | #ifndef HT_COLOR_PRIVATE_H 2 | #define HT_COLOR_PRIVATE_H 3 | 4 | #include "ht_color.h" 5 | 6 | bool initHTColorSensorV2(int port); 7 | 8 | int getHTColorSensorV2ModeFromReadingMode(HTColorV2ReadingMode readingMode); 9 | 10 | int getHTColorSensorV2ModeForMainsFrequency(HTColorV2PowerMainsFrequency frequency); 11 | 12 | void setHTColorSensorV2Mode(int port, int sensorMode); 13 | 14 | void writeToHTColorV2ModeRegister(int port, int value); 15 | 16 | int readHTColorV2RGBA1ByteColor(int port, RGBA* result); 17 | 18 | int readHTColorV2RGBA2ByteColor(int port, RGBA* result); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /API/sensors/ht_compass.c: -------------------------------------------------------------------------------- 1 | #include "inputs/ev3_input_iic.h" 2 | #include "ev3_sensors.h" 3 | #include "ev3_constants.h" 4 | #include "ev3_sensors/ht_compass.h" 5 | 6 | // 7 | // PRIVATE DECLARATIONS 8 | // 9 | 10 | static bool initHTCompassSensor(int port); 11 | 12 | static void exitHTCompassSensor(int port); 13 | 14 | // 15 | // GLOBAL DATA 16 | // 17 | 18 | SensorHandler * HTCompass = &(SensorHandler){ 19 | .Init = initHTCompassSensor, 20 | .Exit = exitHTCompassSensor, 21 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 22 | }; 23 | 24 | static bool htCompassIsCalibrating[NUM_INPUTS]; 25 | 26 | // 27 | // IMPLEMENTATION 28 | // 29 | 30 | bool initHTCompassSensor(int port) { 31 | initIICPort(port, HT_COMPASS_SENSOR_IIC_ADDRESS); 32 | HTCompass->currentSensorMode[port] = HT_COMPASS_SENSOR_DEFAULT_MODE; 33 | return true; 34 | } 35 | 36 | 37 | int ReadHTCompassSensor(int port, HTCompassReadingMode mode) { 38 | HTCompass->currentSensorMode[port] = mode; 39 | DATA8 data; 40 | readFromIIC(port, 0x42, &data, 1); 41 | 42 | if (mode == HTCompassCompass) { 43 | return ((data & 0xFF) << 1); 44 | } else { 45 | int temp = ((data & 0xFF) << 1); 46 | return temp < 180 ? (-temp) : (360 - temp); 47 | } 48 | } 49 | 50 | void StartHTCompassCalibration(int port) { 51 | DATA8 request[] = {0x41, 0x43}; 52 | writeToIIC(port, request, 2, 1, 0, 1); 53 | htCompassIsCalibrating[port] = true; 54 | } 55 | 56 | void StopHTCompassCalibration(int port) { 57 | DATA8 request[] = {0x41, 0x00}; 58 | writeToIIC(port, request, 2, 1, 0, 1); 59 | htCompassIsCalibrating[port] = false; 60 | } 61 | 62 | 63 | void exitHTCompassSensor(int port) { 64 | int i; 65 | for (i = 0; i < NUM_INPUTS; i++) { 66 | if (htCompassIsCalibrating[i]) { 67 | StopHTCompassCalibration(port); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /API/sensors/ht_compass.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_HT_COMPASS_PRIVATE_H 2 | #define EV3_API_HT_COMPASS_PRIVATE_H 3 | 4 | #include "ht_compass.h" 5 | 6 | bool initHTCompassSensor(int port); 7 | 8 | void exitHTCompassSensor(int port); 9 | 10 | #endif //EV3_API_HT_COMPASS_H 11 | -------------------------------------------------------------------------------- /API/sensors/ht_ir_v2.c: -------------------------------------------------------------------------------- 1 | #include "inputs/ev3_input_iic.h" 2 | #include "ev3_sensors.h" 3 | #include "ev3_command.h" 4 | #include "ev3_sensors/ht_ir_v2.h" 5 | 6 | 7 | // 8 | // PRIVATE DECLARATIONS 9 | // 10 | 11 | static bool initHTIrV2Sensor(int port); 12 | 13 | static void exitHTIrV2Sensor(int port); 14 | 15 | static int getHTIrV2RegisterForReadingMode(HTIrV2ReadingMode mode); 16 | 17 | static int getHTIRV2FirstRegisterIndividualChannelsForReadingMode(HTIrV2ReadingMode mode); 18 | 19 | // 20 | // GLOBAL DATA 21 | // 22 | 23 | SensorHandler *HTIrV2 = &(SensorHandler) { 24 | .Init = initHTIrV2Sensor, 25 | .Exit = exitHTIrV2Sensor, 26 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 27 | }; 28 | 29 | // 30 | // IMPLEMENTATION 31 | // 32 | 33 | bool initHTIrV2Sensor(int port) { 34 | initIICPort(port, HT_IR_V2_SENSOR_IIC_ADDRESS); 35 | HTIrV2->currentSensorMode[port] = HT_IR_V2_SENSOR_DEFAULT_MODE; 36 | return true; 37 | } 38 | 39 | 40 | int ReadHTIrV2Sensor(int port, HTIrV2ReadingMode mode) { 41 | DATA8 data; 42 | if(readFromIIC(port, getHTIrV2RegisterForReadingMode(mode), &data, 1) == -1) { 43 | return -1; 44 | } 45 | return ((uint8_t) data) & 0x0Fu; 46 | } 47 | 48 | int getHTIrV2RegisterForReadingMode(HTIrV2ReadingMode mode) { 49 | return mode == Modulated ? HT_IR_V2_SENSOR_AC_READING_MODE_REGISTER : HT_IR_V2_SENSOR_DC_READING_MODE_REGISTER; 50 | } 51 | 52 | int ReadHTIrV2SensorAll(int port, HTIrV2ReadingMode mode, int8_t output[]) { 53 | return readFromIIC(port, getHTIRV2FirstRegisterIndividualChannelsForReadingMode(mode), output, HT_IR_V2_CHANNELS); 54 | } 55 | 56 | int getHTIRV2FirstRegisterIndividualChannelsForReadingMode(HTIrV2ReadingMode mode) { 57 | return mode == Modulated ? HT_IR_V2_SENSOR_AC_ALL_READING_MODE_REGISTER : HT_IR_V2_SENSOR_DC_ALL_READING_MODE_REGISTER; 58 | } 59 | 60 | void exitHTIrV2Sensor(int port) { 61 | /** 62 | * When the ev3 app "Port view" starts, it shows the IR sensor values in DC mode by default. 63 | * If the user used this library and read the IR sensor in AC mode, the EV3 will show the AC values, saying that 64 | * they are DC values. This is why we need to switch back to the DC mode if we are in AC mode 65 | */ 66 | /* 67 | * // TODO: NOT Working 68 | int i; 69 | for (i = 0; i < NUM_INPUTS; i++) { 70 | if (htIrInitialized[port]) { 71 | startPollingFromIIC(port, HT_IR_SENSOR_DC_READING_MODE_REGISTER, 100); 72 | } 73 | }*/ 74 | } 75 | 76 | -------------------------------------------------------------------------------- /API/sensors/ht_ir_v2.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_HT_IR_PRIVATE_H 2 | #define EV3_API_HT_IR_PRIVATE_H 3 | 4 | #include "ht_ir_v2.h" 5 | 6 | 7 | bool initHTIrV2Sensor(int port); 8 | 9 | void exitHTIrV2Sensor(int port); 10 | 11 | int getHTIrV2RegisterForReadingMode(HTIrV2ReadingMode mode); 12 | 13 | int getHTIRV2FirstRegisterIndividualChannelsForReadingMode(HTIrV2ReadingMode mode); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /API/sensors/nxt_sound.c: -------------------------------------------------------------------------------- 1 | #include "inputs/ev3_input_analog.h" 2 | #include "ev3_sensors.h" 3 | #include "ev3_sensors/nxt_sound.h" 4 | 5 | // 6 | // PRIVATE DECLARATIONS 7 | // 8 | 9 | static bool initNXTSoundSensor (int port); 10 | 11 | // 12 | // GLOBAL DATA 13 | // 14 | 15 | SensorHandler * NXTSound = &(SensorHandler){ 16 | .Init = initNXTSoundSensor, 17 | .Exit = NULL, 18 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 19 | }; 20 | 21 | // 22 | // IMPLEMENTATION 23 | // 24 | 25 | bool initNXTSoundSensor (int port) { 26 | NXTSound->currentSensorMode[port] = NXT_SOUND_SENSOR_DEFAULT_MODE; 27 | return true; 28 | } 29 | 30 | int ReadNXTSoundSensor(int port, NXTSoundReadingMode mode) { 31 | // TODO: How to switch reading mode for OldDumb sensor? 32 | DATA16 data = readOldDumbSensor(port); 33 | int temp = data; 34 | return (int)((1.0 - (temp/4095.0)) * 100.0); // ADC_RES = 4095 35 | } 36 | -------------------------------------------------------------------------------- /API/sensors/nxt_sound.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_NXT_SOUND_PRIVATE_H 2 | #define EV3_API_NXT_SOUND_PRIVATE_H 3 | 4 | #include "nxt_sound.h" 5 | 6 | bool initNXTSoundSensor (int port); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /API/sensors/nxt_temperature.c: -------------------------------------------------------------------------------- 1 | #include "inputs/ev3_input_iic.h" 2 | #include "ev3_sensors.h" 3 | #include "ev3_sensors/nxt_temperature.h" 4 | 5 | // 6 | // PRIVATE DECLARATIONS 7 | // 8 | 9 | static bool initNXTTemperatureSensor(int port); 10 | 11 | // 12 | // GLOBAL DATA 13 | // 14 | 15 | SensorHandler * NXTTemperature = &(SensorHandler) { 16 | .Init = initNXTTemperatureSensor, 17 | .Exit = NULL, 18 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 19 | }; 20 | 21 | // 22 | // IMPLEMENTATION 23 | // 24 | 25 | bool initNXTTemperatureSensor (int port) { 26 | NXTSound->currentSensorMode[port] = NXT_TEMPERATURE_SENSOR_DEFAULT_MODE; 27 | return true; 28 | } 29 | 30 | // TODO: Not tested yet 31 | int ReadNXTTemperatureSensor(int port, NXTTemperatureUnit unit) { 32 | DATA16 data; 33 | readFromIICSharedMemory(port, (DATA8 *) &data, 2); 34 | int temp = (data>>4) & 0x0FFF; 35 | if (unit == NXT_TEMPERATURE_C) { 36 | if(temp & 0x800) { 37 | temp = ((temp&0x7FF) ^ 0x7FF) + 1; 38 | return (-1)*(((temp>>4) & 0xFF)*10 + ((temp & 0xF) * 10 / 15)); 39 | } 40 | return ((temp>>4) & 0xFF)*10 + ((temp & 0xF) * 10 / 15); 41 | } else { 42 | if(temp & 0x800) { 43 | temp = ((temp&0x7FF) ^ 0x7FF) + 1; 44 | return (-1)*(((temp>>4) & 0xFF)*10 + ((temp & 0xF) * 10 / 15)) * 9/5 + 320; 45 | } 46 | return (((temp>>4) & 0xFF)*10 + ((temp & 0xF) * 10 / 15)) * 9/5 + 320; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /API/sensors/nxt_temperature.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_NXT_TEMPERATURE_PRIVATE_H 2 | #define EV3_API_NXT_TEMPERATURE_PRIVATE_H 3 | 4 | #include "nxt_temperature.h" 5 | 6 | bool initNXTTemperatureSensor(int port); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /API/sensors/pixy_cam.c: -------------------------------------------------------------------------------- 1 | #include "inputs/ev3_input_iic.h" 2 | #include "ev3_sensors/pixy_cam.h" 3 | #include "ev3_sensors.h" 4 | 5 | // 6 | // PRIVATE DECLARATIONS 7 | // 8 | 9 | static bool initPixyCamSensor(int port); 10 | 11 | // 12 | // GLOBAL DATA 13 | // 14 | 15 | SensorHandler * PixyCam = &(SensorHandler){ 16 | .Init = initPixyCamSensor, 17 | .Exit = NULL, 18 | .currentSensorMode = {NONE_MODE, NONE_MODE, NONE_MODE, NONE_MODE} 19 | }; 20 | 21 | // 22 | // IMPLEMENTATION 23 | // 24 | 25 | static bool initPixyCamSensor(int port) { 26 | initIICPort(port, PIXY_CAM_SENSOR_IIC_ADDRESS); 27 | return true; 28 | } 29 | 30 | 31 | int ReadPixyCamSensorBiggestBlobRectangle(int port, PixyRectangle* result) { 32 | DATA8 rectangleData[6]; 33 | DATA8 angleData[1]; 34 | if(readFromIIC(port, PIXY_CAM_BIGGEST_BLOB_RECTANGLE_REGISTER, rectangleData, 6) < 0) { 35 | return -1; 36 | } 37 | if(readFromIIC(port, PIXY_CAM_BIGGEST_BLOB_ANGLE_REGISTER, angleData, 1) < 0) { 38 | return -1; 39 | } 40 | 41 | result->signature = ((rectangleData[0] & 0xFF) << 8) | (rectangleData[1] & 0xFF); 42 | result->x = (rectangleData[2] & 0xFF); 43 | result->y = (rectangleData[3] & 0xFF); 44 | result->width = (rectangleData[4] & 0xFF); 45 | result->height = (rectangleData[5] & 0xFF); 46 | result->angle = (angleData[0] & 0xFF) * PIXY_CAM_ANGLE_CONSTANT; 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /API/sensors/utility.c: -------------------------------------------------------------------------------- 1 | #include "../inputs/ev3_input_uart.h" 2 | #include "ev3_command.h" 3 | #include "utility.h" 4 | 5 | void setUARTSensorHandlerMode(SensorHandler *handler, int port, int type, int mode) { 6 | int previousMode = handler->currentSensorMode[port]; 7 | setUARTSensorMode(port, type, mode); 8 | handler->currentSensorMode[port] = mode; 9 | if (previousMode != mode) { 10 | Wait(200); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /API/sensors/utility.h: -------------------------------------------------------------------------------- 1 | #include "ev3_sensors.h" 2 | 3 | #ifndef EV3_API_SENSORS_UTILITY_PRIVATE_H 4 | #define EV3_API_SENSORS_UTILITY_PRIVATE_H 5 | 6 | /** 7 | * Changes the mode of the sensor, calling the appropriate function of the UART 8 | * module, and updates the structure of the sensor handler. 9 | * NOTE: a delay is waited when the mode is changed 10 | * @param handler Sensor handler to which change the mode 11 | * @param port The port to which the sensor is connected 12 | * @param type Type of UART sensor, as defined in the lms2012 firmware 13 | * @param mode Mode of the sensor 14 | */ 15 | void setUARTSensorHandlerMode(SensorHandler *handler, int port, int type, int mode); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /API/small_font.xbm: -------------------------------------------------------------------------------- 1 | #define small_font_width 128 2 | #define small_font_height 48 3 | static unsigned char small_font_bits[] = { 4 | 0x00, 0x18, 0x6C, 0x50, 0x20, 0x00, 0x1C, 0x30, 0x60, 0x18, 0x00, 0x00, 5 | 0x00, 0x00, 0x00, 0x60, 0x00, 0x18, 0x6C, 0x50, 0x78, 0x8E, 0x36, 0x30, 6 | 0x30, 0x30, 0x10, 0x10, 0x00, 0x00, 0x00, 0x60, 0x00, 0x18, 0x24, 0xFC, 7 | 0x2C, 0x4A, 0x36, 0x10, 0x18, 0x60, 0x54, 0x10, 0x00, 0x00, 0x00, 0x30, 8 | 0x00, 0x18, 0x00, 0x28, 0x78, 0x2E, 0x9C, 0x00, 0x18, 0x60, 0x38, 0x10, 9 | 0x00, 0x00, 0x00, 0x30, 0x00, 0x18, 0x00, 0x28, 0xD0, 0x10, 0xB6, 0x00, 10 | 0x18, 0x60, 0x54, 0xFE, 0x00, 0x7C, 0x00, 0x18, 0x00, 0x18, 0x00, 0x7E, 11 | 0xD4, 0xE8, 0x66, 0x00, 0x18, 0x60, 0x10, 0x10, 0x00, 0x00, 0x00, 0x18, 12 | 0x00, 0x00, 0x00, 0x14, 0x78, 0xA4, 0xC6, 0x00, 0x30, 0x30, 0x00, 0x10, 13 | 0x60, 0x00, 0x18, 0x0C, 0x00, 0x18, 0x00, 0x14, 0x10, 0xE2, 0xBC, 0x00, 14 | 0x60, 0x18, 0x00, 0x10, 0x70, 0x00, 0x18, 0x0C, 0x7C, 0x30, 0x7C, 0x7C, 15 | 0x60, 0xFC, 0x78, 0xFE, 0x7C, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 16 | 0xC6, 0x3C, 0xC6, 0xC6, 0x70, 0x0C, 0x0C, 0xC0, 0xC6, 0xC6, 0x30, 0x30, 17 | 0x60, 0x00, 0x0C, 0x64, 0xC6, 0x30, 0xC6, 0xC6, 0x68, 0x0C, 0x06, 0x60, 18 | 0xC6, 0xC6, 0x30, 0x30, 0x18, 0xFE, 0x30, 0x60, 0xC6, 0x30, 0x60, 0x30, 19 | 0x64, 0x7C, 0x7E, 0x60, 0x7C, 0xC6, 0x00, 0x00, 0x06, 0x00, 0xC0, 0x30, 20 | 0xC6, 0x30, 0x30, 0xC0, 0x62, 0xC0, 0xC6, 0x30, 0xC6, 0xFC, 0x00, 0x00, 21 | 0x06, 0x00, 0xC0, 0x18, 0xC6, 0x30, 0x18, 0xC6, 0xFE, 0xC6, 0xC6, 0x30, 22 | 0xC6, 0xC0, 0x30, 0x30, 0x18, 0xFE, 0x30, 0x18, 0xC6, 0x30, 0x0C, 0xC6, 23 | 0x60, 0xC6, 0xC6, 0x18, 0xC6, 0x60, 0x30, 0x30, 0x60, 0x00, 0x0C, 0x00, 24 | 0x7C, 0xFC, 0xFE, 0x7C, 0x60, 0x7C, 0x7C, 0x18, 0x7C, 0x3C, 0x00, 0x10, 25 | 0x00, 0x00, 0x00, 0x18, 0x78, 0x18, 0x3E, 0x78, 0x3E, 0xFE, 0xFE, 0x78, 26 | 0xC6, 0x78, 0x7C, 0xC6, 0x06, 0xC6, 0x66, 0x38, 0x84, 0x18, 0x66, 0xCC, 27 | 0x66, 0x06, 0x06, 0xCC, 0xC6, 0x30, 0x60, 0x66, 0x06, 0xEE, 0x6E, 0x6C, 28 | 0xB2, 0x3C, 0x66, 0xC6, 0xC6, 0x06, 0x06, 0xC6, 0xC6, 0x30, 0x60, 0x36, 29 | 0x06, 0xEE, 0x6E, 0xC6, 0xAA, 0x24, 0x7E, 0x06, 0xC6, 0xFE, 0xFE, 0x06, 30 | 0xC6, 0x30, 0x60, 0x1E, 0x06, 0xEE, 0x7E, 0xC6, 0xAA, 0x66, 0xC6, 0x06, 31 | 0xC6, 0x06, 0x06, 0xE6, 0xFE, 0x30, 0x60, 0x36, 0x06, 0xD6, 0x76, 0xC6, 32 | 0x72, 0x7E, 0xC6, 0xC6, 0xC6, 0x06, 0x06, 0xC6, 0xC6, 0x30, 0x60, 0x66, 33 | 0x06, 0xD6, 0x76, 0xC6, 0x04, 0x66, 0xC6, 0xCC, 0x66, 0x06, 0x06, 0xCC, 34 | 0xC6, 0x30, 0x60, 0xC6, 0x06, 0xD6, 0x66, 0x6C, 0x78, 0x66, 0x7E, 0x78, 35 | 0x3E, 0xFE, 0x06, 0xF8, 0xC6, 0x78, 0x3E, 0x86, 0xFE, 0xC6, 0x66, 0x38, 36 | 0x7E, 0x18, 0x7E, 0x7C, 0xFC, 0xC6, 0xC6, 0xC6, 0x66, 0x66, 0xFE, 0x78, 37 | 0x0C, 0x78, 0x30, 0x00, 0xC6, 0x3C, 0xC6, 0xC6, 0x30, 0xC6, 0xC6, 0xC6, 38 | 0x66, 0x66, 0x60, 0x18, 0x0C, 0x60, 0x78, 0x00, 0xC6, 0x66, 0xC6, 0x0E, 39 | 0x30, 0xC6, 0x6C, 0xD6, 0x3C, 0x24, 0x30, 0x18, 0x18, 0x60, 0xCC, 0x00, 40 | 0xC6, 0x66, 0x7E, 0x7C, 0x30, 0xC6, 0x6C, 0xD6, 0x18, 0x3C, 0x30, 0x18, 41 | 0x18, 0x60, 0x00, 0x00, 0x7E, 0x66, 0x36, 0xE0, 0x30, 0xC6, 0x38, 0xD6, 42 | 0x18, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, 0x00, 0x06, 0x76, 0x66, 0xC6, 43 | 0x30, 0xC6, 0x38, 0x7C, 0x3C, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, 0x00, 44 | 0x06, 0x3C, 0xC6, 0xC6, 0x30, 0xC6, 0x10, 0x7C, 0x66, 0x18, 0x0C, 0x18, 45 | 0x60, 0x60, 0x00, 0x00, 0x06, 0xD8, 0x86, 0x7C, 0x30, 0x7C, 0x10, 0x6C, 46 | 0x66, 0x18, 0xFE, 0x78, 0x60, 0x78, 0x00, 0xFE, 0x30, 0x00, 0x06, 0x00, 47 | 0xC0, 0x00, 0x70, 0x00, 0x06, 0x18, 0x18, 0x06, 0x18, 0x00, 0x00, 0x00, 48 | 0x30, 0x7C, 0x06, 0x7C, 0xC0, 0x7C, 0x18, 0xFC, 0x06, 0x18, 0x18, 0xC6, 49 | 0x18, 0xEE, 0x76, 0x7C, 0x20, 0xC0, 0x76, 0xC6, 0xFC, 0xC6, 0x18, 0xC6, 50 | 0x76, 0x00, 0x00, 0x66, 0x18, 0xFE, 0xCE, 0xC6, 0x00, 0xFC, 0xCE, 0x06, 51 | 0xC6, 0xC6, 0x7C, 0xC6, 0xCE, 0x18, 0x1C, 0x36, 0x18, 0xD6, 0xC6, 0xC6, 52 | 0x00, 0xC6, 0xC6, 0x06, 0xC6, 0xFE, 0x18, 0xE6, 0xC6, 0x18, 0x18, 0x1E, 53 | 0x18, 0xD6, 0xC6, 0xC6, 0x00, 0xC6, 0xC6, 0x06, 0xC6, 0x06, 0x18, 0xDC, 54 | 0xC6, 0x18, 0x18, 0x36, 0x18, 0xD6, 0xC6, 0xC6, 0x00, 0xC6, 0xC6, 0xC6, 55 | 0xE6, 0xC6, 0x18, 0xC0, 0xC6, 0x18, 0x18, 0x66, 0x18, 0xD6, 0xC6, 0xC6, 56 | 0x00, 0xFC, 0x7E, 0x7C, 0xDC, 0x7C, 0x18, 0x7C, 0xC6, 0x18, 0x0E, 0xC6, 57 | 0x18, 0xD6, 0xC6, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 58 | 0x00, 0x00, 0x00, 0x70, 0x30, 0x38, 0x98, 0x00, 0x76, 0xFC, 0x6C, 0xF8, 59 | 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xFC, 0x18, 0x30, 0x60, 0xFC, 0x00, 60 | 0xCE, 0xC6, 0x7C, 0x0C, 0x18, 0xC6, 0xC6, 0xD6, 0xC6, 0xC6, 0xC0, 0x18, 61 | 0x30, 0x60, 0x64, 0x00, 0xC6, 0xE6, 0x0C, 0x1C, 0x18, 0xC6, 0xC6, 0xD6, 62 | 0x6C, 0x6C, 0x60, 0x30, 0x30, 0x30, 0x00, 0x00, 0x7E, 0xDC, 0x0C, 0x78, 63 | 0x18, 0xC6, 0x6C, 0xD6, 0x38, 0x6C, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 64 | 0x06, 0xC0, 0x0C, 0xE0, 0x18, 0xC6, 0x6C, 0x7C, 0x6C, 0x38, 0x18, 0x18, 65 | 0x30, 0x60, 0x00, 0x00, 0x06, 0xC0, 0x0C, 0xC0, 0x18, 0xE6, 0x38, 0x6C, 66 | 0xC6, 0x30, 0x0C, 0x18, 0x30, 0x60, 0x00, 0x92, 0x06, 0xC0, 0x0C, 0x7C, 67 | 0x70, 0xDC, 0x38, 0x6C, 0xC6, 0x1C, 0xFC, 0x70, 0x30, 0x38, 0x00, 0x92, 68 | }; 69 | -------------------------------------------------------------------------------- /API/small_icons.xbm: -------------------------------------------------------------------------------- 1 | #define small_icons_width 16 2 | #define small_icons_height 176 3 | static unsigned char small_icons_bits[] = { 4 | 0xFF, 0x7F, 0x01, 0x40, 0xE1, 0xD0, 0xF1, 0x9B, 0xD9, 0x8F, 0x0D, 0xC7, 5 | 0x01, 0x40, 0xFF, 0x7F, 0xFF, 0x7F, 0x01, 0x40, 0xFD, 0xDF, 0xFD, 0x9F, 6 | 0xFD, 0x9F, 0xFD, 0xDF, 0x01, 0x40, 0xFF, 0x7F, 0xFF, 0x7F, 0x01, 0x40, 7 | 0xFD, 0xDF, 0xFD, 0x8F, 0xFD, 0x87, 0xFD, 0xC3, 0x01, 0x40, 0xFF, 0x7F, 8 | 0xFF, 0x7F, 0x01, 0x40, 0xFD, 0xC3, 0xFD, 0x81, 0xFD, 0x80, 0x7D, 0xC0, 9 | 0x01, 0x40, 0xFF, 0x7F, 0xFF, 0x7F, 0x01, 0x40, 0x3D, 0xC0, 0x1D, 0x80, 10 | 0x0D, 0x80, 0x05, 0xC0, 0x01, 0x40, 0xFF, 0x7F, 0xFF, 0x7F, 0x01, 0x40, 11 | 0x01, 0xC0, 0x01, 0x80, 0x01, 0x80, 0x01, 0xC0, 0x01, 0x40, 0xFF, 0x7F, 12 | 0x30, 0x0C, 0x70, 0x0E, 0xB0, 0x0D, 0x30, 0x0C, 0x30, 0x0C, 0xB0, 0x0D, 13 | 0x70, 0x0E, 0x30, 0x0C, 0xF0, 0x0F, 0xF0, 0x0F, 0x20, 0x04, 0x40, 0x02, 14 | 0x40, 0x02, 0x20, 0x04, 0xF0, 0x0F, 0xF0, 0x0F, 0x08, 0x00, 0x1A, 0x00, 15 | 0x2C, 0x00, 0x18, 0x00, 0x2C, 0x00, 0x1A, 0x00, 0x08, 0x00, 0x00, 0x00, 16 | 0x08, 0x00, 0x1A, 0x02, 0x2C, 0x01, 0x98, 0x00, 0x2C, 0x01, 0x1A, 0x02, 17 | 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x9A, 0x00, 0x2C, 0x01, 0x18, 0x02, 18 | 0x2C, 0x01, 0x9A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x1A, 0x0A, 19 | 0x2C, 0x11, 0x98, 0x20, 0x2C, 0x11, 0x1A, 0x0A, 0x08, 0x00, 0x00, 0x00, 20 | 0xFE, 0x01, 0x01, 0x02, 0xFC, 0x00, 0x02, 0x01, 0x78, 0x00, 0x84, 0x00, 21 | 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x02, 0x01, 22 | 0x78, 0x00, 0x84, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x84, 0x00, 0x30, 0x00, 0x30, 0x00, 24 | 0xFE, 0x01, 0x01, 0x12, 0xFC, 0xF8, 0x02, 0x11, 0x78, 0x40, 0x84, 0xF8, 25 | 0x30, 0x40, 0x30, 0x00, 0xFE, 0x21, 0x01, 0x72, 0xFC, 0x70, 0x02, 0x71, 26 | 0x78, 0x20, 0x84, 0x00, 0x30, 0x20, 0x30, 0x20, 0x20, 0x00, 0x70, 0x04, 27 | 0x20, 0x02, 0x20, 0x01, 0xA0, 0x00, 0x20, 0x04, 0xE0, 0x0F, 0x00, 0x04, 28 | 0x20, 0x00, 0x70, 0x00, 0x20, 0x02, 0x20, 0x01, 0xA0, 0x00, 0x20, 0x04, 29 | 0xE0, 0x0F, 0x00, 0x04, 0x20, 0x00, 0x70, 0x00, 0x20, 0x00, 0x20, 0x01, 30 | 0xA0, 0x00, 0x20, 0x04, 0xE0, 0x0F, 0x00, 0x04, 0x20, 0x00, 0x70, 0x00, 31 | 0x20, 0x00, 0x20, 0x00, 0xA0, 0x00, 0x20, 0x04, 0xE0, 0x0F, 0x00, 0x04, 32 | 0x00, 0x00, 0x00, 0x00, 0xC9, 0x1D, 0x29, 0x24, 0xE9, 0x1D, 0x09, 0x25, 33 | 0xE6, 0x1C, 0x00, 0x00, }; 34 | -------------------------------------------------------------------------------- /API/tiny_font.xbm: -------------------------------------------------------------------------------- 1 | #define tiny_font_width 125 2 | #define tiny_font_height 42 3 | static unsigned char tiny_font_bits[] = { 4 | 0x00, 0x02, 0x0A, 0x0A, 0x04, 0x00, 0x06, 0x04, 0x04, 0x01, 0x00, 0x00, 5 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0A, 0x0F, 0x0E, 0x0A, 0x09, 0x04, 6 | 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x00, 0x0A, 7 | 0x02, 0x08, 0x09, 0x02, 0x01, 0x04, 0x07, 0x04, 0x00, 0x00, 0x00, 0x08, 8 | 0x00, 0x02, 0x00, 0x0F, 0x0E, 0x04, 0x06, 0x00, 0x01, 0x04, 0x02, 0x0E, 9 | 0x00, 0x0F, 0x00, 0x04, 0x00, 0x02, 0x00, 0x0A, 0x08, 0x04, 0x09, 0x00, 10 | 0x01, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 11 | 0x0E, 0x02, 0x05, 0x00, 0x02, 0x02, 0x00, 0x00, 0x04, 0x00, 0x04, 0x02, 12 | 0x00, 0x02, 0x00, 0x00, 0x04, 0x0A, 0x0A, 0x00, 0x04, 0x01, 0x00, 0x00, 13 | 0x06, 0x00, 0x04, 0x02, 0x06, 0x04, 0x06, 0x06, 0x04, 0x0E, 0x06, 0x0F, 14 | 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x06, 0x09, 0x09, 15 | 0x06, 0x02, 0x09, 0x08, 0x09, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 16 | 0x09, 0x05, 0x08, 0x08, 0x05, 0x07, 0x01, 0x04, 0x09, 0x09, 0x00, 0x00, 17 | 0x04, 0x00, 0x01, 0x08, 0x09, 0x04, 0x04, 0x06, 0x0F, 0x09, 0x07, 0x04, 18 | 0x06, 0x0E, 0x04, 0x04, 0x02, 0x07, 0x02, 0x04, 0x09, 0x04, 0x02, 0x08, 19 | 0x04, 0x08, 0x09, 0x02, 0x09, 0x08, 0x00, 0x00, 0x01, 0x00, 0x04, 0x04, 20 | 0x09, 0x04, 0x01, 0x09, 0x04, 0x09, 0x09, 0x02, 0x09, 0x09, 0x04, 0x04, 21 | 0x02, 0x07, 0x02, 0x00, 0x06, 0x04, 0x0F, 0x06, 0x04, 0x06, 0x06, 0x02, 22 | 0x06, 0x06, 0x00, 0x02, 0x04, 0x00, 0x01, 0x04, 0x00, 0x06, 0x07, 0x06, 23 | 0x07, 0x0F, 0x0F, 0x06, 0x09, 0x0E, 0x07, 0x09, 0x01, 0x1B, 0x09, 0x06, 24 | 0x0E, 0x09, 0x09, 0x09, 0x09, 0x01, 0x01, 0x01, 0x09, 0x04, 0x04, 0x09, 25 | 0x01, 0x15, 0x0B, 0x09, 0x09, 0x09, 0x09, 0x01, 0x09, 0x01, 0x01, 0x01, 26 | 0x09, 0x04, 0x04, 0x05, 0x01, 0x15, 0x0B, 0x09, 0x0D, 0x0F, 0x07, 0x01, 27 | 0x09, 0x0F, 0x03, 0x0D, 0x0F, 0x04, 0x04, 0x03, 0x01, 0x15, 0x0D, 0x09, 28 | 0x05, 0x09, 0x09, 0x01, 0x09, 0x01, 0x01, 0x09, 0x09, 0x04, 0x04, 0x05, 29 | 0x01, 0x11, 0x0D, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x01, 0x01, 0x09, 30 | 0x09, 0x04, 0x04, 0x09, 0x01, 0x11, 0x09, 0x09, 0x0E, 0x09, 0x07, 0x06, 31 | 0x07, 0x0F, 0x01, 0x06, 0x09, 0x0E, 0x03, 0x09, 0x0F, 0x11, 0x09, 0x06, 32 | 0x07, 0x06, 0x07, 0x06, 0x07, 0x09, 0x09, 0x11, 0x09, 0x09, 0x0F, 0x0E, 33 | 0x00, 0x0E, 0x04, 0x00, 0x09, 0x09, 0x09, 0x09, 0x02, 0x09, 0x09, 0x11, 34 | 0x09, 0x09, 0x08, 0x02, 0x02, 0x08, 0x0A, 0x00, 0x09, 0x09, 0x09, 0x01, 35 | 0x02, 0x09, 0x09, 0x11, 0x06, 0x09, 0x04, 0x02, 0x02, 0x08, 0x00, 0x00, 36 | 0x09, 0x0B, 0x09, 0x06, 0x02, 0x09, 0x0A, 0x11, 0x06, 0x06, 0x04, 0x02, 37 | 0x04, 0x08, 0x00, 0x00, 0x07, 0x05, 0x07, 0x08, 0x02, 0x09, 0x0A, 0x15, 38 | 0x06, 0x02, 0x02, 0x02, 0x04, 0x08, 0x00, 0x00, 0x01, 0x09, 0x05, 0x09, 39 | 0x02, 0x0D, 0x04, 0x15, 0x09, 0x02, 0x01, 0x02, 0x08, 0x08, 0x00, 0x00, 40 | 0x01, 0x06, 0x09, 0x06, 0x02, 0x0A, 0x04, 0x1B, 0x09, 0x02, 0x0F, 0x0E, 41 | 0x08, 0x0E, 0x00, 0x0F, 0x04, 0x00, 0x01, 0x00, 0x08, 0x00, 0x0C, 0x00, 42 | 0x01, 0x00, 0x08, 0x01, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 43 | 0x08, 0x00, 0x02, 0x0E, 0x01, 0x04, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 44 | 0x00, 0x0E, 0x01, 0x06, 0x08, 0x06, 0x02, 0x09, 0x01, 0x00, 0x0C, 0x01, 45 | 0x04, 0x0B, 0x07, 0x06, 0x00, 0x09, 0x07, 0x09, 0x0E, 0x09, 0x07, 0x09, 46 | 0x07, 0x04, 0x08, 0x09, 0x04, 0x15, 0x09, 0x09, 0x00, 0x09, 0x09, 0x01, 47 | 0x09, 0x0F, 0x02, 0x0E, 0x09, 0x04, 0x08, 0x05, 0x04, 0x15, 0x09, 0x09, 48 | 0x00, 0x0D, 0x09, 0x09, 0x0D, 0x01, 0x02, 0x08, 0x09, 0x04, 0x09, 0x03, 49 | 0x04, 0x15, 0x09, 0x09, 0x00, 0x0A, 0x07, 0x06, 0x0A, 0x06, 0x02, 0x06, 50 | 0x09, 0x04, 0x06, 0x0D, 0x0C, 0x15, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x02, 0x14, 0x00, 52 | 0x07, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 53 | 0x04, 0x04, 0x0A, 0x00, 0x09, 0x09, 0x05, 0x0E, 0x02, 0x09, 0x11, 0x15, 54 | 0x11, 0x09, 0x0F, 0x04, 0x04, 0x04, 0x00, 0x00, 0x09, 0x09, 0x0B, 0x01, 55 | 0x0F, 0x09, 0x11, 0x15, 0x0A, 0x09, 0x08, 0x02, 0x04, 0x08, 0x00, 0x00, 56 | 0x07, 0x0E, 0x01, 0x06, 0x02, 0x09, 0x0A, 0x15, 0x04, 0x0E, 0x06, 0x04, 57 | 0x04, 0x04, 0x00, 0x00, 0x01, 0x08, 0x01, 0x08, 0x02, 0x09, 0x0A, 0x15, 58 | 0x0A, 0x08, 0x01, 0x04, 0x04, 0x04, 0x00, 0x00, 0x01, 0x08, 0x01, 0x07, 59 | 0x0C, 0x0E, 0x04, 0x0A, 0x11, 0x06, 0x0F, 0x08, 0x04, 0x02, 0x00, 0x05, 60 | }; 61 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ## Copyright (c) 2015 Ahmad Fatoum 2 | 3 | # define commands 4 | CROSS_COMPILE ?= C:/CSLite/bin/arm-none-linux-gnueabi- 5 | PREFIX ?= $(CROSS_COMPILE) 6 | CC = $(PREFIX)gcc 7 | AR = $(PREFIX)ar 8 | SED = sed 9 | MKDIR = mkdir -p 10 | INSTALL = cp 11 | RM = rm -rf 12 | 13 | # define directories 14 | # - for build 15 | OBJDIR := .objs 16 | # - for install 17 | DESTDIR ?= $(CURDIR)/installed 18 | INCLUDEDIR ?= $(DESTDIR)/include 19 | LIBDIR ?= $(DESTDIR)/lib 20 | 21 | # define files 22 | SRCS = $(wildcard API/*.c API/**/*.c contrib/**/*.c) 23 | OBJS = $(patsubst %.c,$(OBJDIR)/%.o,$(SRCS)) 24 | DEPFILES = $(patsubst %.c,$(OBJDIR)/%.d,$(SRCS)) 25 | 26 | # define flags 27 | override CFLAGS += -std=c99 28 | override CFLAGS += -fno-strict-aliasing -fwrapv 29 | override CFLAGS += -Wall -Wextra -Wpointer-sign -Wno-unused-parameter 30 | override CFLAGS += -D_GNU_SOURCE=1 31 | 32 | # logging control 33 | ifeq ($(VERBOSE)$(V),) 34 | Q = @@ 35 | else 36 | Q = 37 | endif 38 | 39 | -include api-config.mk 40 | 41 | # library building 42 | 43 | all: libev3api.a 44 | 45 | libev3api.a: $(OBJS) 46 | @echo " [AR] $@" 47 | $(Q)$(AR) rcs $@ $^ 48 | 49 | $(OBJDIR)/%.o: %.c $(OBJDIR)/%.d 50 | @echo " [CC] $<" 51 | @$(MKDIR) $(@D) 52 | $(Q)$(CC) -isystem include -MMD -MP -Os $(CFLAGS) -isystem. -I API -c $< -o $@ 53 | 54 | $(DEPFILES): 55 | @$(MKDIR) $(@D) 56 | 57 | -include $(DEPFILES) 58 | 59 | # pkgconfig processing & installation 60 | 61 | install: libev3api.a API/libev3api.pc.in 62 | @# this cannot be a target because it depends on the variable value 63 | @echo " [SED] libev3api.pc" 64 | $(Q)$(SED) -e "s+@PREFIX@+$(DESTDIR)+" \ 65 | -e "s+@INCDIR@+$(INCLUDEDIR)+" \ 66 | -e "s+@LIBDIR@+$(LIBDIR)+" \ 67 | API/libev3api.pc.in > libev3api.pc 68 | 69 | @echo " [INSTALL] libev3api.a" 70 | $(Q)$(MKDIR) $(LIBDIR)/pkgconfig $(INCLUDEDIR)/ev3api 71 | $(Q)$(INSTALL) libev3api.a $(LIBDIR)/ 72 | 73 | @echo " [INSTALL] libev3api.pc" 74 | $(Q)$(INSTALL) libev3api.pc $(LIBDIR)/pkgconfig/ 75 | 76 | @echo " [INSTALL] API/*.h" 77 | $(Q)$(INSTALL) API/*.h $(INCLUDEDIR)/ev3api/ 78 | 79 | uninstall: 80 | $(RM) $(LIBDIR)/libev3api.a \ 81 | $(LIBDIR)/pkgconfig/libev3api.pc \ 82 | $(INCLUDEDIR)/ev3api 83 | 84 | 85 | # sanity check helper 86 | 87 | example: 88 | echo 'int main(void) { return EV3IsInitialized() == 1; }' | $(CC) -xc $(CFLAGS) - -L. -lev3api -IAPI/include -oexample -include ev3.h 89 | 90 | # cleanup 91 | 92 | clean: 93 | $(RM) $(OBJDIR) *.a *.pc example 94 | 95 | .PHONY: all clean install uninstall 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EV3-API [![Build Status](https://travis-ci.org/c4ev3/EV3-API.svg?branch=master)](https://travis-ci.org/c4ev3/EV3-API) [![Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/c4ev3/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 2 | 3 | This API supports the follwing functionallity: 4 | * Easy initialization with one header-file 5 | * Controlling LEGO motors 6 | * Reading out of Touch, Ultrasonic, Color, Gyro, EV3-Infrared, NXT-Infrared Sensor and NXT Temperaturesensor 7 | * Controling Buttons and LED 8 | * Printing text on LCD 9 | * Playing sounds 10 | 11 | The basis of this API was developed by [John Hansen](http://bricxcc.sourceforge.net/test_releases/) 12 | and [Carsten Zeiffert](https://github.com/carstenz/ev3sensor/). 13 | These API's were merged and extended. 14 | 15 | ## Building from source 16 | If you change something in the source, rebuild with a simple `make` (with MinGW, it's called `mingw32-make`). 17 | 18 | Unless you are using the Eclipse Plugin, you will also need to explicitly link against the static `.a` file generated like so: 19 | `-L/path/to/libev3api -lev3api`. 20 | 21 | # Acknowledgements 22 | This plugin has been originally written for use in the teaching of Informatics at the [Hochschule Aschaffenburg](https://www.h-ab.de/). 23 | The work is part of the [EVELIN](http://www.evelinprojekt.de/en/) project, which was funded by the German Federal Ministry of Education and Research (Bundesministerium für Bildung und Forschung) under grant number 01PL12022B. 24 | The authors are responsible for the content of this publication. 25 | 26 | The code is provided under the terms of the GNU General Public License v2.0. 27 | -------------------------------------------------------------------------------- /commands.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c4ev3/EV3-API/89994acb4d7887dc38fdd741555b0633e66d044e/commands.pdf -------------------------------------------------------------------------------- /contrib/bluetooth/bluetooth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2001 Qualcomm Incorporated 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 8 | * 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | * 24 | */ 25 | 26 | #ifndef __BLUETOOTH_H 27 | #define __BLUETOOTH_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #ifndef AF_BLUETOOTH 40 | #define AF_BLUETOOTH 31 41 | #define PF_BLUETOOTH AF_BLUETOOTH 42 | #endif 43 | 44 | #define BTPROTO_L2CAP 0 45 | #define BTPROTO_HCI 1 46 | #define BTPROTO_SCO 2 47 | #define BTPROTO_RFCOMM 3 48 | #define BTPROTO_BNEP 4 49 | #define BTPROTO_CMTP 5 50 | #define BTPROTO_HIDP 6 51 | #define BTPROTO_AVDTP 7 52 | 53 | #define SOL_HCI 0 54 | #define SOL_L2CAP 6 55 | #define SOL_SCO 17 56 | #define SOL_RFCOMM 18 57 | 58 | #ifndef SOL_BLUETOOTH 59 | #define SOL_BLUETOOTH 274 60 | #endif 61 | 62 | #define BT_SECURITY 4 63 | struct bt_security { 64 | uint8_t level; 65 | }; 66 | #define BT_SECURITY_SDP 0 67 | #define BT_SECURITY_LOW 1 68 | #define BT_SECURITY_MEDIUM 2 69 | #define BT_SECURITY_HIGH 3 70 | 71 | #define BT_DEFER_SETUP 7 72 | 73 | /* Connection and socket states */ 74 | enum { 75 | BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ 76 | BT_OPEN, 77 | BT_BOUND, 78 | BT_LISTEN, 79 | BT_CONNECT, 80 | BT_CONNECT2, 81 | BT_CONFIG, 82 | BT_DISCONN, 83 | BT_CLOSED 84 | }; 85 | 86 | /* Byte order conversions */ 87 | #if __BYTE_ORDER == __LITTLE_ENDIAN 88 | #define htobs(d) (d) 89 | #define htobl(d) (d) 90 | #define btohs(d) (d) 91 | #define btohl(d) (d) 92 | #elif __BYTE_ORDER == __BIG_ENDIAN 93 | #define htobs(d) bswap_16(d) 94 | #define htobl(d) bswap_32(d) 95 | #define btohs(d) bswap_16(d) 96 | #define btohl(d) bswap_32(d) 97 | #else 98 | #error "Unknown byte order" 99 | #endif 100 | 101 | /* Bluetooth unaligned access */ 102 | #define bt_get_unaligned(ptr) \ 103 | ({ \ 104 | struct __attribute__((packed)) { \ 105 | typeof(*(ptr)) __v; \ 106 | } *__p = (void *) (ptr); \ 107 | __p->__v; \ 108 | }) 109 | 110 | #define bt_put_unaligned(val, ptr) \ 111 | do { \ 112 | struct __attribute__((packed)) { \ 113 | typeof(*(ptr)) __v; \ 114 | } *__p = (void *) (ptr); \ 115 | __p->__v = (val); \ 116 | } while(0) 117 | 118 | /* BD Address */ 119 | typedef struct { 120 | uint8_t b[6]; 121 | } __attribute__((packed)) bdaddr_t; 122 | 123 | #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 124 | #define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) 125 | #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) 126 | 127 | /* Copy, swap, convert BD Address */ 128 | static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2) 129 | { 130 | return memcmp(ba1, ba2, sizeof(bdaddr_t)); 131 | } 132 | static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src) 133 | { 134 | memcpy(dst, src, sizeof(bdaddr_t)); 135 | } 136 | 137 | void baswap(bdaddr_t *dst, const bdaddr_t *src); 138 | bdaddr_t *strtoba(const char *str); 139 | char *batostr(const bdaddr_t *ba); 140 | int ba2str(const bdaddr_t *ba, char *str); 141 | int str2ba(const char *str, bdaddr_t *ba); 142 | int ba2oui(const bdaddr_t *ba, char *oui); 143 | int bachk(const char *str); 144 | 145 | int baprintf(const char *format, ...); 146 | int bafprintf(FILE *stream, const char *format, ...); 147 | int basprintf(char *str, const char *format, ...); 148 | int basnprintf(char *str, size_t size, const char *format, ...); 149 | 150 | void *bt_malloc(size_t size); 151 | void bt_free(void *ptr); 152 | 153 | int bt_error(uint16_t code); 154 | char *bt_compidtostr(int id); 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | 160 | #endif /* __BLUETOOTH_H */ 161 | -------------------------------------------------------------------------------- /contrib/bluetooth/bnep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2002-2003 Maxim Krasnyansky 6 | * Copyright (C) 2002-2010 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef __BNEP_H 26 | #define __BNEP_H 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #include 33 | 34 | #ifndef ETH_ALEN 35 | #define ETH_ALEN 6 /* from */ 36 | #endif 37 | 38 | /* BNEP UUIDs */ 39 | #define BNEP_BASE_UUID 0x0000000000001000800000805F9B34FB 40 | #define BNEP_UUID16 0x02 41 | #define BNEP_UUID32 0x04 42 | #define BNEP_UUID128 0x16 43 | 44 | #define BNEP_SVC_PANU 0x1115 45 | #define BNEP_SVC_NAP 0x1116 46 | #define BNEP_SVC_GN 0x1117 47 | 48 | /* BNEP packet types */ 49 | #define BNEP_GENERAL 0x00 50 | #define BNEP_CONTROL 0x01 51 | #define BNEP_COMPRESSED 0x02 52 | #define BNEP_COMPRESSED_SRC_ONLY 0x03 53 | #define BNEP_COMPRESSED_DST_ONLY 0x04 54 | 55 | /* BNEP control types */ 56 | #define BNEP_CMD_NOT_UNDERSTOOD 0x00 57 | #define BNEP_SETUP_CONN_REQ 0x01 58 | #define BNEP_SETUP_CONN_RSP 0x02 59 | #define BNEP_FILTER_NET_TYPE_SET 0x03 60 | #define BNEP_FILTER_NET_TYPE_RSP 0x04 61 | #define BNEP_FILTER_MULT_ADDR_SET 0x05 62 | #define BNEP_FILTER_MULT_ADDR_RSP 0x06 63 | 64 | /* BNEP response messages */ 65 | #define BNEP_SUCCESS 0x00 66 | 67 | #define BNEP_CONN_INVALID_DST 0x01 68 | #define BNEP_CONN_INVALID_SRC 0x02 69 | #define BNEP_CONN_INVALID_SVC 0x03 70 | #define BNEP_CONN_NOT_ALLOWED 0x04 71 | 72 | #define BNEP_FILTER_UNSUPPORTED_REQ 0x01 73 | #define BNEP_FILTER_INVALID_RANGE 0x02 74 | #define BNEP_FILTER_INVALID_MCADDR 0x02 75 | #define BNEP_FILTER_LIMIT_REACHED 0x03 76 | #define BNEP_FILTER_DENIED_SECURITY 0x04 77 | 78 | /* L2CAP settings */ 79 | #define BNEP_MTU 1691 80 | #define BNEP_FLUSH_TO 0xffff 81 | #define BNEP_CONNECT_TO 15 82 | #define BNEP_FILTER_TO 15 83 | 84 | #ifndef BNEP_PSM 85 | #define BNEP_PSM 0x0f 86 | #endif 87 | 88 | /* BNEP headers */ 89 | #define BNEP_TYPE_MASK 0x7f 90 | #define BNEP_EXT_HEADER 0x80 91 | 92 | struct bnep_setup_conn_req { 93 | uint8_t type; 94 | uint8_t ctrl; 95 | uint8_t uuid_size; 96 | uint8_t service[0]; 97 | } __attribute__((packed)); 98 | 99 | struct bnep_set_filter_req { 100 | uint8_t type; 101 | uint8_t ctrl; 102 | uint16_t len; 103 | uint8_t list[0]; 104 | } __attribute__((packed)); 105 | 106 | struct bnep_control_rsp { 107 | uint8_t type; 108 | uint8_t ctrl; 109 | uint16_t resp; 110 | } __attribute__((packed)); 111 | 112 | struct bnep_ext_hdr { 113 | uint8_t type; 114 | uint8_t len; 115 | uint8_t data[0]; 116 | } __attribute__((packed)); 117 | 118 | /* BNEP ioctl defines */ 119 | #define BNEPCONNADD _IOW('B', 200, int) 120 | #define BNEPCONNDEL _IOW('B', 201, int) 121 | #define BNEPGETCONNLIST _IOR('B', 210, int) 122 | #define BNEPGETCONNINFO _IOR('B', 211, int) 123 | 124 | struct bnep_connadd_req { 125 | int sock; /* Connected socket */ 126 | uint32_t flags; 127 | uint16_t role; 128 | char device[16]; /* Name of the Ethernet device */ 129 | }; 130 | 131 | struct bnep_conndel_req { 132 | uint32_t flags; 133 | uint8_t dst[ETH_ALEN]; 134 | }; 135 | 136 | struct bnep_conninfo { 137 | uint32_t flags; 138 | uint16_t role; 139 | uint16_t state; 140 | uint8_t dst[ETH_ALEN]; 141 | char device[16]; 142 | }; 143 | 144 | struct bnep_connlist_req { 145 | uint32_t cnum; 146 | struct bnep_conninfo *ci; 147 | }; 148 | 149 | #ifdef __cplusplus 150 | } 151 | #endif 152 | 153 | #endif /* __BNEP_H */ 154 | -------------------------------------------------------------------------------- /contrib/bluetooth/cmtp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2002-2010 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifndef __CMTP_H 25 | #define __CMTP_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* CMTP defaults */ 32 | #define CMTP_MINIMUM_MTU 152 33 | #define CMTP_DEFAULT_MTU 672 34 | 35 | /* CMTP ioctl defines */ 36 | #define CMTPCONNADD _IOW('C', 200, int) 37 | #define CMTPCONNDEL _IOW('C', 201, int) 38 | #define CMTPGETCONNLIST _IOR('C', 210, int) 39 | #define CMTPGETCONNINFO _IOR('C', 211, int) 40 | 41 | #define CMTP_LOOPBACK 0 42 | 43 | struct cmtp_connadd_req { 44 | int sock; /* Connected socket */ 45 | uint32_t flags; 46 | }; 47 | 48 | struct cmtp_conndel_req { 49 | bdaddr_t bdaddr; 50 | uint32_t flags; 51 | }; 52 | 53 | struct cmtp_conninfo { 54 | bdaddr_t bdaddr; 55 | uint32_t flags; 56 | uint16_t state; 57 | int num; 58 | }; 59 | 60 | struct cmtp_connlist_req { 61 | uint32_t cnum; 62 | struct cmtp_conninfo *ci; 63 | }; 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __CMTP_H */ 70 | -------------------------------------------------------------------------------- /contrib/bluetooth/hidp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2003-2010 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifndef __HIDP_H 25 | #define __HIDP_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* HIDP defaults */ 32 | #define HIDP_MINIMUM_MTU 48 33 | #define HIDP_DEFAULT_MTU 48 34 | 35 | /* HIDP ioctl defines */ 36 | #define HIDPCONNADD _IOW('H', 200, int) 37 | #define HIDPCONNDEL _IOW('H', 201, int) 38 | #define HIDPGETCONNLIST _IOR('H', 210, int) 39 | #define HIDPGETCONNINFO _IOR('H', 211, int) 40 | 41 | #define HIDP_VIRTUAL_CABLE_UNPLUG 0 42 | #define HIDP_BOOT_PROTOCOL_MODE 1 43 | #define HIDP_BLUETOOTH_VENDOR_ID 9 44 | 45 | struct hidp_connadd_req { 46 | int ctrl_sock; /* Connected control socket */ 47 | int intr_sock; /* Connected interrupt socket */ 48 | uint16_t parser; /* Parser version */ 49 | uint16_t rd_size; /* Report descriptor size */ 50 | uint8_t *rd_data; /* Report descriptor data */ 51 | uint8_t country; 52 | uint8_t subclass; 53 | uint16_t vendor; 54 | uint16_t product; 55 | uint16_t version; 56 | uint32_t flags; 57 | uint32_t idle_to; 58 | char name[128]; /* Device name */ 59 | }; 60 | 61 | struct hidp_conndel_req { 62 | bdaddr_t bdaddr; 63 | uint32_t flags; 64 | }; 65 | 66 | struct hidp_conninfo { 67 | bdaddr_t bdaddr; 68 | uint32_t flags; 69 | uint16_t state; 70 | uint16_t vendor; 71 | uint16_t product; 72 | uint16_t version; 73 | char name[128]; 74 | }; 75 | 76 | struct hidp_connlist_req { 77 | uint32_t cnum; 78 | struct hidp_conninfo *ci; 79 | }; 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* __HIDP_H */ 86 | -------------------------------------------------------------------------------- /contrib/bluetooth/l2cap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2001 Qualcomm Incorporated 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 8 | * 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | * 24 | */ 25 | 26 | #ifndef __L2CAP_H 27 | #define __L2CAP_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include 34 | 35 | /* L2CAP defaults */ 36 | #define L2CAP_DEFAULT_MTU 672 37 | #define L2CAP_DEFAULT_FLUSH_TO 0xFFFF 38 | 39 | /* L2CAP socket address */ 40 | struct sockaddr_l2 { 41 | sa_family_t l2_family; 42 | unsigned short l2_psm; 43 | bdaddr_t l2_bdaddr; 44 | unsigned short l2_cid; 45 | }; 46 | 47 | /* L2CAP socket options */ 48 | #define L2CAP_OPTIONS 0x01 49 | struct l2cap_options { 50 | uint16_t omtu; 51 | uint16_t imtu; 52 | uint16_t flush_to; 53 | uint8_t mode; 54 | uint8_t fcs; 55 | uint8_t max_tx; 56 | uint16_t txwin_size; 57 | }; 58 | 59 | #define L2CAP_CONNINFO 0x02 60 | struct l2cap_conninfo { 61 | uint16_t hci_handle; 62 | uint8_t dev_class[3]; 63 | }; 64 | 65 | #define L2CAP_LM 0x03 66 | #define L2CAP_LM_MASTER 0x0001 67 | #define L2CAP_LM_AUTH 0x0002 68 | #define L2CAP_LM_ENCRYPT 0x0004 69 | #define L2CAP_LM_TRUSTED 0x0008 70 | #define L2CAP_LM_RELIABLE 0x0010 71 | #define L2CAP_LM_SECURE 0x0020 72 | 73 | /* L2CAP command codes */ 74 | #define L2CAP_COMMAND_REJ 0x01 75 | #define L2CAP_CONN_REQ 0x02 76 | #define L2CAP_CONN_RSP 0x03 77 | #define L2CAP_CONF_REQ 0x04 78 | #define L2CAP_CONF_RSP 0x05 79 | #define L2CAP_DISCONN_REQ 0x06 80 | #define L2CAP_DISCONN_RSP 0x07 81 | #define L2CAP_ECHO_REQ 0x08 82 | #define L2CAP_ECHO_RSP 0x09 83 | #define L2CAP_INFO_REQ 0x0a 84 | #define L2CAP_INFO_RSP 0x0b 85 | 86 | /* L2CAP structures */ 87 | typedef struct { 88 | uint16_t len; 89 | uint16_t cid; 90 | } __attribute__ ((packed)) l2cap_hdr; 91 | #define L2CAP_HDR_SIZE 4 92 | 93 | typedef struct { 94 | uint8_t code; 95 | uint8_t ident; 96 | uint16_t len; 97 | } __attribute__ ((packed)) l2cap_cmd_hdr; 98 | #define L2CAP_CMD_HDR_SIZE 4 99 | 100 | typedef struct { 101 | uint16_t reason; 102 | } __attribute__ ((packed)) l2cap_cmd_rej; 103 | #define L2CAP_CMD_REJ_SIZE 2 104 | 105 | typedef struct { 106 | uint16_t psm; 107 | uint16_t scid; 108 | } __attribute__ ((packed)) l2cap_conn_req; 109 | #define L2CAP_CONN_REQ_SIZE 4 110 | 111 | typedef struct { 112 | uint16_t dcid; 113 | uint16_t scid; 114 | uint16_t result; 115 | uint16_t status; 116 | } __attribute__ ((packed)) l2cap_conn_rsp; 117 | #define L2CAP_CONN_RSP_SIZE 8 118 | 119 | /* connect result */ 120 | #define L2CAP_CR_SUCCESS 0x0000 121 | #define L2CAP_CR_PEND 0x0001 122 | #define L2CAP_CR_BAD_PSM 0x0002 123 | #define L2CAP_CR_SEC_BLOCK 0x0003 124 | #define L2CAP_CR_NO_MEM 0x0004 125 | 126 | /* connect status */ 127 | #define L2CAP_CS_NO_INFO 0x0000 128 | #define L2CAP_CS_AUTHEN_PEND 0x0001 129 | #define L2CAP_CS_AUTHOR_PEND 0x0002 130 | 131 | typedef struct { 132 | uint16_t dcid; 133 | uint16_t flags; 134 | uint8_t data[0]; 135 | } __attribute__ ((packed)) l2cap_conf_req; 136 | #define L2CAP_CONF_REQ_SIZE 4 137 | 138 | typedef struct { 139 | uint16_t scid; 140 | uint16_t flags; 141 | uint16_t result; 142 | uint8_t data[0]; 143 | } __attribute__ ((packed)) l2cap_conf_rsp; 144 | #define L2CAP_CONF_RSP_SIZE 6 145 | 146 | #define L2CAP_CONF_SUCCESS 0x0000 147 | #define L2CAP_CONF_UNACCEPT 0x0001 148 | #define L2CAP_CONF_REJECT 0x0002 149 | #define L2CAP_CONF_UNKNOWN 0x0003 150 | 151 | typedef struct { 152 | uint8_t type; 153 | uint8_t len; 154 | uint8_t val[0]; 155 | } __attribute__ ((packed)) l2cap_conf_opt; 156 | #define L2CAP_CONF_OPT_SIZE 2 157 | 158 | #define L2CAP_CONF_MTU 0x01 159 | #define L2CAP_CONF_FLUSH_TO 0x02 160 | #define L2CAP_CONF_QOS 0x03 161 | #define L2CAP_CONF_RFC 0x04 162 | #define L2CAP_CONF_FCS 0x05 163 | 164 | #define L2CAP_CONF_MAX_SIZE 22 165 | 166 | #define L2CAP_MODE_BASIC 0x00 167 | #define L2CAP_MODE_RETRANS 0x01 168 | #define L2CAP_MODE_FLOWCTL 0x02 169 | #define L2CAP_MODE_ERTM 0x03 170 | #define L2CAP_MODE_STREAMING 0x04 171 | 172 | typedef struct { 173 | uint16_t dcid; 174 | uint16_t scid; 175 | } __attribute__ ((packed)) l2cap_disconn_req; 176 | #define L2CAP_DISCONN_REQ_SIZE 4 177 | 178 | typedef struct { 179 | uint16_t dcid; 180 | uint16_t scid; 181 | } __attribute__ ((packed)) l2cap_disconn_rsp; 182 | #define L2CAP_DISCONN_RSP_SIZE 4 183 | 184 | typedef struct { 185 | uint16_t type; 186 | } __attribute__ ((packed)) l2cap_info_req; 187 | #define L2CAP_INFO_REQ_SIZE 2 188 | 189 | typedef struct { 190 | uint16_t type; 191 | uint16_t result; 192 | uint8_t data[0]; 193 | } __attribute__ ((packed)) l2cap_info_rsp; 194 | #define L2CAP_INFO_RSP_SIZE 4 195 | 196 | /* info type */ 197 | #define L2CAP_IT_CL_MTU 0x0001 198 | #define L2CAP_IT_FEAT_MASK 0x0002 199 | 200 | /* info result */ 201 | #define L2CAP_IR_SUCCESS 0x0000 202 | #define L2CAP_IR_NOTSUPP 0x0001 203 | 204 | #ifdef __cplusplus 205 | } 206 | #endif 207 | 208 | #endif /* __L2CAP_H */ 209 | -------------------------------------------------------------------------------- /contrib/bluetooth/rfcomm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2002-2003 Maxim Krasnyansky 6 | * Copyright (C) 2002-2010 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef __RFCOMM_H 26 | #define __RFCOMM_H 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #include 33 | 34 | /* RFCOMM defaults */ 35 | #define RFCOMM_DEFAULT_MTU 127 36 | 37 | #define RFCOMM_PSM 3 38 | 39 | /* RFCOMM socket address */ 40 | struct sockaddr_rc { 41 | sa_family_t rc_family; 42 | bdaddr_t rc_bdaddr; 43 | uint8_t rc_channel; 44 | }; 45 | 46 | /* RFCOMM socket options */ 47 | #define RFCOMM_CONNINFO 0x02 48 | struct rfcomm_conninfo { 49 | uint16_t hci_handle; 50 | uint8_t dev_class[3]; 51 | }; 52 | 53 | #define RFCOMM_LM 0x03 54 | #define RFCOMM_LM_MASTER 0x0001 55 | #define RFCOMM_LM_AUTH 0x0002 56 | #define RFCOMM_LM_ENCRYPT 0x0004 57 | #define RFCOMM_LM_TRUSTED 0x0008 58 | #define RFCOMM_LM_RELIABLE 0x0010 59 | #define RFCOMM_LM_SECURE 0x0020 60 | 61 | /* RFCOMM TTY support */ 62 | #define RFCOMM_MAX_DEV 256 63 | 64 | #define RFCOMMCREATEDEV _IOW('R', 200, int) 65 | #define RFCOMMRELEASEDEV _IOW('R', 201, int) 66 | #define RFCOMMGETDEVLIST _IOR('R', 210, int) 67 | #define RFCOMMGETDEVINFO _IOR('R', 211, int) 68 | 69 | struct rfcomm_dev_req { 70 | int16_t dev_id; 71 | uint32_t flags; 72 | bdaddr_t src; 73 | bdaddr_t dst; 74 | uint8_t channel; 75 | }; 76 | #define RFCOMM_REUSE_DLC 0 77 | #define RFCOMM_RELEASE_ONHUP 1 78 | #define RFCOMM_HANGUP_NOW 2 79 | #define RFCOMM_TTY_ATTACHED 3 80 | 81 | struct rfcomm_dev_info { 82 | int16_t id; 83 | uint32_t flags; 84 | uint16_t state; 85 | bdaddr_t src; 86 | bdaddr_t dst; 87 | uint8_t channel; 88 | }; 89 | 90 | struct rfcomm_dev_list_req { 91 | uint16_t dev_num; 92 | struct rfcomm_dev_info dev_info[0]; 93 | }; 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* __RFCOMM_H */ 100 | -------------------------------------------------------------------------------- /contrib/bluetooth/sco.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2002-2003 Maxim Krasnyansky 6 | * Copyright (C) 2002-2010 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef __SCO_H 26 | #define __SCO_H 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /* SCO defaults */ 33 | #define SCO_DEFAULT_MTU 500 34 | #define SCO_DEFAULT_FLUSH_TO 0xFFFF 35 | 36 | #define SCO_CONN_TIMEOUT (HZ * 40) 37 | #define SCO_DISCONN_TIMEOUT (HZ * 2) 38 | #define SCO_CONN_IDLE_TIMEOUT (HZ * 60) 39 | 40 | /* SCO socket address */ 41 | struct sockaddr_sco { 42 | sa_family_t sco_family; 43 | bdaddr_t sco_bdaddr; 44 | }; 45 | 46 | /* set/get sockopt defines */ 47 | #define SCO_OPTIONS 0x01 48 | struct sco_options { 49 | uint16_t mtu; 50 | }; 51 | 52 | #define SCO_CONNINFO 0x02 53 | struct sco_conninfo { 54 | uint16_t hci_handle; 55 | uint8_t dev_class[3]; 56 | }; 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* __SCO_H */ 63 | -------------------------------------------------------------------------------- /contrib/lms2012/ev3_analog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * EV3-API 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see Shared Memory 26 | * 27 | *
28 | * 29 | * 30 | * \verbatim 31 | */ 32 | 33 | #define COLORS 4 34 | #define CALPOINTS 3 35 | 36 | typedef struct 37 | { 38 | uint32_t Calibration[CALPOINTS][COLORS]; 39 | uint16_t CalLimits[CALPOINTS - 1]; 40 | uint16_t Crc; 41 | uint16_t ADRaw[COLORS]; 42 | uint16_t SensorRaw[COLORS]; 43 | } 44 | COLORSTRUCT; 45 | 46 | /*! \page AnalogModuleMemory 47 | * Shared Memory 48 | * 49 | *
50 | * 51 | * It is possible to get a pointer to the raw analogue values for use in userspace 52 | * this pointer will point to a struct and the layout is following: 53 | * 54 | * \verbatim 55 | */ 56 | 57 | typedef struct 58 | { 59 | DATA16 InPin1[INPUTS]; //!< Analog value at input port connection 1 60 | DATA16 InPin6[INPUTS]; //!< Analog value at input port connection 6 61 | DATA16 OutPin5[OUTPUTS]; //!< Analog value at output port connection 5 62 | DATA16 BatteryTemp; //!< Battery temperature 63 | DATA16 MotorCurrent; //!< Current flowing to motors 64 | DATA16 BatteryCurrent; //!< Current flowing from the battery 65 | DATA16 Cell123456; //!< Voltage at battery cell 1, 2, 3,4, 5, and 6 66 | #ifndef DISABLE_FAST_DATALOG_BUFFER 67 | DATA16 Pin1[INPUTS][DEVICE_LOGBUF_SIZE]; //!< Raw value from analog device 68 | DATA16 Pin6[INPUTS][DEVICE_LOGBUF_SIZE]; //!< Raw value from analog device 69 | uint16_t Actual[INPUTS]; 70 | uint16_t LogIn[INPUTS]; 71 | uint16_t LogOut[INPUTS]; 72 | #endif 73 | #ifndef DISABLE_OLD_COLOR 74 | COLORSTRUCT NxtCol[INPUTS]; 75 | #endif 76 | DATA16 OutPin5Low[OUTPUTS]; //!< Analog value at output port connection 5 when connection 6 is low 77 | 78 | DATA8 Updated[INPUTS]; 79 | 80 | DATA8 InDcm[INPUTS]; //!< Input port device types 81 | DATA8 InConn[INPUTS]; 82 | 83 | DATA8 OutDcm[OUTPUTS]; //!< Output port device types 84 | DATA8 OutConn[OUTPUTS]; 85 | #ifndef DISABLE_PREEMPTED_VM 86 | uint16_t PreemptMilliSeconds; 87 | #endif 88 | } 89 | ANALOG; 90 | 91 | #endif //EV3_ANALOG_H_ 92 | -------------------------------------------------------------------------------- /contrib/lms2012/ev3_basictypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * EV3-API 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see 22 | 23 | // Some basic data type defines 24 | #if 0 25 | typedef unsigned char UBYTE; //!< Basic Type used to symbolise 8 bit unsigned values 26 | typedef unsigned short uint16_t; //!< Basic Type used to symbolise 16 bit unsigned values 27 | typedef unsigned int uint32_t; //!< Basic Type used to symbolise 32 bit unsigned values 28 | typedef signed short int16_t; //!< Basic Type used to symbolise 16 bit signed values 29 | typedef signed char int8_t; //!< Basic Type used to symbolise 8 bit signed values 30 | #endif 31 | typedef int8_t DATA8; //!< VM Type for 1 byte signed value 32 | typedef int16_t DATA16; //!< VM Type for 2 byte signed value 33 | typedef float DATAF; //!< VM Type for 4 byte floating point value 34 | 35 | #endif //EV3_BASICTYPES_H_ 36 | -------------------------------------------------------------------------------- /contrib/lms2012/ev3_iic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 2 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see Shared Memory 25 | * 26 | *
27 | * 28 | * It is possible to get a pointer to the iic values for use in userspace 29 | * this pointer will point to a struct and the layout is following: 30 | * 31 | * \verbatim 32 | */ 33 | 34 | #define IIC_DATA_LENGTH MAX_DEVICE_DATALENGTH 35 | #define IIC_NAME_LENGTH 8 36 | 37 | typedef enum 38 | { 39 | OK = 0, //!< No errors to report 40 | BUSY = 1, //!< Busy - try again 41 | FAIL = 2, //!< Something failed 42 | STOP = 4 //!< Stopped 43 | } 44 | RESULT; 45 | typedef struct 46 | { 47 | TYPES TypeData[INPUTS][MAX_DEVICE_MODES]; //!< TypeData 48 | 49 | #ifndef DISABLE_FAST_DATALOG_BUFFER 50 | uint16_t Repeat[INPUTS][DEVICE_LOGBUF_SIZE]; 51 | DATA8 Raw[INPUTS][DEVICE_LOGBUF_SIZE][IIC_DATA_LENGTH]; //!< Raw value from IIC device 52 | uint16_t Actual[INPUTS]; 53 | uint16_t LogIn[INPUTS]; 54 | #else 55 | DATA8 Raw[INPUTS][IIC_DATA_LENGTH]; //!< Raw value from IIC device 56 | #endif 57 | DATA8 Status[INPUTS]; //!< Status 58 | DATA8 Changed[INPUTS]; 59 | DATA8 Output[INPUTS][IIC_DATA_LENGTH]; //!< Bytes to IIC device 60 | DATA8 OutputLength[INPUTS]; 61 | } 62 | IIC; 63 | 64 | typedef struct 65 | { 66 | RESULT Result; 67 | DATA8 Port; 68 | DATA8 Repeat; 69 | DATA16 Time; 70 | DATA8 WrLng; 71 | DATA8 WrData[IIC_DATA_LENGTH]; 72 | DATA8 RdLng; 73 | DATA8 RdData[IIC_DATA_LENGTH]; 74 | } 75 | IICDAT; 76 | 77 | 78 | 79 | #endif //EV3_IIC_H_ 80 | -------------------------------------------------------------------------------- /contrib/lms2012/ev3_uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 2 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see Shared Memory 30 | * 31 | *
32 | * 33 | * It is possible to get a pointer to the uart values for use in userspace 34 | * this pointer will point to a struct and the layout is following: 35 | * 36 | * \verbatim 37 | */ 38 | 39 | #define UART_DATA_LENGTH MAX_DEVICE_DATALENGTH 40 | #define UART_BUFFER_SIZE 64 41 | 42 | typedef struct 43 | { 44 | TYPES TypeData[INPUTS][MAX_DEVICE_MODES]; //!< TypeData 45 | 46 | #ifndef DISABLE_FAST_DATALOG_BUFFER 47 | uint16_t Repeat[INPUTS][DEVICE_LOGBUF_SIZE]; 48 | DATA8 Raw[INPUTS][DEVICE_LOGBUF_SIZE][UART_DATA_LENGTH]; //!< Raw value from UART device 49 | uint16_t Actual[INPUTS]; 50 | uint16_t LogIn[INPUTS]; 51 | #else 52 | DATA8 Raw[INPUTS][UART_DATA_LENGTH]; //!< Raw value from UART device 53 | #endif 54 | DATA8 Status[INPUTS]; //!< Status 55 | DATA8 Output[INPUTS][UART_DATA_LENGTH]; //!< Bytes to UART device 56 | DATA8 OutputLength[INPUTS]; 57 | } 58 | UART; 59 | 60 | typedef struct 61 | { 62 | TYPES TypeData; 63 | DATA8 Port; 64 | DATA8 Mode; 65 | } 66 | UARTCTL; 67 | 68 | #endif //EV3_UART_H_ 69 | -------------------------------------------------------------------------------- /examples/compatibility/ev3_color/ambient.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 color sensor. 9 | * The program reads the ambient light and prints the value on the screen. 10 | * 11 | * Stop the program by pressing the back/exit button of the robot. 12 | */ 13 | int main () { 14 | /** 15 | * Initialize EV3Color sensor connected at port 1 16 | */ 17 | InitEV3(); 18 | SetAllSensorMode(COL_AMBIENT, NO_SEN, NO_SEN, NO_SEN); 19 | 20 | while (!isExitButtonPressed()) { 21 | int ambient = ReadSensor(IN_1); 22 | 23 | LcdClean(); 24 | LcdTextf(1, 0, LcdRowToY(1), "Ambient: %d", ambient); 25 | Wait(100); 26 | } 27 | 28 | FreeEV3(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /examples/compatibility/ev3_color/color.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 color sensor. 9 | * The program reads the color and prints the value on the screen. 10 | * 11 | * Stop the program by pressing the back/exit button of the robot. 12 | */ 13 | int main () { 14 | /** 15 | * Initialize EV3Color sensor connected at port 1 16 | */ 17 | InitEV3(); 18 | SetAllSensorMode(COL_COLOR, NO_SEN, NO_SEN, NO_SEN); 19 | 20 | while (!isExitButtonPressed()) { 21 | int color = ReadSensor(IN_1); 22 | 23 | LcdClean(); 24 | LcdTextf(1, 0, LcdRowToY(1), "Color: %d", color); 25 | Wait(100); 26 | } 27 | 28 | FreeEV3(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /examples/compatibility/ev3_color/reflect.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 color sensor. 9 | * The program reads the reflected light and prints the value on the screen. 10 | * 11 | * Stop the program by pressing the back/exit button of the robot. 12 | */ 13 | int main () { 14 | /** 15 | * Initialize EV3Color sensor connected at port 1 16 | */ 17 | InitEV3(); 18 | SetAllSensorMode(COL_REFLECT, NO_SEN, NO_SEN, NO_SEN); 19 | 20 | while (!isExitButtonPressed()) { 21 | int reflected = ReadSensor(IN_1); 22 | 23 | LcdClean(); 24 | LcdTextf(1, 0, LcdRowToY(1), "Reflected: %d", reflected); 25 | Wait(100); 26 | } 27 | 28 | FreeEV3(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /examples/compatibility/ev3_color/rgb.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 color sensor. 9 | * The program reads the rgb color and prints the value on the screen. 10 | * 11 | * Stop the program by pressing the back/exit button of the robot. 12 | */ 13 | int main () { 14 | /** 15 | * Initialize EV3Color sensor connected at port 1 16 | */ 17 | InitEV3(); 18 | SetAllSensorMode(COL_COLOR_RGB, NO_SEN, NO_SEN, NO_SEN); 19 | 20 | while (!isExitButtonPressed()) { 21 | int rgb = ReadSensor(IN_1); 22 | 23 | LcdClean(); 24 | LcdTextf(1, 0, LcdRowToY(1), "R: %d\tG: %d\tB: %d", 25 | RGB_INT_GET_RED(rgb), 26 | RGB_INT_GET_GREEN(rgb), 27 | RGB_INT_GET_BLUE(rgb)); 28 | Wait(100); 29 | } 30 | 31 | FreeEV3(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /examples/compatibility/ev3_gyro/angle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | bool isCenterButtonPressed() { 8 | return ButtonIsDown(BTNCENTER); 9 | } 10 | 11 | /** 12 | * Example program that uses the EV3 gyro sensor. 13 | * The program reads the angle and shows it on the screen every 100ms. 14 | * Press the center button to reset the angle (please, keep the robot still 15 | * while resetting, to avoid the common drifting problem). 16 | * Stop the program by pressing the back/exit button of the robot. 17 | */ 18 | int main () { 19 | /** 20 | * Initialize EV3Gyro sensor connected at port 1 21 | */ 22 | InitEV3(); 23 | SetAllSensorMode(GYRO_ANG, NO_SEN, NO_SEN, NO_SEN); 24 | 25 | while (!isExitButtonPressed()) { 26 | int angle = ReadSensor(IN_1); 27 | 28 | LcdClean(); 29 | LcdTextf(1, 0, LcdRowToY(1), "Angle: %d", angle); 30 | Wait(100); 31 | 32 | if (isCenterButtonPressed()) { 33 | LcdClean(); 34 | LcdTextf(1, 0, 8, "Resetting gyro sensor ..."); 35 | Wait(1000); 36 | ResetEV3GyroSensor(IN_1, EV3GyroSoftwareOffset); 37 | } 38 | } 39 | 40 | FreeEV3(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /examples/compatibility/ev3_gyro/rate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 gyro sensor. 9 | * The program reads the rate and shows it on the screen every 100ms. 10 | * Stop the program by pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize EV3Gyro sensor connected at port 1 15 | */ 16 | InitEV3(); 17 | SetAllSensorMode(GYRO_RATE, NO_SEN, NO_SEN, NO_SEN); 18 | 19 | while (!isExitButtonPressed()) { 20 | int angle = ReadSensor(IN_1); 21 | 22 | LcdClean(); 23 | LcdTextf(1, 0, LcdRowToY(1), "Rate: %d", angle); 24 | Wait(100); 25 | } 26 | 27 | FreeEV3(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /examples/compatibility/ev3_touch.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 touch sensor. 9 | * The program checks every 100ms if a touch sensor connected to port 1 is pressed 10 | * and write if it is pressed on the screen. Stop the program by pressing the back/exit 11 | * button of the robot. 12 | */ 13 | int main () { 14 | /** 15 | * Initialize EV3Touch sensor connected at port 1 16 | */ 17 | InitEV3(); 18 | SetAllSensorMode(TOUCH_PRESS, NO_SEN, NO_SEN, NO_SEN); 19 | 20 | while (!isExitButtonPressed()) { 21 | 22 | /** 23 | * Read if the button is pressed (true) or not (false) 24 | */ 25 | int touchSensor = ReadSensor(IN_1); 26 | 27 | LcdClean(); 28 | if (touchSensor) { 29 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Button is pressed"); 30 | } else { 31 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Button is not pressed"); 32 | } 33 | Wait(100); 34 | } 35 | 36 | FreeEV3(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /examples/compatibility/ev3_ultrasonic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 ultrasonic sensor. 9 | * The program checks every 100ms the distance. 10 | * Stop the program by pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize EV3 ultrasonic sensor connected at port 1 15 | */ 16 | InitEV3(); 17 | SetAllSensorMode(US_DIST_CM, NO_SEN, NO_SEN, NO_SEN); 18 | 19 | while (!isExitButtonPressed()) { 20 | LcdClean(); 21 | 22 | int distance = ReadSensor(IN_1); 23 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Distance: %d cm", distance); 24 | Wait(100); 25 | } 26 | 27 | FreeEV3(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /examples/ev3_color.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 color sensor. 9 | * The program reads the color, RGB values, reflected and ambient light and prints 10 | * the values on the screen. 11 | * 12 | * The sensor automatically change its mode according to the reading function/parameters- 13 | * When the sensor changes its mode, the program automatically waits 200ms. 14 | * 15 | * Stop the program by pressing the back/exit button of the robot. 16 | */ 17 | int main () { 18 | /** 19 | * Initialize EV3Color sensor connected at port 1 20 | */ 21 | InitEV3(); 22 | SetAllSensors(EV3Color, NULL, NULL, NULL); 23 | 24 | while (!isExitButtonPressed()) { 25 | 26 | Color color = ReadEV3ColorSensorColor(IN_1); 27 | 28 | RGB rgb; 29 | int res = ReadEV3ColorSensorColorRGB(IN_1, &rgb); 30 | 31 | int reflectedLight = ReadEV3ColorSensorReflectedLight(IN_1); 32 | 33 | int ambientLight = ReadEV3ColorSensorAmbientLight(IN_1); 34 | 35 | 36 | LcdClean(); 37 | LcdTextf(1, 0, LcdRowToY(1), "Color: %d", color); 38 | LcdTextf(1, 0, LcdRowToY(2), "R: %d\tG: %d\tB: %d", rgb.red, rgb.green, rgb.blue); 39 | LcdTextf(1, 0, LcdRowToY(3), "Reflected: %d", reflectedLight); 40 | LcdTextf(1, 0, LcdRowToY(4), "Ambient: %d", ambientLight); 41 | Wait(100); 42 | } 43 | 44 | FreeEV3(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /examples/ev3_gyro.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | bool isCenterButtonPressed() { 8 | return ButtonIsDown(BTNCENTER); 9 | } 10 | 11 | /** 12 | * Example program that uses the EV3 gyro sensor. 13 | * The program reads the angle and the rotation rate and shows them on the 14 | * screen every 100ms. 15 | * 16 | * Press the center button to reset the angle (please, keep the robot still 17 | * while resetting, to avoid the common drifting problem). 18 | * 19 | * Stop the program by pressing the back/exit button of the robot. 20 | */ 21 | int main () { 22 | /** 23 | * Initialize EV3Gyro sensor connected at port 1 24 | */ 25 | InitEV3(); 26 | SetAllSensors(EV3Gyro, NULL, NULL, NULL); 27 | 28 | while (!isExitButtonPressed()) { 29 | int angle = ReadEV3GyroSensorAngle(IN_1, EV3GyroInterleavedAngle); 30 | int rate = ReadEV3GyroSensorRate(IN_1, EV3GyroInterleavedRate); 31 | 32 | LcdClean(); 33 | LcdTextf(1, 0, LcdRowToY(1), "Angle: %d", angle); 34 | LcdTextf(1, 0, LcdRowToY(1), "Rate: %d", rate); 35 | 36 | Wait(100); 37 | 38 | if (isCenterButtonPressed()) { 39 | LcdClean(); 40 | LcdTextf(1, 0, 8, "Resetting gyro sensor ..."); 41 | Wait(1000); 42 | ResetEV3GyroSensor(IN_1, EV3GyroSoftwareOffset); 43 | } 44 | } 45 | 46 | FreeEV3(); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /examples/ev3_ir/proximity.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 IR sensor. 9 | * The program checks every 100ms the proximity. 10 | * Stop the program by pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize EV3Ir sensor connected at port 1 15 | */ 16 | InitEV3(); 17 | SetAllSensors(EV3Ir, NULL, NULL, NULL); 18 | 19 | while (!isExitButtonPressed()) { 20 | LcdClean(); 21 | 22 | int proximity = ReadEV3IrSensorProximity(IN_1); 23 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Proximity: %d cm", proximity); 24 | 25 | Wait(100); 26 | } 27 | 28 | FreeEV3(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /examples/ev3_ir/remote.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | const char* getBeaconButtonName (int beaconButton) { 8 | switch (beaconButton) { 9 | case BEACON_OFF: 10 | return "Off"; 11 | case BEACON_UP_LEFT: 12 | return "Up Left"; 13 | case BEACON_DOWN_LEFT: 14 | return "Down Left"; 15 | case BEACON_UP_RIGHT: 16 | return "Up Right"; 17 | case BEACON_DOWN_RIGHT: 18 | return "Down Right"; 19 | case BEACON_UP: 20 | return "Both Up"; 21 | case BEACON_DIAG_UP_LEFT: 22 | return "Down Right + Up Left"; 23 | case BEACON_DIAG_UP_RIGHT: 24 | return "Down Left + Up Right"; 25 | case BEACON_DOWN: 26 | return "Both Down"; 27 | case BEACON_ON: 28 | return "On"; 29 | case BEACON_LEFT: 30 | return "Both Left"; 31 | case BEACON_RIGHT: 32 | return "Both Right"; 33 | default: 34 | return "None"; 35 | } 36 | } 37 | 38 | /** 39 | * Example program that uses the EV3 IR sensor. 40 | * The program checks every 100ms if and which EV3 beacon button is pressed. 41 | * Stop the program by pressing the back/exit button of the robot. 42 | */ 43 | int main () { 44 | /** 45 | * Initialize EV3Ir sensor connected at port 1 46 | */ 47 | InitEV3(); 48 | SetAllSensors(EV3Ir, NULL, NULL, NULL); 49 | 50 | while (!isExitButtonPressed()) { 51 | LcdClean(); 52 | 53 | // read pressed button of beacon transmitting on channel 1 54 | int beaconButton = ReadEV3IrSensorRemote(IN_1, BEACON_CH_1); 55 | const char* buttonName = getBeaconButtonName(beaconButton); 56 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Beacon button: %s", buttonName); 57 | 58 | Wait(100); 59 | } 60 | 61 | FreeEV3(); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /examples/ev3_ir/seek.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 IR sensor. 9 | * The program checks every 100ms the presence of a beacon and its position. 10 | * Stop the program by pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize EV3Ir sensor connected at port 1 15 | */ 16 | InitEV3(); 17 | SetAllSensors(EV3Ir, NULL, NULL, NULL); 18 | 19 | while (!isExitButtonPressed()) { 20 | LcdClean(); 21 | 22 | EV3IrSeekResult result = ReadEV3IrSensorSeek(IN_1); 23 | 24 | int i; 25 | for (i = 0; i < EV3_IR_CHANNELS; i++) { 26 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(i + 1), "CH %d: %d %d cm", (i + 1), result.directions[i], result.distances[i]); 27 | } 28 | 29 | Wait(100); 30 | } 31 | 32 | FreeEV3(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /examples/ev3_touch.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 touch sensor. 9 | * The program checks every 100ms if a touch sensor connected to port 1 is pressed 10 | * and write if it is pressed on the screen. Stop the program by pressing the back/exit 11 | * button of the robot. 12 | */ 13 | int main () { 14 | /** 15 | * Initialize EV3Touch sensor connected at port 1 16 | */ 17 | InitEV3(); 18 | SetAllSensors(EV3Touch, NULL, NULL, NULL); 19 | 20 | while (!isExitButtonPressed()) { 21 | 22 | /** 23 | * Read if the button is pressed (true) or not (false) 24 | */ 25 | bool touchSensor = ReadEV3TouchSensor(IN_1); 26 | 27 | LcdClean(); 28 | if (touchSensor) { 29 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Button is pressed"); 30 | } else { 31 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Button is not pressed"); 32 | } 33 | Wait(100); 34 | } 35 | 36 | FreeEV3(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /examples/ev3_ultrasonic/distance.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 ultrasonic sensor. 9 | * The program checks every 100ms the distance. 10 | * Stop the program by pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize EV3 ultrasonic sensor connected at port 1 15 | */ 16 | InitEV3(); 17 | SetAllSensors(EV3Ultrasonic, NULL, NULL, NULL); 18 | 19 | while (!isExitButtonPressed()) { 20 | LcdClean(); 21 | 22 | int distance = ReadEV3UltrasonicSensorDistance(IN_1, EV3_ULTRASONIC_CM); 23 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Distance: %d cm", distance); 24 | Wait(100); 25 | } 26 | 27 | FreeEV3(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /examples/ev3_ultrasonic/presence.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the EV3 ultrasonic sensor. 9 | * The program checks every 100ms the presence of another ultrasonic sensor. 10 | * Stop the program by pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize EV3 ultrasonic sensor connected at port 1 15 | */ 16 | InitEV3(); 17 | SetAllSensors(EV3Ultrasonic, NULL, NULL, NULL); 18 | 19 | while (!isExitButtonPressed()) { 20 | LcdClean(); 21 | 22 | bool presence = ReadEV3UltrasonicSensorListen(IN_1); 23 | if (presence) { 24 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Presence of another sensor"); 25 | } else { 26 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "No other sensors"); 27 | } 28 | Wait(100); 29 | } 30 | 31 | FreeEV3(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /examples/ht_color/color.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the HiTechnic Color Sensor V2. 9 | * The program prints the color code every 200ms. 10 | * Stop the program by pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize EV3Color sensor connected at port 1 for a country that uses 60Hz mains power 15 | */ 16 | InitEV3(); 17 | SetAllSensors(HTColorV2, NULL, NULL, NULL); 18 | SetHTColorV2PowerMainsFrequency(IN_1, PowerMains60Hz); 19 | 20 | while (!isExitButtonPressed()) { 21 | int color = ReadHTColorSensorV2(IN_1); 22 | 23 | LcdClean(); 24 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Color: %d", color); 25 | Wait(200); 26 | } 27 | 28 | FreeEV3(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /examples/ht_color/rgb.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the HiTechnic Color Sensor V2. 9 | * The program prints the rgb values every 200ms. 10 | * Stop the program by pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize EV3Color sensor connected at port 1 for a country that uses 60Hz mains power 15 | */ 16 | InitEV3(); 17 | SetAllSensors(HTColorV2, NULL, NULL, NULL); 18 | SetHTColorV2PowerMainsFrequency(IN_1, PowerMains60Hz); 19 | 20 | while (!isExitButtonPressed()) { 21 | RGBA rgba; 22 | 23 | ReadHTColorSensorV2RGBA(IN_1, HTColorSensorDefaultMode, &rgba); 24 | //ReadHTColorSensorV2RGBA(IN_1, HTColorSensorPassiveMode, &rgba); 25 | //ReadHTColorSensorV2RGBA(IN_1, HTColorSensorRawMode, &rgba); 26 | 27 | LcdClean(); 28 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "W:\tR: %d\tG: %d\tB: %d", rgba.white, rgba.red, rgba.green, rgba.blue); 29 | Wait(500); 30 | } 31 | 32 | FreeEV3(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /examples/ht_compass.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | bool isCenterButtonPressed() { 8 | return ButtonIsDown(BTNCENTER); 9 | } 10 | 11 | /** 12 | * Example program that uses the HiTechnic Compass Sensor. 13 | * The program prints the angle of the compass sensor. 14 | * 15 | * Press the center button to calibrate the sensor. Once the calibration is started, 16 | * you should rotate very slowly the sensor, taking at least 20 seconds per rotation. 17 | * You should make 1.5 to 2 full rotations. After you completed the calibration, 18 | * press the center button again. 19 | * 20 | * Stop the program by pressing the back/exit button of the robot. 21 | */ 22 | int main () { 23 | /** 24 | * Initialize EV3Color sensor connected at port 1 for a country that uses 60Hz mains power 25 | */ 26 | InitEV3(); 27 | SetAllSensors(HTCompass, NULL, NULL, NULL); 28 | 29 | while (!isExitButtonPressed()) { 30 | int angle = ReadHTCompassSensor(IN_1, HTCompassAngle); 31 | 32 | LcdClean(); 33 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Angle: %d", angle); 34 | 35 | if (isCenterButtonPressed()) { 36 | LcdClean(); 37 | LcdTextf(1, 0, 8, "Start calibration"); 38 | Wait(1000); 39 | StartHTCompassCalibration(IN_1); 40 | while(!isCenterButtonPressed()) { 41 | Wait(100); 42 | } 43 | StopHTCompassCalibration(IN_1); 44 | LcdClean(); 45 | LcdTextf(1, 0, 8, "Done"); 46 | Wait(1000); 47 | } 48 | } 49 | 50 | FreeEV3(); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /examples/ht_ir.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the HiTechnic IR Sensor. 9 | * The program checks every 100ms the direction of a beacon. 10 | * Stop the program by pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize HT Ir sensor connected at port 1 15 | */ 16 | InitEV3(); 17 | SetAllSensors(HTIrV2, NULL, NULL, NULL); 18 | 19 | while (!isExitButtonPressed()) { 20 | 21 | /** 22 | * Read the direction of a beacon transmitting modulated ir signal (AC) 23 | */ 24 | int direction = ReadHTIrV2Sensor(IN_1, Modulated); 25 | 26 | LcdClean(); 27 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Direction: %d", direction); 28 | Wait(100); 29 | } 30 | 31 | FreeEV3(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /examples/nxt_sound.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the NXT sound sensor. 9 | * The programs check every 100ms the sound level and prints it to the screen. 10 | * Stop the program pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize NXTSound sensor connected at port 1 15 | */ 16 | InitEV3(); 17 | SetAllSensors(NXTSound, NULL, NULL, NULL); 18 | 19 | while (!isExitButtonPressed()) { 20 | LcdClean(); 21 | 22 | int sound = ReadNXTSoundSensor(IN_1, NXT_SOUND_DB); 23 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Sound: %d", sound); 24 | 25 | Wait(100); 26 | } 27 | 28 | FreeEV3(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /examples/nxt_temperature.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the NXT temperature sensor. 9 | * The programs check every 100ms the temperature and prints it to the screen. 10 | * Stop the program pressing the back/exit button of the robot. 11 | */ 12 | int main () { 13 | /** 14 | * Initialize NXTTemperature sensor connected at port 1 15 | */ 16 | InitEV3(); 17 | SetAllSensors(NXTTemperature, NULL, NULL, NULL); 18 | 19 | while (!isExitButtonPressed()) { 20 | int c = ReadNXTTemperatureSensor(IN_1, NXT_TEMPERATURE_C); 21 | int f = ReadNXTTemperatureSensor(IN_1, NXT_TEMPERATURE_F); 22 | 23 | LcdClean(); 24 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "C: %d", c); 25 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(2), "F: %d", f); 26 | Wait(100); 27 | } 28 | 29 | FreeEV3(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /examples/pixy_cam.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isExitButtonPressed() { 4 | return ButtonIsDown(BTNEXIT); 5 | } 6 | 7 | /** 8 | * Example program that uses the Pixy Cam 1 sensor. 9 | * The program prints every 100ms the biggest blob found. To use this program you first 10 | * need to select a blob connecting the PixyCam to a computer. 11 | * Stop the program by pressing the back/exit button of the robot. 12 | */ 13 | int main () { 14 | /** 15 | * Initialize PixyCam sensor connected at port 1 16 | */ 17 | InitEV3(); 18 | SetAllSensors(PixyCam, NULL, NULL, NULL); 19 | 20 | while (!isExitButtonPressed()) { 21 | PixyRectangle blob; 22 | ReadPixyCamSensorBiggestBlobRectangle(IN_1, &blob); 23 | 24 | LcdClean(); 25 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(1), "Signature: %d", blob.signature); 26 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(2), "X: %d\tY: %d", blob.x, blob.y); 27 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(3), "Width: %d\tHeight: %d", blob.width, blob.height); 28 | LcdTextf(LCD_COLOR_BLACK, 0, LcdRowToY(4), "Angle: %d", blob.angle); 29 | Wait(100); 30 | } 31 | 32 | FreeEV3(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /include/ev3.h: -------------------------------------------------------------------------------- 1 | /** \file ev3.h 2 | * \brief Initialisation for all working EV3 functions (sensors, lcd, motors, buttons) 3 | * 4 | * ev3.h contains declarations for the EV3 C API Initialisationfunctions. 5 | * 6 | * License: 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "ev3_constants.h" 47 | #include "ev3_command.h" 48 | #include "ev3_output.h" 49 | #include "ev3_sensors/ev3_sensors.h" 50 | #include "ev3_button.h" 51 | #include "ev3_lcd.h" 52 | #include "ev3_sound.h" 53 | #include "ev3_bluetooth.h" 54 | #include "ev3_array.h" 55 | #include "ev3_timer.h" 56 | 57 | // Priority of the InitEV3/FreeEV3 functions for automatic construction and destruction 58 | // see https://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Function-Attributes.html 59 | // see https://stackoverflow.com/a/24361145 60 | // - 0-100 is reserved for the compiler 61 | // - 101-200 is left for the user 62 | #define EV3_CONSTRUCTOR_PRIORITY 201 63 | #define EV3_DESTRUCTOR_PRIORITY 201 64 | 65 | int InitEV3(void); 66 | int FreeEV3(void); 67 | bool EV3IsInitialized(void); 68 | 69 | /* 70 | * Compatibility alias definitions 71 | */ 72 | 73 | /*! 74 | * @deprecated 75 | */ 76 | #define CloseEV3() FreeEV3() 77 | 78 | /*! 79 | * @deprecated 80 | */ 81 | #define ExitEV3() FreeEV3() 82 | 83 | /* Students are lazy, so lets have the intialization happen automatically for them. 84 | * This code is usually linked in as a static library and the linker will throw 85 | * the InitEV3 function out if no one wants it, so lets reference it manually 86 | * and have GCC warn if a user accesses it. 87 | */ 88 | 89 | #ifndef EV3_NO_CONSTRUCTORS 90 | static int __attribute__((used,deprecated)) (* volatile __reference_InitEV3)(void) = InitEV3; 91 | static int __attribute__((used,deprecated)) (* volatile __reference_FreeEV3)(void) = FreeEV3; 92 | #endif 93 | 94 | #endif // ev3_h 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | -------------------------------------------------------------------------------- /include/ev3_bluetooth.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #ifndef ev3_bluetooth_h 6 | #define ev3_bluetooth_h 7 | 8 | #define BLUETOOTH_ADDRESS_LENGTH sizeof("00:00:00:00:00:00") 9 | #define MAX_BLUETOOTH_NAME_LENGTH 128 10 | 11 | void BluetoothInit(void); 12 | 13 | typedef int BluetoothConnectionHandle; 14 | 15 | /** 16 | * Connect to the remote device given his bluetooth name or address. 17 | * If the connection can't be established, a new attempt will be tried after 1 18 | * second. 19 | * @param nameOrAddress 20 | * @param attempts maximum number of attempts. This argument should be >= 1, 21 | * otherwise no attempt will be tried (and the connection will never be 22 | * established) 23 | * @return Connection handle or -1 if wasn't possible to find the address given the device name 24 | */ 25 | BluetoothConnectionHandle ConnectTo(const char * nameOrAddress, int attempts); 26 | 27 | /** 28 | * Wait for an incoming bluetooth connection from another device 29 | * @return Connection handle or -1 if there was an error while waiting for the connection 30 | */ 31 | BluetoothConnectionHandle WaitConnection(void); 32 | 33 | /** 34 | * Sends a string to the remote device. 35 | * The string is sent without the null terminator, since ReceiveStringFrom will 36 | * add it once it's received. 37 | * @param to handle of the connection to use to send the string 38 | * @param str null-terminated string to send 39 | * @return number of bytes sent or -1 if there was an error. It may happen that 40 | * the number of sent bytes is smaller than the length of the string. 41 | */ 42 | int SendStringTo(BluetoothConnectionHandle to, const char * str); 43 | 44 | /** 45 | * Receives a string from a connection, copying it into the buffer. The buffer 46 | * will be null-terminated. 47 | * @param from connection to use to receive the string 48 | * @param buffer buffer where to write the null-terminated received string 49 | * @param bufferLength length of the buffer (max length of the string) 50 | * @return number of bytes received or -1 if there was an error 51 | */ 52 | int ReceiveStringFrom(BluetoothConnectionHandle from, char * buffer, int bufferLength); 53 | 54 | void DisconnectFrom(BluetoothConnectionHandle from); 55 | 56 | void BluetoothExit(void); 57 | 58 | #endif // ev3_bluetooth_h 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | -------------------------------------------------------------------------------- /include/ev3_button.core.h: -------------------------------------------------------------------------------- 1 | /** \file ev3_button.core.h 2 | * \brief Low level abstractions for driving EV3 buttons & LEDs. 3 | * 4 | * License: 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see 42 | 43 | /*! 44 | * \brief Initialize the button kernel interface. 45 | * \return Whether the initialization succeeded or not. 46 | */ 47 | bool ButtonCoreInit(void); 48 | 49 | /*! 50 | * \brief Deinitialize the button kernel interface. 51 | * \return Whether the deinitialization succeeded or not. 52 | */ 53 | bool ButtonCoreExit(void); 54 | 55 | /*! 56 | * \brief Check if the kernel button interface is initialized. 57 | * \return Whether the module is initialized or not. 58 | */ 59 | bool ButtonCoreInitialized(void); 60 | 61 | /*! 62 | * \brief Read the brick hardware revision from the kernel. 63 | * \return String received from the kernel. 64 | */ 65 | const char *ButtonCoreReadHWRev(void); 66 | 67 | /*! 68 | * \brief Write the specified LED pattern to kernel. 69 | * \param pattern Pattern to set. 70 | * \return Whether the operation succeeded or not. 71 | */ 72 | bool ButtonCoreSetLEDs(LEDPattern pattern); 73 | 74 | /*! 75 | * \brief Read button states from the kernel. 76 | * \param buttonStates Where to save the press states. 77 | * This is an array containing 6 bytes, each having either value 0 (b. released) or 1 (b. pressed). 78 | * The button indices correspond to BUTTON_IDX_* constants. 79 | * \return Whether the operation succeeded or not. 80 | */ 81 | bool ButtonCoreReadButtons(uint8_t *buttonStates); 82 | 83 | /*! 84 | * \brief Read a state of one button from the kernel. 85 | * \param button Button to check. 86 | * \return 1 if the button is pressed, 0 if not, -1 if an error occured. 87 | */ 88 | int ButtonCoreReadButton(Button button); 89 | 90 | #endif // ev3_button_core_h 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | -------------------------------------------------------------------------------- /include/ev3_button.h: -------------------------------------------------------------------------------- 1 | /** \file ev3_button.h 2 | * \brief Functions and constants for controlling EV3 buttons and LEDs 3 | * 4 | * ev3_button.h contains declarations for the EV3 C API button and LED functions. 5 | * 6 | * License: 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see 39 | 40 | /*! 41 | * \brief Initialize the LED interface. 42 | * \return Whether the initialization succeeded or not. 43 | */ 44 | bool LedInit(void); 45 | 46 | /*! 47 | * \brief Deinitialize the LED interface. 48 | * \return Whether the deinitialization succeeded or not. 49 | */ 50 | bool LedExit(void); 51 | 52 | /*! 53 | * \brief Check whether the LED interface is initialized. 54 | * \return Whether the module is initialized or not. 55 | */ 56 | bool LedInitialized(void); 57 | 58 | /*! 59 | * \brief Check whether a warning mode (LEDs always orange) is currently activated. 60 | * \return True if a warning light is activated, false otherwise. 61 | */ 62 | bool LedWarning(); 63 | 64 | /*! 65 | * \brief Set new warning mode state (LEDs always orange). 66 | * \param Value True to activate always-orange LEDs, false otherwise. 67 | */ 68 | bool SetLedWarning(bool Value); 69 | 70 | /*! 71 | * \brief Check the current LED pattern (color & blink mode). 72 | * \return Current LED pattern value. 73 | * \sa LEDPattern 74 | */ 75 | LEDPattern LedPattern(); 76 | 77 | /*! 78 | * \brief Set new LED pattern (color & blink mode). 79 | * \param newPattern New pattern to set. 80 | * \sa LEDPattern 81 | */ 82 | bool SetLedPattern(LEDPattern newPattern); 83 | 84 | #endif // ev3_button_led_h 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | -------------------------------------------------------------------------------- /include/ev3_button.lejos.h: -------------------------------------------------------------------------------- 1 | /** \file ev3_button.lejos.h 2 | * \brief leJOS-like API for accessing brick buttons. 3 | * 4 | * License: 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see 39 | 40 | //////////////////////////////////////////////////////////////////////////////// 41 | // MACROS 42 | 43 | //! shift bits in order to make leJOS released button bitmask 44 | #define EVENT_MASK_MAKE_RELEASED(mask) ((unsigned int)(mask) << 8u) 45 | 46 | //! shift bits in order to make leJOS pressed button bitmask 47 | #define EVENT_MASK_MAKE_PRESSED(mask) ((unsigned int)(mask) << 0u) 48 | 49 | //! shift bits in order to make leJOS complete button bitmask 50 | #define EVENT_MASK_MAKE(pressed, released) (EVENT_MASK_MAKE_PRESSED(pressed) | \ 51 | EVENT_MASK_MAKE_RELEASED(released)) 52 | 53 | //! shift bits in order to get released button bitmask 54 | #define EVENT_MASK_GET_RELEASED(mask) (((mask) >> 8u) & 0xFF) 55 | 56 | //! shift bits in order to get pressed button bitmask 57 | #define EVENT_MASK_GET_PRESSED(mask) (((mask) >> 0u) & 0xFF) 58 | 59 | //! check if a given bitmask contains 60 | #define BUTTON_MASK_CONTAINS(mask, button) ((BUTTON_MASK_OF(button) & (mask)) != 0) 61 | 62 | //! generate bitmask of a button id 63 | #define BUTTON_MASK_OF(button) (1u << (button)) 64 | 65 | //////////////////////////////////////////////////////////////////////////////// 66 | // PUBLIC DECLARATIONS 67 | 68 | /*! 69 | * \brief Check whether the given button is currently released. 70 | * \param Button Button to check. 71 | * \return True if the button is released, false otherwise. 72 | */ 73 | bool ButtonIsUp(Button Button); 74 | 75 | /*! 76 | * \brief Check whether the given button is currently pressed. 77 | * \param Button Button to check. 78 | * \return True if the button is pressed, false otherwise. 79 | */ 80 | bool ButtonIsDown(Button Button); 81 | 82 | /*! 83 | * \brief Wait for the given button to be pressed. 84 | * 85 | * The function will return once a transition from the released to the pressed state occurs. 86 | * 87 | * \param btn Button to wait for. 88 | * \return Whether the operation succeeded or not. 89 | */ 90 | bool ButtonWaitForPress(Button btn); 91 | 92 | /*! 93 | * \brief Wait for the given button to be pressed and then released (rtansition from rele). 94 | * 95 | * The function will return once a transition from the released to the pressed state and back occurs. 96 | * 97 | * \param btn Button to wait for. 98 | * \return Whether the operation succeeded or not. 99 | */ 100 | bool ButtonWaitForPressAndRelease(Button btn); 101 | 102 | /*! 103 | * \brief Wait for any button press to happen. 104 | * \param timeout Maximum wait duration in milliseconds. 105 | * \return ButtonMask bitmask of pressed buttons. 106 | * \sa ButtonMask 107 | */ 108 | unsigned int ButtonWaitForAnyPress(unsigned int timeout); 109 | 110 | /*! 111 | * \brief Wait for any button press or release to happen. 112 | * \param timeout Maximum wait duration in milliseconds. 113 | * \return ButtonMask of pressed buttons in bits 0-7, 114 | * ButtonMask of released buttons in bits 15-8. 115 | */ 116 | unsigned int ButtonWaitForAnyEvent(unsigned int timeout); 117 | 118 | #endif // ev3_button_lejos_h 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | -------------------------------------------------------------------------------- /include/ev3_command.h: -------------------------------------------------------------------------------- 1 | /** \file ev3_command.h 2 | * \brief Functions and constants for controlling misc EV3 items 3 | * 4 | * ev3_command.h contains declarations for the EV3 C API command functions. 5 | * 6 | * License: 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see 40 | #include 41 | #include 42 | #include 43 | 44 | #include "ev3_constants.h" 45 | 46 | void Wait(unsigned long ms); 47 | 48 | #endif // ev3_command_h 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | -------------------------------------------------------------------------------- /include/ev3_sensors/c4ev3_compatibility.h: -------------------------------------------------------------------------------- 1 | /** \file back_compatibility.h 2 | * \brief Back-compatible functions to read sensors like in the original c4ev3 3 | * 4 | */ 5 | 6 | #ifndef EV3_API_BACK_COMPATIBILITY_H 7 | #define EV3_API_BACK_COMPATIBILITY_H 8 | 9 | // Sensor Names 10 | #include "ev3_sensors.h" 11 | 12 | #define NO_SEN -1 // No sensor connected 13 | // Touchsenor 14 | #define TOUCH_PRESS 1 // Press 15 | 16 | // Light sensor 17 | #define COL_REFLECT 2 // Reflect 18 | #define COL_AMBIENT 3 // Ambient 19 | #define COL_COLOR 4 // Color 20 | #define COL_COLOR_RGB 23 // "Raw" Color in RGB 21 | 22 | #define RGB_INT_GET_RED(x) (((x) >> 16) & 0xFF) 23 | #define RGB_INT_GET_GREEN(x) (((x) >> 8) & 0xFF) 24 | #define RGB_INT_GET_BLUE(x) (((x) >> 0) & 0xFF) 25 | 26 | // Ultrasonic 27 | #define US_DIST_CM 5 // Dist in cm 28 | #define US_DIST_MM 6 // Dist in mm 29 | #define US_DIST_IN 7 // Dist in inch 30 | 31 | // Gyroskop 32 | #define GYRO_ANG 8 // angle 33 | #define GYRO_RATE 9 // rate 34 | 35 | // Infrared 36 | #define IR_PROX 10 // Proximity 37 | #define IR_SEEK 11 // Seek 38 | #define IR_REMOTE 12 // Remote Control 39 | 40 | // NXT 41 | #define NXT_TEMP_C 21 // Temperature in C 42 | #define NXT_TEMP_F 22 // Temperature in F 43 | 44 | // HiTechnic IR Seeker V2 Sensor 45 | #define HT_DIR_DC 30 46 | #define HT_DIR_AC 31 47 | #define HT_DIR_DALL 32 48 | #define HT_DIR_AALL 33 49 | 50 | // HiTechnic Compass Sensor 51 | #define HT_COMP 34 52 | 53 | /** 54 | * Initializes the sensors. This function may be called only once at the beginning. 55 | * If one sensor initialization fails, the previous initialized sensors are 56 | * de-initialized and -1 is returned. 57 | * @param name_1 58 | * @param name_2 59 | * @param name_3 60 | * @param name_4 61 | * @return -1 in case of error 62 | */ 63 | int SetAllSensorMode(int name_1, int name_2, int name_3, int name_4); 64 | 65 | /** 66 | * Read value from the sensor connected to the specified port 67 | * @param sensorPort port to which the sensor is connected 68 | * @return value from the sensor. The range of value changes depending on the 69 | * type of sensor 70 | */ 71 | int ReadSensor(int sensorPort); 72 | 73 | /** 74 | * Set which channel of the ev3 IR sensor you want to read. Once you've set the 75 | * desidered channel, use ReadSensor to get the value 76 | * @param sensorPort port to which the sensor is connected 77 | * @param channel channel you want to read 78 | * @return 0 79 | */ 80 | int SetIRBeaconCH(int sensorPort, int channel); 81 | 82 | #endif //EV3_API_BACK_COMPATIBILITY_H 83 | -------------------------------------------------------------------------------- /include/ev3_sensors/ev3_ir.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_IR_H 2 | #define EV3_API_EV3_IR_H 3 | 4 | #include "ev3_sensors.h" 5 | 6 | #define EV3_IR_CHANNELS 4 7 | 8 | #define EV3_IR_SENSOR_TYPE 33 9 | 10 | #define EV3_IR_SENSOR_PROXIMITY_MODE 0 11 | #define EV3_IR_SENSOR_SEEK_MODE 1 12 | #define EV3_IR_SENSOR_REMOTE_MODE 2 13 | #define EV3_IR_SENSOR_DEFAULT_MODE EV3_IR_SENSOR_PROXIMITY_MODE 14 | 15 | 16 | #define BEACON_CH_1 0 17 | #define BEACON_CH_2 1 18 | #define BEACON_CH_3 2 19 | #define BEACON_CH_4 3 20 | 21 | // Infrared Beacon Buttons. Macros are kept for back-compatibility, and are now 22 | // replaced with the EV3IrRemoteButton enum 23 | #define BEACON_OFF 0 24 | #define BEACON_UP_LEFT 1 25 | #define BEACON_DOWN_LEFT 2 26 | #define BEACON_UP_RIGHT 3 27 | #define BEACON_DOWN_RIGHT 4 28 | #define BEACON_UP 5 29 | #define BEACON_DIAG_UP_LEFT 6 30 | #define BEACON_DIAG_UP_RIGHT 7 31 | #define BEACON_DOWN 8 32 | #define BEACON_ON 9 33 | #define BEACON_LEFT 10 34 | #define BEACON_RIGHT 11 35 | 36 | typedef enum EV3IrRemoteButton { 37 | EV3_IR_REMOTE_OFF, 38 | EV3_IR_REMOTE_UP_LEFT, 39 | EV3_IR_REMOTE_DOWN_LEFT, 40 | EV3_IR_REMOTE_UP_RIGHT, 41 | EV3_IR_REMOTE_DOWN_RIGHT, 42 | EV3_IR_REMOTE_UP, 43 | EV3_IR_REMOTE_DIAG_UP_LEFT, 44 | EV3_IR_REMOTE_DIAG_UP_RIGHT, 45 | EV3_IR_REMOTE_DOWN, 46 | EV3_IR_REMOTE_ON, 47 | EV3_IR_REMOTE_LEFT, 48 | EV3_IR_REMOTE_RIGHT 49 | } EV3IrRemoteButton; 50 | 51 | extern SensorHandler * EV3Ir; 52 | 53 | typedef struct EV3IrSeekResult { 54 | int directions[EV3_IR_CHANNELS]; 55 | int distances[EV3_IR_CHANNELS]; 56 | } EV3IrSeekResult; 57 | 58 | /** 59 | * @param port port to which the sensor is connected 60 | * @param result struct to which the result will be written (output variable) 61 | * @return -1 if there was an error while reading the sensor 62 | */ 63 | int ReadEV3IrSensorSeek (int port, EV3IrSeekResult* result); 64 | 65 | /** 66 | * Read the distance measured by the IR sensor in proximity mode 67 | * @param port port to which the sensor is connected 68 | * @return distance 69 | */ 70 | int ReadEV3IrSensorProximity (int port); 71 | 72 | /** 73 | * Reads which button on the EV3 IR Remote is pressed 74 | * @param port port to which the sensor is connected 75 | * @param channel IR channel to read 76 | * @return enum value of the pressed button 77 | */ 78 | EV3IrRemoteButton ReadEV3IrSensorRemote (int port, int channel); 79 | 80 | 81 | #endif //EV3_API_EV3_IR_H 82 | -------------------------------------------------------------------------------- /include/ev3_sensors/ev3_sensors.h: -------------------------------------------------------------------------------- 1 | /** \file ev3_sensors.h 2 | * \brief Imports all the c4ev3 supported sensors. 3 | * 4 | */ 5 | 6 | #ifndef EV3_API_EV3_SENSORS_H 7 | #define EV3_API_EV3_SENSORS_H 8 | 9 | #include 10 | #include "ev3_constants.h" 11 | 12 | #define NONE_MODE -1 13 | 14 | struct SensorHandler; 15 | 16 | typedef struct SensorHandler SensorHandler; 17 | 18 | /** 19 | * Initializes the specified sensor connected to the specified port 20 | * @param port 21 | * @param sensor 22 | * @return true if the initialization was successful 23 | */ 24 | bool SetSensor (int port, SensorHandler * sensor); 25 | 26 | /** 27 | * Returns the sensor handler initialized for the specified port 28 | * @param port port 29 | * @return Sensor handler or null 30 | */ 31 | SensorHandler * GetSensor (int port); 32 | 33 | /** 34 | * Initializes the specified sensor handlers for the 4 different robot ports. 35 | * Specify null to not initialize any sensor for a specific port. 36 | * If one sensor initialization fails, the previous initialized sensors are 37 | * de-initialized and false is returned. 38 | * @param port1 39 | * @param port2 40 | * @param port3 41 | * @param port4 42 | * @return true if the initialization was successful 43 | */ 44 | bool SetAllSensors (SensorHandler * port1, SensorHandler * port2, SensorHandler * port3, SensorHandler * port4); 45 | 46 | #include "ev3_touch.h" 47 | #include "ev3_color.h" 48 | #include "ev3_ir.h" 49 | #include "ht_ir_v2.h" 50 | #include "ev3_ultrasonic.h" 51 | #include "ev3_gyro.h" 52 | #include "nxt_temperature.h" 53 | #include "nxt_sound.h" 54 | #include "ht_compass.h" 55 | #include "ht_color.h" 56 | #include "pixy_cam.h" 57 | #include "ev3_sensors/c4ev3_compatibility.h" 58 | 59 | #endif //EV3_API_EV3_SENSORS_H 60 | -------------------------------------------------------------------------------- /include/ev3_sensors/ev3_touch.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_TOUCH_SENSOR_H 2 | #define EV3_API_EV3_TOUCH_SENSOR_H 3 | 4 | #include 5 | #include "ev3_sensors.h" 6 | 7 | #define EV3_TOUCH_SENSOR_TOUCH_MODE 0 8 | 9 | extern SensorHandler * EV3Touch; 10 | 11 | /** 12 | * Read the state of the touch sensor 13 | * @param sensorPort port to which the sensor is connected 14 | * @return true if pressed, false if not 15 | */ 16 | bool ReadEV3TouchSensor(int sensorPort); 17 | 18 | 19 | #endif //EV3_API_EV3_TOUCH_SENSOR_H 20 | -------------------------------------------------------------------------------- /include/ev3_sensors/ev3_ultrasonic.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_EV3_ULTRASONIC_H 2 | #define EV3_API_EV3_ULTRASONIC_H 3 | 4 | #include 5 | #include "ev3_sensors.h" 6 | 7 | // see http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-buster/sensor_data.html#lego-ev3-us 8 | 9 | #define EV3_ULTRASONIC_SENSOR_TYPE 30 10 | 11 | #define EV3_ULTRASONIC_SENSOR_DISTANCE_MM_MODE 0 12 | #define EV3_ULTRASONIC_SENSOR_DISTANCE_IN_MODE 1 13 | #define EV3_ULTRASONIC_SENSOR_LISTEN_MODE 2 14 | #define EV3_ULTRASONIC_SENSOR_SINGLE_MM_MODE 3 15 | #define EV3_ULTRASONIC_SENSOR_SINGLE_IN_MODE 4 16 | #define EV3_ULTRASONIC_SENSOR_DC_MM_MODE 5 17 | #define EV3_ULTRASONIC_SENSOR_DC_IN_MODE 6 18 | #define EV3_ULTRASONIC_SENSOR_DEFAULT_MODE EV3_ULTRASONIC_SENSOR_DISTANCE_MM_MODE 19 | 20 | #define EV3_ULTRASONIC_FIRE_COMMAND 0x11 21 | 22 | /** 23 | * @brief EV3 Ultrasonic Sensor (LEGO #45504) 24 | */ 25 | extern SensorHandler * EV3Ultrasonic; 26 | 27 | /** 28 | * @brief Units to measure the result in 29 | */ 30 | typedef enum EV3UltrasonicDistanceUnit { 31 | /** 32 | * @brief Return the distance in centimeters 33 | * (discard the decimal place of the *-MM measurement) 34 | * range: 0-255 35 | */ 36 | EV3_ULTRASONIC_CM, 37 | 38 | /** 39 | * @brief Return the distance in millimetes (*-MM) 40 | * range: 0-255 41 | */ 42 | EV3_ULTRASONIC_MM, 43 | 44 | /** 45 | * @brief Return the distance in inches (*-IN) 46 | * range: 0-1003 47 | */ 48 | EV3_ULTRASONIC_IN, 49 | } EV3UltrasonicDistanceUnit; 50 | 51 | /** 52 | * @brief Returns the distance continually measured by the sensor (US-DIST-*) 53 | * @param port Port to which the sensor is connected 54 | * @param mode Wheter to read the distance in cm, mm or inches 55 | * @return measured value or INT_MIN in case of error 56 | */ 57 | int ReadEV3UltrasonicSensorDistance(int port, EV3UltrasonicDistanceUnit mode); 58 | 59 | /** 60 | * @brief Returns the distance measured by the sensor by a single ping (US-SI-*) 61 | * 62 | * The distance will be measured only once after the mode is set. 63 | * To do the measurement again, either switch the sensor mode, or 64 | * call the FireEV3UltrasonicSensor() function. 65 | * 66 | * @param port Port to which the sensor is connected 67 | * @param mode Wheter to read the distance in cm, mm or inches 68 | * @return measured value or INT_MIN in case of error 69 | * @remark Beware, if you switch the sensor modes too often or 70 | * trigger the ping too often, the sensor may lock up for 2-3 seconds. 71 | */ 72 | int ReadEV3UltrasonicSensorSingleDistance(int port, EV3UltrasonicDistanceUnit mode); 73 | 74 | /** 75 | * @brief Returns the distance measured by the sensor in an unknown alternative way (US-DC-*) 76 | * @param port Port to which the sensor is connected 77 | * @param mode Wheter to read the distance in cm, mm or inches 78 | * @return measured value or INT_MIN in case of error 79 | * @remark It is not known how this mode is different from US-DIST-*. 80 | * It is recommended to use US-DIST-* as that is 81 | * the mode used in the stock lms2012 VM. 82 | */ 83 | int ReadEV3UltrasonicSensorDcDistance(int port, EV3UltrasonicDistanceUnit mode); 84 | 85 | /** 86 | * @brief Makes the sensor send out a ping for the single measurement mode. 87 | * @param port Port to which the sensor is connected 88 | * @return 0 or INT_MIN in case of error 89 | */ 90 | int FireEV3UltrasonicSensor(int port); 91 | 92 | /** 93 | * @brief Tries to find another ultrasonic sensor running in distance mode (US-LISTEN) 94 | * @param port Port to which the sensor is connected 95 | * @return true if there exists another ultrasonic sensor reading in distance mode, 96 | * false if not and finally INT_MIN in case of error 97 | */ 98 | int ReadEV3UltrasonicSensorListen(int port); 99 | 100 | #endif //EV3_API_EV3_ULTRASONIC_H 101 | -------------------------------------------------------------------------------- /include/ev3_sensors/ht_color.h: -------------------------------------------------------------------------------- 1 | #ifndef HT_COLOR_H 2 | #define HT_COLOR_H 3 | 4 | #include "ev3_sensors.h" 5 | 6 | #define HT_COLOR_SENSOR_V2_IIC_ADDRESS 0x01 7 | 8 | #define HT_COLOR_SENSOR_V2_50HZ_MODE 0x35 9 | #define HT_COLOR_SENSOR_V2_60HZ_MODE 0x36 10 | 11 | #define HT_COLOR_SENSOR_V2_MODE_REGISTER 0x41 12 | #define HT_COLOR_SENSOR_V2_COLOR_REGISTER 0x42 13 | #define HT_COLOR_SENSOR_V2_R_1BYTE_REGISTER 0x43 14 | #define HT_COLOR_SENSOR_V2_G_1BYTE_REGISTER 0x44 15 | #define HT_COLOR_SENSOR_V2_B_1BYTE_REGISTER 0x45 16 | #define HT_COLOR_SENSOR_V2_W_1BYTE_REGISTER 0x46 17 | 18 | #define HT_COLOR_SENSOR_V2_DEFAULT_MODE 0 19 | #define HT_COLOR_SENSOR_V2_PASSIVE_MODE 1 20 | #define HT_COLOR_SENSOR_V2_RAW_MODE 3 21 | 22 | extern SensorHandler * HTColorV2; 23 | 24 | typedef enum HTColorV2PowerMainsFrequency { 25 | PowerMains50Hz, 26 | PowerMains60Hz, 27 | } HTColorV2PowerMainsFrequency; 28 | 29 | typedef enum HTColorV2ReadingMode { 30 | HTColorSensorDefaultMode, 31 | HTColorSensorPassiveMode, 32 | HTColorSensorRawMode 33 | } HTColorV2ReadingMode; 34 | 35 | typedef struct RGBA { 36 | int red; 37 | int blue; 38 | int green; 39 | int white; 40 | } RGBA; 41 | 42 | int ReadHTColorSensorV2(int port); 43 | 44 | /** 45 | * Read RGBA values. Each value ranges from 0 to 1023 46 | * @param port port to which the sensor is connected 47 | * @param mode HTColorV2ReadingMode 48 | * @param result struct to which the result will be written (output variable) 49 | * @return -1 if there was an error 50 | */ 51 | int ReadHTColorSensorV2RGBA(int port, HTColorV2ReadingMode mode, RGBA* result); 52 | 53 | /** 54 | * Prepare the sensor to read values in an environment where mains power uses the 55 | * specified frequency 56 | * @param port port to which the sensor is connected 57 | * @param frequency frequency 58 | */ 59 | void SetHTColorV2PowerMainsFrequency(int port, HTColorV2PowerMainsFrequency frequency); 60 | 61 | 62 | #endif //EV3_API_HT_COLOR_H 63 | -------------------------------------------------------------------------------- /include/ev3_sensors/ht_compass.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_HT_COMPASS_H 2 | #define EV3_API_HT_COMPASS_H 3 | 4 | #include "ev3_sensors.h" 5 | 6 | #define HT_COMPASS_SENSOR_IIC_ADDRESS 0x01 7 | 8 | #define HT_COMPASS_SENSOR_DEFAULT_MODE 0 9 | 10 | extern SensorHandler * HTCompass; 11 | 12 | typedef enum HTCompassReadingMode { 13 | HTCompassCompass, 14 | HTCompassAngle 15 | } HTCompassReadingMode; 16 | 17 | int ReadHTCompassSensor(int port, HTCompassReadingMode mode); 18 | 19 | /** 20 | * Starts the compass sensor calibration. 21 | * Once the calibration is started, you should rotate very slowly the sensor, 22 | * taking at least 20 seconds per rotation. You should make 1.5 to 2 full rotations. 23 | * After you completed the calibration, call 'StopHTCompassCalibration'. 24 | * 25 | * Those instructions have been adapted from the LeJOS documentation. 26 | * @param port port to which the sensor is connected 27 | */ 28 | void StartHTCompassCalibration(int port); 29 | 30 | /** 31 | * Stops the calibration initialized calling 'StartHTCompassCalibration' 32 | * @param port port to which the sensor is connected 33 | */ 34 | void StopHTCompassCalibration(int port); 35 | 36 | 37 | #endif //EV3_API_HT_COMPASS_H 38 | -------------------------------------------------------------------------------- /include/ev3_sensors/ht_ir_v2.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_HT_IR_V2_H 2 | #define EV3_API_HT_IR_V2_H 3 | 4 | #include "ev3_sensors.h" 5 | 6 | #define HT_IR_V2_SENSOR_IIC_ADDRESS 0x08 7 | 8 | #define HT_IR_V2_SENSOR_DC_READING_MODE_REGISTER 0x42 9 | #define HT_IR_V2_SENSOR_AC_READING_MODE_REGISTER 0x49 10 | #define HT_IR_V2_SENSOR_DC_ALL_READING_MODE_REGISTER 0x43 11 | #define HT_IR_V2_SENSOR_AC_ALL_READING_MODE_REGISTER 0x4A 12 | 13 | #define HT_IR_V2_CHANNELS 5 14 | 15 | #define HT_IR_V2_SENSOR_DEFAULT_MODE 0 16 | 17 | extern SensorHandler * HTIrV2; 18 | 19 | typedef enum HTIrV2ReadingMode { 20 | Modulated, 21 | Unmodulated ///< Untested 22 | 23 | } HTIrV2ReadingMode; 24 | 25 | /** 26 | * Returns the direction from which the IR signal is coming from. 27 | * The direction ranges from 1 to 9. If no signal is detected, 0 is returned. 28 | * @param port port to which the sensor is connected 29 | * @param mode whether to read AC or DC signals 30 | * @return direction of the IR signal, -1 in case of error. 31 | */ 32 | int ReadHTIrV2Sensor(int port, HTIrV2ReadingMode mode); 33 | 34 | /** 35 | * Read all 5 individual channels of the sensor. 36 | * @param port port to which the sensor is connected 37 | * @param mode whether do read AC or DC IR signals 38 | * @param output array to which the 5 individual channel values are written to. 39 | * This is used as an output variable, and the size must be at least 5 40 | * @return -1 in case of error 41 | */ 42 | int ReadHTIrV2SensorAll(int port, HTIrV2ReadingMode mode, int8_t output[]); 43 | 44 | #endif //EV3_API_HT_IR_V2_H 45 | -------------------------------------------------------------------------------- /include/ev3_sensors/nxt_sound.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_NXT_SOUND_H 2 | #define EV3_API_NXT_SOUND_H 3 | 4 | #include "ev3_sensors.h" 5 | 6 | #define NXT_SOUND_SENSOR_TYPE 3 7 | #define NXT_SOUND_SENSOR_DB_MODE 0 8 | #define NXT_SOUND_SENSOR_DBA_MODE 1 9 | 10 | #define NXT_SOUND_SENSOR_DEFAULT_MODE NXT_SOUND_SENSOR_DB_MODE 11 | 12 | extern SensorHandler * NXTSound; 13 | 14 | typedef enum NXTSoundReadingMode { 15 | NXT_SOUND_DB, 16 | NXT_SOUND_DBA 17 | } NXTSoundReadingMode; 18 | 19 | int ReadNXTSoundSensor(int port, NXTSoundReadingMode mode); 20 | 21 | #endif //EV3_API_NXT_SOUND_H 22 | -------------------------------------------------------------------------------- /include/ev3_sensors/nxt_temperature.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_NXT_TEMPERATURE_H 2 | #define EV3_API_NXT_TEMPERATURE_H 3 | 4 | #include "ev3_sensors.h" 5 | 6 | #define NXT_TEMPERATURE_SENSOR_DEFAULT_MODE 0 7 | 8 | 9 | extern SensorHandler * NXTTemperature; 10 | 11 | typedef enum NXTTemperatureUnit { 12 | NXT_TEMPERATURE_C, 13 | NXT_TEMPERATURE_F 14 | } NXTTemperatureUnit; 15 | 16 | int ReadNXTTemperatureSensor(int port, NXTTemperatureUnit unit); 17 | 18 | #endif //EV3_API_NXT_TEMPERATURE_H 19 | -------------------------------------------------------------------------------- /include/ev3_sensors/pixy_cam.h: -------------------------------------------------------------------------------- 1 | #ifndef EV3_API_PIXY_CAM_H 2 | #define EV3_API_PIXY_CAM_H 3 | 4 | #include 5 | #include "ev3_sensors.h" 6 | 7 | #define PIXY_CAM_SENSOR_IIC_ADDRESS 0x01 8 | 9 | #define PIXY_CAM_BIGGEST_BLOB_RECTANGLE_REGISTER 0x50 10 | #define PIXY_CAM_BIGGEST_BLOB_ANGLE_REGISTER 0x60 11 | 12 | #define PIXY_CAM_ANGLE_CONSTANT 1.40625 13 | 14 | //! Untested. 15 | extern SensorHandler * PixyCam; 16 | 17 | typedef struct PixyRectangle { 18 | int signature; 19 | int x, y; 20 | int width, height; 21 | int angle; 22 | } PixyRectangle; 23 | 24 | /** 25 | * Reads the coordinates, size, signature and angle of the biggest blob found 26 | * by the sensor. 27 | * @param port port to which the sensor is connected to 28 | * @param result struct to which the result will be written (output variable) 29 | * @return -1 if there was an error 30 | */ 31 | int ReadPixyCamSensorBiggestBlobRectangle(int port, PixyRectangle* result); 32 | 33 | #endif //EV3_API_PIXY_CAM_H 34 | -------------------------------------------------------------------------------- /include/ev3_sound.h: -------------------------------------------------------------------------------- 1 | /** \file ev3_sound.h 2 | * \brief Functions and constants for controlling EV3 sounds 3 | * 4 | * ev3_sound.h contains declarations for the EV3 C API sound functions. 5 | * 6 | * License: 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | #include "ev3_command.h" 52 | #include "ev3_constants.h" 53 | 54 | typedef struct 55 | { 56 | unsigned short Frequency; 57 | unsigned short Duration; 58 | } Tone; 59 | 60 | bool SoundInit(); 61 | bool SoundOpen(); 62 | bool SoundClose(); 63 | bool SoundExit(); 64 | bool SoundInitialized(); 65 | 66 | void PlayFileEx(char* pFileName, uint8_t volume, bool loop); 67 | 68 | #define PlayFile(_f) PlayFileEx((_f), 100, false) 69 | 70 | void PlayToneEx(unsigned short frequency, unsigned short duration, uint8_t volume); 71 | 72 | #define PlayTone(_f, _d) PlayToneEx((_f), (_d), 100) 73 | 74 | void PlaySoundEx(uint8_t aCode, uint8_t volume); 75 | 76 | /** 77 | * Play a system sound. 78 | * Play a sound that mimics the RCX system sounds using one of the 79 | * \ref RCXSoundConstants. 80 | * 81 | * 82 | * 83 | * 84 | * 85 | * 86 | * 87 | * 88 | *
aCodeResulting Sound
\ref SOUND_CLICKkey click sound
\ref SOUND_DOUBLE_BEEPdouble beep
\ref SOUND_DOWNsweep down
\ref SOUND_UPsweep up
\ref SOUND_LOW_BEEPerror sound
\ref SOUND_FAST_UPfast sweep up
89 | * \param aCode The system sound to play. See \ref RCXSoundConstants. 90 | */ 91 | #define PlaySound(aCode) PlaySoundEx((aCode), 100) 92 | 93 | /** 94 | * Play multiple tones. 95 | * Play a series of tones contained in the tones array. Each element 96 | * in the array is an instance of the \ref Tone structure, containing 97 | * a frequency and a duration. 98 | * 99 | * \param tones The array of tones to play. 100 | * \param size The number of tones to play. 101 | */ 102 | void PlayTonesEx(Tone tones[], size_t size); 103 | 104 | #define PlayTones(_tones) PlayTonesEx(_tones, sizeof(_tones)/sizeof(_tones[0])) 105 | 106 | int SoundState(); 107 | 108 | void StopSound(); 109 | 110 | bool SoundTest(); 111 | 112 | void SoundReady(); 113 | 114 | void MuteSound(); 115 | 116 | void UnmuteSound(); 117 | 118 | void ClearSound(); 119 | 120 | #endif // ev3_sound_h 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | -------------------------------------------------------------------------------- /projects/make/.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | .objs 3 | *.elf 4 | *.elf.dbg 5 | *.rbf 6 | -------------------------------------------------------------------------------- /projects/make/Makefile: -------------------------------------------------------------------------------- 1 | ## Copyright (c) 2015 Ahmad Fatoum 2 | ## Copyright (c) 2020 Jakub Vanek 3 | 4 | ############################ 5 | # Workspace-level makefile # 6 | ############################ 7 | 8 | ifeq ($(app),) 9 | $(error please specify app=...) 10 | endif 11 | 12 | _default: 13 | @$(MAKE) -C $(app) 14 | 15 | $(MAKECMDGOALS): 16 | @$(MAKE) -C $(app) $@ 17 | 18 | .PHONY: $(MAKECMDGOALS) 19 | -------------------------------------------------------------------------------- /projects/make/README.md: -------------------------------------------------------------------------------- 1 | # Make-based workspace 2 | 3 | This is a workspace for building and uploading C4EV3 projects using Makefiles. 4 | 5 | ## File structure 6 | ``` 7 | /Makefile - top-level makefile (only forwards commands to subdirectories) 8 | /program-makefile.mk - project-level makefile (implements everything) 9 | /common-config.mk - makefile overrides for all projects 10 | /proj1/ - project directory 11 | /proj1/main.c - source file 12 | /proj1/util.h - source file 13 | /proj1/util.c - source file 14 | /proj1/project-config.mk - makefile overrides specific to the project 15 | /proj1/Makefile - symbolic link to program-makefile.mk 16 | /proj1/proj1.elf - resulting ELF binary 17 | /proj1/proj1.rbf - resulting RBF wrapper 18 | /proj/.objs/... - cached object files and dependency files 19 | ``` 20 | 21 | ## Invocation 22 | 23 | For information about makefile targets & parameters, please see 24 | the `help` target in [`program-makefile.mk`](program-makefile.mk). 25 | 26 | ## Requirements 27 | - common POSIX command line utilities (rm, mkdir, ...) 28 | - `make`, preferably GNU Make 29 | - GCC for the brick; see https://github.com/c4ev3/C4EV3.Toolchain 30 | - `ev3duder` installed for uploading programs to the brick 31 | -------------------------------------------------------------------------------- /projects/make/common-config.mk: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /projects/make/example/Makefile: -------------------------------------------------------------------------------- 1 | ../program-makefile.mk -------------------------------------------------------------------------------- /projects/make/example/main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | int main(int argc, char **argv) { 5 | for (int i = 0; i < REPEAT; i++) { 6 | TermPrintf("[%d] Hello, World!\r\n", i + 1); 7 | printf("[%d] Hello, World!\r\n", i + 1); 8 | Wait(1000); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /projects/make/example/main.h: -------------------------------------------------------------------------------- 1 | #ifndef example_main_h 2 | #define example_main_h 3 | 4 | int main(int argc, char **argv); 5 | 6 | #endif // example_main_h 7 | -------------------------------------------------------------------------------- /projects/make/example/project-config.mk: -------------------------------------------------------------------------------- 1 | override CFLAGS += -DREPEAT=5 2 | BRICK_IP = 10.0.0.41 3 | CROSS_COMPILE = armv5-linux-musleabi- 4 | -------------------------------------------------------------------------------- /projects/make/program-makefile.mk: -------------------------------------------------------------------------------- 1 | ## Copyright (c) 2015 Ahmad Fatoum 2 | ## Copyright (c) 2020 Jakub Vanek 3 | 4 | ########################## 5 | # Project-level makefile # 6 | ########################## 7 | 8 | # tool definitions 9 | CROSS_COMPILE ?= C:/CSLite/bin/arm-none-linux-gnueabi- 10 | CC = $(CROSS_COMPILE)gcc 11 | OBJCOPY = $(CROSS_COMPILE)objcopy 12 | STRIP = $(CROSS_COMPILE)strip 13 | MKDIR = mkdir -p 14 | RM = rm -rf 15 | EV3DUDER = ev3 16 | BRICK_IP ?= 17 | 18 | # define directories 19 | OBJDIR = .objs 20 | APIDIR ?= ../../.. 21 | 22 | # define output files 23 | APPNAME = $(shell basename $(CURDIR)) 24 | ELF = $(APPNAME).elf 25 | RBF = $(APPNAME).rbf 26 | DBG = $(ELF).dbg 27 | REMDIR = /home/root/lms2012/prjs/$(APPNAME) 28 | REMFILE = $(REMDIR)/$(ELF) 29 | REMRBF = $(REMDIR)/$(RBF) 30 | REMLOG = $(patsubst %.elf,%.rtf,$(REMFILE)) 31 | 32 | # define file lists 33 | SRCS = $(wildcard *.c) 34 | OBJS = $(patsubst %.c,$(OBJDIR)/%.o,$(SRCS)) 35 | DEPFILES = $(patsubst %.c,$(OBJDIR)/%.d,$(SRCS)) 36 | 37 | # define flags 38 | override CFLAGS += -std=c99 39 | override CFLAGS += -fno-strict-aliasing -fwrapv 40 | override CFLAGS += -Wall -Wextra -Wpointer-sign -Wno-unused-parameter 41 | override CFLAGS += -D_GNU_SOURCE=1 42 | override CXXFLAGS += -I $(APIDIR)/include -I $(APIDIR) -I $(APIDIR)/API 43 | 44 | # optimization and debug flags 45 | opt ?= 46 | ifeq ($(opt),) 47 | RELFLAGS := -Os -g 48 | 49 | else ifeq ($(opt),space) 50 | RELFLAGS := -Os -g 51 | 52 | else ifeq ($(opt),fast) 53 | RELFLAGS := -O3 -g0 54 | 55 | else ifeq ($(opt),debug) 56 | RELFLAGS := -O0 -ggdb3 57 | 58 | else 59 | $(error unknown build type) 60 | endif 61 | 62 | # logging control 63 | VERBOSE ?= 64 | ifeq ($(VERBOSE)$(V),) 65 | Q := @@ 66 | else 67 | Q := 68 | endif 69 | 70 | -include ../common-config.mk 71 | -include project-config.mk 72 | 73 | # default target 74 | all: $(ELF) $(RBF) 75 | 76 | # compile object files 77 | $(OBJDIR)/%.o: %.c $(OBJDIR)/%.d 78 | @echo " [CC] $<" 79 | @$(MKDIR) $(@D) 80 | $(Q)$(CC) -MMD -MP $(RELFLAGS) $(CXXFLAGS) $(CFLAGS) -c $< -o $@ 81 | 82 | $(DEPFILES): 83 | 84 | -include $(DEPFILES) 85 | 86 | # link final app 87 | $(ELF) $(DBG): $(OBJS) $(APIDIR)/libev3api.a 88 | @echo " [LD] $(@F)" 89 | $(Q)$(MKDIR) $(@D) 90 | $(Q)$(CC) $(RELFLAGS) $(LDFLAGS) $^ -o $@ 91 | @echo " [DBG] $(@F)" 92 | $(Q)$(OBJCOPY) --only-keep-debug "$@" "$@.dbg" 93 | $(Q)$(STRIP) --strip-debug --strip-unneeded "$@" 94 | $(Q)$(OBJCOPY) --add-gnu-debuglink="$@.dbg" "$@" 95 | 96 | # compile API 97 | $(APIDIR)/libev3api.a: 98 | $(Q)$(MAKE) -C $(APIDIR) CROSS_COMPILE=$(CROSS_COMPILE) CFLAGS="$(CFLAGS) $(RELFLAGS)" libev3api.a 99 | 100 | # create rbf 101 | $(RBF): $(ELF) 102 | @echo " [RBF] $(@F)" 103 | $(Q)$(EV3DUDER) mkrbf "$(REMFILE) >$(REMLOG) 2>&1" "$@" 104 | 105 | # user-facing targets 106 | 107 | help: 108 | @echo "Usage:" 109 | @echo "- make help - show this message" 110 | @echo "- make build - build this app" 111 | @echo "- make usbload - upload this app via USB" 112 | @echo "- make netload - upload this app via network" 113 | @echo "- make clean - remove built files" 114 | @echo "- make cleanapi - remove built files of the EV3-API library" 115 | @echo "- make gdb - open GDB for remote debugging" 116 | @echo "- make telnet - open telnet session" 117 | @echo "Useful variables:" 118 | @echo "- make ... V=1" 119 | @echo " -> show compilation commands" 120 | @echo "- make ... opt=space/debug/fast" 121 | @echo " -> set default optimization target" 122 | @echo "- make ... BRICK_IP=192.168.1.42" 123 | @echo " -> set brick IP address" 124 | @echo "- make ... CFLAGS='-flto' LDFLAGS='-flto'" 125 | @echo " -> add compiler/linker flags" 126 | @echo "- make ... CROSS_COMPILE=arm-c4ev3-linux-uclibceabi-" 127 | @echo " -> select the compiler used for build" 128 | 129 | build: $(ELF) 130 | 131 | usbload: $(ELF) $(RBF) 132 | @echo " [EV3] mkdir $(REMDIR)" 133 | $(Q)$(EV3DUDER) mkdir "$(REMDIR)" || true 134 | 135 | @echo " [EV3] upload $(RBF) -> $(REMRBF)" 136 | $(Q)$(EV3DUDER) up "$(RBF)" "$(REMRBF)" 137 | 138 | @echo " [EV3] upload $(ELF) -> $(REMFILE)" 139 | $(Q)$(EV3DUDER) up "$(ELF)" "$(REMFILE)" 140 | 141 | ifeq ($(BRICK_IP),) 142 | netload: 143 | @echo "please set BRICK_IP via configuration" && false 144 | else 145 | netload: $(ELF) $(RBF) 146 | @echo " [EV3] mkdir $(REMDIR)" 147 | $(Q)$(EV3DUDER) --tcp=$(BRICK_IP) mkdir "$(REMDIR)" || true 148 | 149 | @echo " [EV3] upload $(RBF) -> $(REMRBF)" 150 | $(Q)$(EV3DUDER) --tcp=$(BRICK_IP) up "$(RBF)" "$(REMRBF)" 151 | 152 | @echo " [EV3] upload $(ELF) -> $(REMFILE)" 153 | $(Q)$(EV3DUDER) --tcp=$(BRICK_IP) up "$(ELF)" "$(REMFILE)" 154 | endif 155 | 156 | # remove built files 157 | clean: 158 | $(RM) $(OBJDIR) $(ELF) $(DBG) $(RBF) 159 | 160 | cleanapi: 161 | $(Q)$(MAKE) -C $(APIDIR) clean 162 | 163 | # run GDB for remote debugging 164 | gdb: $(ELF) $(DBG) 165 | @echo " [GDB] $<" 166 | $(Q)gdb-multiarch "$<" 167 | 168 | # launch a telnet connection via network 169 | ifeq ($(BRICK_IP),) 170 | telnet: 171 | @echo "please set BRICK_IP via configuration" && false 172 | else 173 | telnet: 174 | telnet $(BRICK_IP) || true 175 | endif 176 | 177 | .PHONY: all help build usbload netload clean cleanapi gdb telnet 178 | --------------------------------------------------------------------------------