├── cmsis ├── lpc17xx_dac.h ├── lpc17xx_clkpwr.h ├── lpc17xx_libcfg_default.c ├── system_LPC17xx.h ├── lpc17xx_nvic.h ├── debug_frmwrk.h └── lpc17xx_rit.h ├── .gitignore ├── openocd.gdb ├── delay.cpp ├── delay.h ├── README ├── lib ├── fatfs │ ├── integer.h │ ├── diskio.cpp │ ├── FatFS.h │ └── diskio.h ├── Stream │ ├── Stream.cpp │ └── Stream.h ├── FunctionPointer │ └── FunctionPointer.cpp ├── Debug │ ├── debugpretty.h │ ├── Debug.h │ └── Debug.cpp ├── E36Diag │ ├── E36SRS.h │ ├── E36MK4.h │ ├── E36IHKR.h │ ├── E36ZKE4.h │ ├── E36MK4.cpp │ ├── E36IHKR.cpp │ ├── E36SRS.cpp │ ├── E36Kombi.cpp │ ├── E36ZKE4.cpp │ └── E36Kombi.h ├── Watchdog │ ├── Watchdog.h │ └── Watchdog.cpp ├── Input │ ├── Input.h │ └── Input.cpp ├── PWM │ └── PWM.h ├── AnalogOut │ ├── AnalogOut.h │ └── AnalogOut.cpp ├── RTC │ ├── RTC.h │ └── RTC.cpp ├── SPI │ └── SPI.h ├── DS2 │ ├── Bus.h │ ├── DS2Bus.h │ ├── DS2Bus.cpp │ ├── DS2Packet.h │ ├── Bus.cpp │ └── DS2.h ├── I2C │ └── I2C.h ├── PCA95xx │ ├── PCA95xxPin.h │ ├── PCA95xxPin.cpp │ ├── PCA95xx.h │ └── PCA95xx.cpp ├── ConfigFile │ └── ConfigFile.h ├── AnalogIn │ ├── AnalogIn.h │ └── AnalogIn.cpp ├── IO │ └── IO.h ├── MMA845x │ ├── MMA845x.h │ └── MMA845x.cpp ├── Callback │ ├── Callback.cpp │ └── Callback.h ├── SDFS │ └── SDFS.h ├── Uart │ └── Uart.h └── Timer │ └── Timer.h ├── LICENSE ├── main.cpp ├── syscalls.h ├── tasks ├── ObcKmmls │ ├── ObcKmmls.h │ └── ObcKmmls.cpp ├── ObcRange │ ├── ObcRange.h │ └── ObcRange.cpp ├── ObcSpeed │ ├── ObcSpeed.h │ └── ObcSpeed.cpp ├── ObcOdometer │ ├── ObcOdometer.h │ └── ObcOdometer.cpp ├── ObcClock │ └── ObcClock.h ├── ObcMemo │ ├── ObcMemo.h │ └── ObcMemo.cpp ├── ObcTimer │ ├── ObcTimer.h │ └── ObcTimer.cpp ├── ObcCode │ └── ObcCode.h ├── ObcLimit │ └── ObcLimit.h ├── ObcTemp │ └── ObcTemp.h ├── ObcConsum │ └── ObcConsum.h ├── ObcCheck │ └── ObcCheck.h └── ObcDist │ └── ObcDist.h ├── SpeedInput.h ├── FuelLevel.h ├── FuelConsumption.h ├── ObcLcd.h ├── CheckControlModule.cpp ├── CheckControlModule.h ├── SpeedInput.cpp ├── ObcUI.h ├── ObcUITask.cpp ├── ObcUITask.h ├── FuelConsumption.cpp ├── ObcLcd.cpp └── FuelLevel.cpp /cmsis/lpc17xx_dac.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benemorius/openOBC-devboard/HEAD/cmsis/lpc17xx_dac.h -------------------------------------------------------------------------------- /cmsis/lpc17xx_clkpwr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benemorius/openOBC-devboard/HEAD/cmsis/lpc17xx_clkpwr.h -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .*~ 3 | *.a 4 | *.o 5 | *.bin 6 | *.elf 7 | *.hex 8 | *.lst 9 | *.sym 10 | *.map 11 | *.lss 12 | .dep 13 | .kdev4 14 | *.kdev4 15 | \#*\# 16 | .AppleDouble 17 | .DS_Store 18 | ._.DS_Store 19 | .*.kate-swp 20 | *.xcodeproj 21 | -------------------------------------------------------------------------------- /openocd.gdb: -------------------------------------------------------------------------------- 1 | file openOBC-devboard.elf 2 | target remote | openocd -finterface/olimex-arm-usb-ocd.cfg -ftarget/lpc1768.cfg -c "gdb_port pipe; log_output /dev/null" -c "lpc1768.cpu configure -event gdb-detach { shutdown }" 3 | 4 | monitor adapter_khz 6000 5 | -------------------------------------------------------------------------------- /delay.cpp: -------------------------------------------------------------------------------- 1 | #include "delay.h" 2 | #include "IO.h" 3 | 4 | extern IO* idle; 5 | 6 | void delay(uint32_t ms) 7 | { 8 | idle->off(); 9 | uint32_t systickcnt; 10 | systickcnt = SysTickCnt; 11 | while((SysTickCnt - systickcnt) < ms); 12 | idle->on(); 13 | } 14 | -------------------------------------------------------------------------------- /delay.h: -------------------------------------------------------------------------------- 1 | #ifndef DELAY_H 2 | #define DELAY_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif //__cplusplus 9 | 10 | extern volatile uint32_t SysTickCnt; 11 | 12 | void delay(uint32_t ms); 13 | 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif //__cplusplus 18 | 19 | #endif //DELAY_H 20 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | sudo apt-get install git flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo zlib1g-dev build-essential libftdi-dev 2 | cd 3 | git clone https://github.com/esden/summon-arm-toolchain.git 4 | cd summon-arm-toolchain 5 | sed -i 's/--no-passive-ftp //' summon-arm-toolchain 6 | ./summon-arm-toolchain LIBOPENCM3_EN=0 7 | PATH=$PATH:~/sat/bin 8 | cd 9 | git clone https://github.com/benemorius/openOBC-devboard.git 10 | cd openOBC-devboard 11 | make 12 | 13 | -------------------------------------------------------------------------------- /lib/fatfs/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _INTEGER 6 | #define _INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types must be 16-bit, 32-bit or larger integer */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* These types must be 8-bit integer */ 20 | typedef char CHAR; 21 | typedef unsigned char UCHAR; 22 | typedef unsigned char BYTE; 23 | 24 | /* These types must be 16-bit integer */ 25 | typedef short SHORT; 26 | typedef unsigned short USHORT; 27 | typedef unsigned short WORD; 28 | typedef unsigned short WCHAR; 29 | 30 | /* These types must be 32-bit integer */ 31 | typedef long LONG; 32 | typedef unsigned long ULONG; 33 | typedef unsigned long DWORD; 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | -------------------------------------------------------------------------------- /lib/Stream/Stream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | // #include "Stream.h" 27 | 28 | -------------------------------------------------------------------------------- /lib/FunctionPointer/FunctionPointer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "FunctionPointer.h" 27 | 28 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "OpenOBC.h" 27 | 28 | 29 | 30 | int main() 31 | { 32 | OpenOBC* obc = new OpenOBC(); 33 | obc->mainloop(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /lib/Debug/debugpretty.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef DEBUGPRETTY_H 27 | #define DEBUGPRETTY_H 28 | 29 | #include 30 | 31 | #define DEBUG(format, ...) fprintf(stderr, "[%s{%i} %s()] " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) 32 | 33 | #endif // DEBUGPRETTY_H 34 | -------------------------------------------------------------------------------- /lib/E36Diag/E36SRS.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef E36SRS_H 27 | #define E36SRS_H 28 | 29 | #include "DS2.h" 30 | 31 | class E36SRS 32 | { 33 | 34 | public: 35 | E36SRS(DS2& diagnosticInterface); 36 | 37 | bool query(); 38 | 39 | private: 40 | DS2& diag; 41 | int address; 42 | DS2PacketType packetType; 43 | }; 44 | 45 | #endif // E36SRS_H 46 | -------------------------------------------------------------------------------- /lib/E36Diag/E36MK4.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | 28 | #ifndef E36MK4_H 29 | #define E36MK4_H 30 | 31 | #include "DS2.h" 32 | 33 | class E36MK4 34 | { 35 | 36 | public: 37 | E36MK4(DS2& diagnosticInterface); 38 | 39 | bool query(); 40 | 41 | private: 42 | DS2& diag; 43 | int address; 44 | DS2PacketType packetType; 45 | }; 46 | 47 | #endif // E36MK4_H 48 | -------------------------------------------------------------------------------- /lib/E36Diag/E36IHKR.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | 28 | #ifndef E36IHKR_H 29 | #define E36IHKR_H 30 | 31 | #include "DS2.h" 32 | 33 | class E36IHKR 34 | { 35 | 36 | public: 37 | E36IHKR(DS2& diagnosticInterface); 38 | 39 | bool query(); 40 | 41 | private: 42 | DS2& diag; 43 | int address; 44 | DS2PacketType packetType; 45 | }; 46 | 47 | #endif // E36IHKR_H 48 | -------------------------------------------------------------------------------- /lib/Watchdog/Watchdog.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | #ifndef WATCHDOG_H 28 | #define WATCHDOG_H 29 | 30 | #include 31 | 32 | class Watchdog 33 | { 34 | 35 | public: 36 | Watchdog(); 37 | virtual ~Watchdog(); 38 | 39 | void start(float seconds); 40 | void stop(); 41 | void feed(); 42 | bool wasReset(); 43 | }; 44 | 45 | #endif // WATCHDOG_H 46 | -------------------------------------------------------------------------------- /lib/E36Diag/E36ZKE4.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef ZKE4_H 27 | #define ZKE4_H 28 | 29 | #include "DS2.h" 30 | 31 | class E36ZKE4 32 | { 33 | public: 34 | E36ZKE4(DS2& diagnosticInterface); 35 | 36 | E36ZKE4& lock(); 37 | E36ZKE4& unlock(); 38 | bool query(); 39 | 40 | private: 41 | DS2& diag; 42 | int address; 43 | DS2PacketType packetType; 44 | }; 45 | 46 | #endif // ZKE4_H 47 | -------------------------------------------------------------------------------- /syscalls.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef SYSCALLS_H 27 | #define SYSCALLS_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | 40 | #include "LPC17xx.h" /* for _get_PSP() from core_cm3.h*/ 41 | 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif // SYSCALLS_H -------------------------------------------------------------------------------- /tasks/ObcKmmls/ObcKmmls.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCKMMLS_H 27 | #define OBCKMMLS_H 28 | 29 | #include 30 | 31 | class ObcKmmls : public ObcUITask 32 | { 33 | 34 | public: 35 | ObcKmmls(OpenOBC& obc); 36 | ~ObcKmmls(); 37 | 38 | virtual void runTask(); 39 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 40 | 41 | virtual void wake(); 42 | // virtual void sleep(); 43 | 44 | }; 45 | 46 | #endif // OBCKMMLS_H 47 | -------------------------------------------------------------------------------- /tasks/ObcRange/ObcRange.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCRANGE_H 27 | #define OBCRANGE_H 28 | 29 | #include 30 | 31 | class ObcRange : public ObcUITask 32 | { 33 | 34 | public: 35 | ObcRange(OpenOBC& obc); 36 | ~ObcRange(); 37 | 38 | virtual void runTask(); 39 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 40 | 41 | virtual void wake(); 42 | // virtual void sleep(); 43 | 44 | }; 45 | 46 | #endif // OBCRANGE_H 47 | -------------------------------------------------------------------------------- /lib/E36Diag/E36MK4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "E36MK4.h" 27 | 28 | #define CMD_QUERY {0x00} 29 | 30 | E36MK4::E36MK4(DS2& diagnosticInterface) : diag(diagnosticInterface) 31 | { 32 | address = 0x36; 33 | packetType = DS2_16BIT; 34 | } 35 | 36 | bool E36MK4::query() 37 | { 38 | const uint8_t cmd[] = CMD_QUERY; 39 | DS2Packet query(address, cmd, sizeof(cmd), packetType); 40 | DS2Packet* reply = diag.query(query); 41 | if(reply != NULL) 42 | { 43 | delete reply; 44 | return true; 45 | } 46 | return false; 47 | } 48 | -------------------------------------------------------------------------------- /lib/E36Diag/E36IHKR.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "E36IHKR.h" 27 | 28 | #define CMD_QUERY {0x00} 29 | 30 | E36IHKR::E36IHKR(DS2& diagnosticInterface) : diag(diagnosticInterface) 31 | { 32 | address = 0x59; 33 | packetType = DS2_16BIT; 34 | } 35 | 36 | bool E36IHKR::query() 37 | { 38 | const uint8_t cmd[] = CMD_QUERY; 39 | DS2Packet query(address, cmd, sizeof(cmd), packetType); 40 | DS2Packet* reply = diag.query(query); 41 | if(reply != NULL) 42 | { 43 | delete reply; 44 | return true; 45 | } 46 | return false; 47 | } 48 | -------------------------------------------------------------------------------- /tasks/ObcSpeed/ObcSpeed.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCSPEED_H 27 | #define OBCSPEED_H 28 | 29 | #include 30 | 31 | class ObcSpeed : public ObcUITask 32 | { 33 | 34 | public: 35 | ObcSpeed(OpenOBC& obc); 36 | ~ObcSpeed(); 37 | 38 | virtual void runTask(); 39 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 40 | 41 | virtual void wake(); 42 | virtual void sleep(); 43 | 44 | 45 | private: 46 | float averageSpeedKmh; 47 | float averageSeconds; 48 | }; 49 | 50 | #endif // OBCSPEED_H 51 | -------------------------------------------------------------------------------- /tasks/ObcOdometer/ObcOdometer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCODOMETER_H 27 | #define OBCODOMETER_H 28 | 29 | #include 30 | 31 | class ObcOdometer : public ObcUITask 32 | { 33 | 34 | public: 35 | ObcOdometer(OpenOBC& obc); 36 | ~ObcOdometer(); 37 | 38 | virtual void runTask(); 39 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 40 | virtual void wake(); 41 | virtual void sleep(); 42 | 43 | private: 44 | Timer timer; 45 | float currentKm; 46 | float ignitionOnKm; 47 | }; 48 | 49 | #endif // OBCODOMETER_H 50 | -------------------------------------------------------------------------------- /lib/E36Diag/E36SRS.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "E36SRS.h" 27 | 28 | #define CMD_QUERY {0x00} 29 | 30 | E36SRS::E36SRS(DS2& diagnosticInterface) : diag(diagnosticInterface) 31 | { 32 | address = 0xa4; 33 | packetType = DS2_8BIT; 34 | } 35 | 36 | bool E36SRS::query() //FIXME srs module requires a delay between eacy byte iirc 37 | { 38 | const uint8_t cmd[] = CMD_QUERY; 39 | DS2Packet query(address, cmd, sizeof(cmd), packetType); 40 | DS2Packet* reply = diag.query(query); 41 | if(reply != NULL) 42 | { 43 | delete reply; 44 | return true; 45 | } 46 | return false; 47 | } 48 | -------------------------------------------------------------------------------- /SpeedInput.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef SPEEDINPUT_H 27 | #define SPEEDINPUT_H 28 | 29 | #include "Input.h" 30 | #include "InterruptManager.h" 31 | #include "Timer.h" 32 | 33 | class SpeedInput 34 | { 35 | public: 36 | SpeedInput(Input& input, InterruptManager& interruptManager); 37 | ~SpeedInput(); 38 | 39 | float getKmh(); 40 | float getMph() {return getKmh() * 0.621371f;} 41 | 42 | private: 43 | void interruptHandler(); 44 | 45 | Input& input; 46 | InterruptManager& interruptManager; 47 | Timer* periodTimer; 48 | float currentSpeed; 49 | }; 50 | 51 | #endif // SPEEDINPUT_H 52 | -------------------------------------------------------------------------------- /lib/Input/Input.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef INPUT_H 27 | #define INPUT_H 28 | 29 | #include 30 | 31 | class Input 32 | { 33 | public: 34 | Input(uint8_t port, uint8_t pin, bool onIsHigh = true); 35 | bool getState() const; 36 | void setPullup(); 37 | void setPulldown(); 38 | void setTristate(); 39 | 40 | uint8_t getPort() const {return port;} 41 | uint8_t getPin() const {return pin;} 42 | 43 | operator bool() const { return getState();} 44 | 45 | 46 | private: 47 | uint8_t port; 48 | uint8_t pin; 49 | bool onIsHigh; 50 | }; 51 | 52 | #endif // INPUT_H 53 | -------------------------------------------------------------------------------- /tasks/ObcClock/ObcClock.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCCLOCK_H 27 | #define OBCCLOCK_H 28 | 29 | #include 30 | 31 | namespace ObcClockState { 32 | enum state {Clock, Date, ClockSet, DateSet, YearSet}; 33 | } 34 | 35 | class ObcClock : public ObcUITask 36 | { 37 | 38 | public: 39 | ObcClock(OpenOBC& obc); 40 | ~ObcClock(); 41 | 42 | virtual void runTask(); 43 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 44 | 45 | virtual void wake(); 46 | virtual void sleep(); 47 | 48 | private: 49 | ObcClockState::state state; 50 | 51 | }; 52 | 53 | #endif // OBCCLOCK_H 54 | -------------------------------------------------------------------------------- /cmsis/lpc17xx_libcfg_default.c: -------------------------------------------------------------------------------- 1 | /***********************************************************************//** 2 | * @file lpc17xx_libcfg_default.c 3 | * @brief Library configuration source file (default), 4 | * used to build library without examples. 5 | * @version 2.0 6 | * @date 21. May. 2010 7 | * @author NXP MCU SW Application Team 8 | ************************************************************************** 9 | * Software that is described herein is for illustrative purposes only 10 | * which provides customers with programming information regarding the 11 | * products. This software is supplied "AS IS" without any warranties. 12 | * NXP Semiconductors assumes no responsibility or liability for the 13 | * use of the software, conveys no license or title under any patent, 14 | * copyright, or mask work right to the product. NXP Semiconductors 15 | * reserves the right to make changes in the software without 16 | * notification. NXP Semiconductors also make no representation or 17 | * warranty that such application will be suitable for the specified 18 | * use without further testing or modification. 19 | **************************************************************************/ 20 | 21 | /* Library group ----------------------------------------------------------- */ 22 | /** @addtogroup LIBCFG_DEFAULT 23 | * @{ 24 | */ 25 | 26 | /* Includes ------------------------------------------------------------------- */ 27 | #include "lpc17xx_libcfg_default.h" 28 | 29 | /* Public Functions ----------------------------------------------------------- */ 30 | /** @addtogroup LIBCFG_DEFAULT_Public_Functions 31 | * @{ 32 | */ 33 | 34 | 35 | /** 36 | * @} 37 | */ 38 | 39 | /** 40 | * @} 41 | */ 42 | 43 | /* --------------------------------- End Of File ------------------------------ */ 44 | -------------------------------------------------------------------------------- /lib/Watchdog/Watchdog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | #include "Watchdog.h" 28 | 29 | Watchdog::Watchdog() 30 | { 31 | WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET); 32 | } 33 | 34 | Watchdog::~Watchdog() 35 | { 36 | //FIXME deinit wdt 37 | } 38 | 39 | void Watchdog::start(float seconds) 40 | { 41 | WDT_Start(seconds * 1000 * 1000); 42 | } 43 | 44 | void Watchdog::stop() 45 | { 46 | LPC_WDT->WDMOD &= ~WDT_WDMOD_WDEN; 47 | } 48 | 49 | void Watchdog::feed() 50 | { 51 | WDT_Feed(); 52 | } 53 | 54 | bool Watchdog::wasReset() 55 | { 56 | if(WDT_ReadTimeOutFlag()) 57 | { 58 | WDT_ClrTimeOutFlag(); 59 | return true; 60 | } 61 | return false; 62 | } 63 | -------------------------------------------------------------------------------- /tasks/ObcMemo/ObcMemo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCMEMO_H 27 | #define OBCMEMO_H 28 | 29 | #include 30 | 31 | namespace ObcMemoState 32 | { 33 | enum state {Voltage, FreeMem, Accelerometer}; 34 | } 35 | 36 | class ObcMemo : public ObcUITask 37 | { 38 | 39 | public: 40 | ObcMemo(OpenOBC& obc); 41 | ~ObcMemo(); 42 | 43 | virtual void runTask(); 44 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 45 | 46 | virtual void wake(); 47 | virtual void sleep(); 48 | 49 | private: 50 | ObcMemoState::state state; 51 | }; 52 | 53 | #endif // OBCMEMO_H 54 | -------------------------------------------------------------------------------- /lib/PWM/PWM.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef PWM_H 27 | #define PWM_H 28 | 29 | #include 30 | #include 31 | 32 | 33 | class PWM 34 | { 35 | public: 36 | PWM(uint8_t port, uint8_t pin, float dutyCycle = .5, float frequency = 80000); 37 | void setDutyCycle(float dutyCycle); 38 | float getDutyCycle(); 39 | void setFrequency(float frequency); //on the LPC17xx this will set the frequency of all 6 PWM channels 40 | float getFrequency(); 41 | 42 | private: 43 | uint8_t port; 44 | uint8_t pin; 45 | uint8_t channel; 46 | LPC_PWM_TypeDef* peripheral; 47 | float dutyCycle; 48 | float frequency; 49 | }; 50 | 51 | #endif // PWM_H 52 | -------------------------------------------------------------------------------- /tasks/ObcTimer/ObcTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCTIMER_H 27 | #define OBCTIMER_H 28 | 29 | #include 30 | 31 | namespace ObcTimerState { 32 | enum state {Inactive, Armed, Timing}; 33 | } 34 | 35 | class ObcTimer : public ObcUITask 36 | { 37 | 38 | public: 39 | ObcTimer(OpenOBC& obc); 40 | virtual ~ObcTimer(); 41 | 42 | virtual void runTask(); 43 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 44 | 45 | virtual void wake(); 46 | virtual void sleep(); 47 | 48 | private: 49 | ObcTimerState::state state; 50 | Timer timer; 51 | float timedValue; 52 | 53 | }; 54 | 55 | #endif // OBCTIMER_H 56 | -------------------------------------------------------------------------------- /tasks/ObcCode/ObcCode.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCCODE_H 27 | #define OBCCODE_H 28 | 29 | #include 30 | 31 | namespace ObcCodeState { 32 | enum state {CodeSet, CodeActive, CodeInactive, CodeArmed, CodePrompt}; 33 | } 34 | 35 | class ObcCode : public ObcUITask 36 | { 37 | 38 | public: 39 | ObcCode(OpenOBC& obc); 40 | ~ObcCode(); 41 | 42 | virtual void runTask(); 43 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 44 | 45 | virtual void wake(); 46 | virtual void sleep(); 47 | 48 | private: 49 | uint32_t code; 50 | uint32_t codeSet; 51 | ObcCodeState::state state; 52 | }; 53 | 54 | #endif // OBCCODE_H 55 | -------------------------------------------------------------------------------- /tasks/ObcLimit/ObcLimit.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCLIMIT_H 27 | #define OBCLIMIT_H 28 | 29 | #include 30 | 31 | namespace ObcLimitState { 32 | enum state {LimitInactive, LimitActive, LimitSet}; 33 | } 34 | 35 | class ObcLimit : public ObcUITask 36 | { 37 | 38 | public: 39 | ObcLimit(OpenOBC& obc); 40 | ~ObcLimit(); 41 | 42 | virtual void runTask(); 43 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 44 | 45 | // virtual void wake(); 46 | virtual void sleep(); 47 | 48 | private: 49 | ObcLimitState::state state; 50 | float limitKmh; 51 | float limitKmhSet; 52 | bool hasWarned; 53 | }; 54 | 55 | #endif // OBCLIMIT_H 56 | -------------------------------------------------------------------------------- /tasks/ObcTemp/ObcTemp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCTEMP_H 27 | #define OBCTEMP_H 28 | 29 | #include 30 | 31 | namespace ObcTempState { 32 | enum state {TempExt, TempCoolant, TempCoolantWarningSet}; 33 | } 34 | 35 | class ObcTemp : public ObcUITask 36 | { 37 | 38 | public: 39 | ObcTemp(OpenOBC& obc); 40 | ~ObcTemp(); 41 | 42 | virtual void runTask(); 43 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 44 | 45 | virtual void wake(); 46 | virtual void sleep(); 47 | 48 | private: 49 | ObcTempState::state state; 50 | uint32_t coolantWarningTemp; 51 | uint32_t coolantWarningTempSet; 52 | }; 53 | 54 | #endif // OBCTEMP_H 55 | -------------------------------------------------------------------------------- /lib/AnalogOut/AnalogOut.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef ANALOGOUT_H 27 | #define ANALOGOUT_H 28 | 29 | #include 30 | #include 31 | 32 | class AnalogOut 33 | { 34 | 35 | public: 36 | AnalogOut(uint8_t port, uint8_t pin, float maxScaleVoltage); 37 | ~AnalogOut(); 38 | 39 | float readVoltage(); 40 | float readPercent(); 41 | uint16_t readRaw(); 42 | 43 | void writeVoltage(float voltage); 44 | void writePercent(float percent); 45 | void writeRaw(uint16_t rawValue); 46 | 47 | private: 48 | uint8_t port; 49 | uint8_t pin; 50 | float maxScaleVoltage; 51 | LPC_DAC_TypeDef* peripheral; 52 | uint16_t currentRawValue; 53 | }; 54 | 55 | #endif // ANALOGOUT_H 56 | -------------------------------------------------------------------------------- /lib/RTC/RTC.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef RTC_H 27 | #define RTC_H 28 | 29 | #include 30 | 31 | class RTC 32 | { 33 | public: 34 | RTC(); 35 | 36 | void setTime(RTC_TIME_Type* time); 37 | void getTime(RTC_TIME_Type* time); 38 | 39 | uint8_t getSecond(); 40 | uint8_t getMinute(); 41 | uint8_t getHour(); 42 | uint8_t getDay(); 43 | uint8_t getMonth(); 44 | uint16_t getYear(); 45 | 46 | void setSecond(uint8_t second); 47 | void setMinute(uint8_t minute); 48 | void setHour(uint8_t hour); 49 | void setDay(uint8_t day); 50 | void setMonth(uint8_t month); 51 | void setYear(uint16_t year); 52 | 53 | private: 54 | RTC_TIME_Type time; 55 | }; 56 | 57 | #endif // RTC_H 58 | -------------------------------------------------------------------------------- /FuelLevel.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef FUELLEVEL_H 27 | #define FUELLEVEL_H 28 | 29 | #include "Input.h" 30 | #include "InterruptManager.h" 31 | #include "Timer.h" 32 | 33 | class FuelLevel 34 | { 35 | public: 36 | FuelLevel(Input& dataPin, InterruptManager& interruptManager); 37 | ~FuelLevel(); 38 | 39 | uint16_t getDeciLitres() {return decilitres;} 40 | float getLitres() {return (float)decilitres / 10;} 41 | float getGallons() {return getLitres() / 3.78541f;} 42 | 43 | private: 44 | void interruptHandler(); 45 | 46 | Input& dataPin; 47 | InterruptManager& interruptManager; 48 | Timer timeout; 49 | Timer periodTimer; 50 | uint16_t decilitres; 51 | }; 52 | 53 | #endif // FUELLEVEL_H 54 | -------------------------------------------------------------------------------- /lib/SPI/SPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef SPI_H 27 | #define SPI_H 28 | 29 | #include 30 | 31 | #include 32 | 33 | class SPI 34 | { 35 | 36 | public: 37 | SPI(uint8_t mosiPort, uint8_t mosiPin, uint8_t misoPort, uint8_t misoPin, uint8_t sckPort, uint8_t sckPin, uint32_t clockRate = 100000); 38 | 39 | uint8_t readWrite(uint8_t writeByte); 40 | void setClockRate(uint32_t hz); 41 | void setPullup(bool isEnabled); 42 | 43 | private: 44 | uint8_t mosiPort; 45 | uint8_t mosiPin; 46 | uint8_t misoPort; 47 | uint8_t misoPin; 48 | uint8_t sckPort; 49 | uint8_t sckPin; 50 | LPC_SSP_TypeDef* peripheral; 51 | uint32_t clockRate; 52 | 53 | }; 54 | 55 | #endif // SPI_H 56 | -------------------------------------------------------------------------------- /tasks/ObcConsum/ObcConsum.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCCONSUM_H 27 | #define OBCCONSUM_H 28 | 29 | #include 30 | 31 | namespace ObcConsumScreen { 32 | enum screen {Screen1, Screen2, Screen3, Screen4}; 33 | } 34 | 35 | class ObcConsum : public ObcUITask 36 | { 37 | 38 | public: 39 | ObcConsum(OpenOBC& obc); 40 | ~ObcConsum(); 41 | 42 | virtual void runTask(); 43 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 44 | 45 | virtual void wake(); 46 | virtual void sleep(); 47 | 48 | private: 49 | float averageLitresPer100km; 50 | uint32_t averageFuelConsumptionSeconds; 51 | ObcConsumScreen::screen screen; 52 | 53 | }; 54 | 55 | #endif // OBCCONSUM_H 56 | -------------------------------------------------------------------------------- /FuelConsumption.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef FUELCONSUMPTION_H 27 | #define FUELCONSUMPTION_H 28 | 29 | #include "Input.h" 30 | #include "InterruptManager.h" 31 | #include "Timer.h" 32 | 33 | class FuelConsumption 34 | { 35 | public: 36 | FuelConsumption(Input& input, InterruptManager& interruptManager); 37 | ~FuelConsumption(); 38 | 39 | float getRpm(); 40 | float getDutyCycle(); 41 | 42 | uint32_t getOntime_us(); 43 | uint32_t getPeriod_us(); 44 | 45 | 46 | private: 47 | void interruptHandler(); 48 | 49 | Input& input; 50 | InterruptManager& interruptManager; 51 | Timer timeSinceLastFallingEdge; 52 | uint32_t period_us; 53 | uint32_t ontime_us; 54 | }; 55 | 56 | #endif // FUELCONSUMPTION_H 57 | -------------------------------------------------------------------------------- /tasks/ObcCheck/ObcCheck.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCCHECK_H 27 | #define OBCCHECK_H 28 | 29 | #include 30 | 31 | namespace ObcCheckState { 32 | enum state {}; 33 | } 34 | 35 | class ObcCheck : public ObcUITask 36 | { 37 | 38 | public: 39 | ObcCheck(OpenOBC& obc); 40 | ~ObcCheck(); 41 | 42 | virtual void runTask(); 43 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 44 | 45 | virtual void wake(); 46 | virtual void sleep(); 47 | 48 | void errorTimeout(); 49 | 50 | private: 51 | std::deque warnings; 52 | bool isValid; 53 | 54 | void updateDisplay(); 55 | void newWarning(ObcCCMBits::bits warning); 56 | 57 | }; 58 | 59 | #endif // OBCCHECK_H 60 | -------------------------------------------------------------------------------- /lib/DS2/Bus.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef BUS_H 27 | #define BUS_H 28 | 29 | #include 30 | #include "Uart.h" 31 | 32 | /** 33 | * The Bus class extends DS2Bus to provide the hardware interface. 34 | * In this implementation for the current hardware, it is necessary 35 | * to intercept and omit the echo from the received data. 36 | */ 37 | class Bus : public DS2Bus 38 | { 39 | public: 40 | Bus(Uart& uart); 41 | 42 | virtual int _bus_read(uint8_t* buffer, int maxLength); 43 | virtual int _bus_write( const uint8_t* data, int dataLength); 44 | virtual bool _bus_readable(); 45 | 46 | void receiveHandler(); 47 | 48 | private: 49 | Uart& uart; 50 | volatile bool readEnabled; 51 | 52 | }; 53 | 54 | #endif // BUS_H 55 | -------------------------------------------------------------------------------- /tasks/ObcDist/ObcDist.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCDIST_H 27 | #define OBCDIST_H 28 | 29 | #include 30 | 31 | namespace ObcDistState 32 | { 33 | enum state {Run, Set}; 34 | } 35 | 36 | class ObcDist : public ObcUITask 37 | { 38 | 39 | public: 40 | ObcDist(OpenOBC& obc); 41 | ~ObcDist(); 42 | 43 | virtual void runTask(); 44 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask); 45 | 46 | virtual void wake(); 47 | virtual void sleep(); 48 | 49 | private: 50 | ObcDistState::state state; 51 | float initialDistanceToTravelKm; 52 | float distanceToTravelKm; 53 | float distanceKmSet; 54 | float odometerStartKm; 55 | float distanceTraveledKm; 56 | }; 57 | 58 | #endif // OBCDIST_H 59 | -------------------------------------------------------------------------------- /ObcLcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCLCD_H 27 | #define OBCLCD_H 28 | #include "SPI.h" 29 | #include "IO.h" 30 | 31 | #define LCD_MAX_CHARACTERS (20) 32 | #define CLOCK_MAX_CHARACTERS (4) 33 | 34 | class ObcLcd 35 | { 36 | public: 37 | ObcLcd(SPI& spi, IO& cs, IO& refresh, IO& unk0, IO& unk1, uint32_t spiClockrateHz = 1000000); 38 | 39 | void printf(char* format, ...); 40 | void printfClock(char* format, ...); 41 | void clear(); 42 | void clearClock(); 43 | 44 | 45 | private: 46 | void update(); 47 | 48 | SPI& spi; 49 | IO& cs; 50 | IO& refresh; 51 | IO& unk0; 52 | IO& unk1; 53 | uint32_t spiClockrate; 54 | 55 | char lcdBuffer[LCD_MAX_CHARACTERS+1]; 56 | char clockBuffer[CLOCK_MAX_CHARACTERS+1]; 57 | }; 58 | 59 | #endif // OBCLCD_H 60 | -------------------------------------------------------------------------------- /lib/I2C/I2C.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | #ifndef I2C_H 28 | #define I2C_H 29 | 30 | #include 31 | #include 32 | 33 | class I2C 34 | { 35 | 36 | public: 37 | I2C(uint8_t sdaPort, uint8_t sdaPin, uint8_t sclPort, uint8_t sclPin, uint32_t hz = 100000); 38 | ~I2C(); 39 | 40 | I2C& setFrequency(uint32_t hz); 41 | uint32_t read(uint8_t address, uint8_t* buffer, uint32_t length); 42 | uint32_t write(uint8_t address, uint8_t* data, uint32_t length); 43 | uint32_t readwrite(uint8_t address, uint8_t* writeData, uint32_t writeLength, uint8_t* readBuffer, uint32_t readLength); 44 | 45 | private: 46 | uint8_t sdaPort; 47 | uint8_t sdaPin; 48 | uint8_t sclPort; 49 | uint8_t sclPin; 50 | uint32_t hz; 51 | LPC_I2C_TypeDef* peripheral; 52 | }; 53 | 54 | #endif // I2C_H 55 | -------------------------------------------------------------------------------- /lib/PCA95xx/PCA95xxPin.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef PCA95XXPIN_H 27 | #define PCA95XXPIN_H 28 | 29 | #include "PCA95xx.h" 30 | #include 31 | 32 | class PCA95xxPin : public IO 33 | { 34 | public: 35 | PCA95xxPin(PCA95xx& pca, uint8_t port, uint8_t pin, bool isOutput = false, bool isOn = false, bool onIsHigh = true); 36 | ~PCA95xxPin(); 37 | 38 | void setState(bool state); 39 | bool getState() const; 40 | void setOpenDrain(bool isOpenDrain) {}; //NOT SUPPORTED 41 | void setInput(); 42 | void setOutput(); 43 | void setPullup() {}; //NOT SUPPORTED 44 | void setPulldown() {}; //NOT SUPPORTED 45 | void setTristate() {}; //NOT SUPPORTED 46 | 47 | private: 48 | PCA95xx& pca; 49 | uint8_t port; 50 | uint8_t pin; 51 | bool state; 52 | uint16_t bitmask; 53 | bool isOutput; 54 | 55 | }; 56 | #endif // PCA95XXPIN_H 57 | -------------------------------------------------------------------------------- /lib/ConfigFile/ConfigFile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef CONFIGFILE_H 27 | #define CONFIGFILE_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | class ConfigFile 34 | { 35 | public: 36 | ConfigFile(const char* filename); 37 | 38 | std::string getValueByName(const std::string& name); 39 | std::string getValueByNameWithDefault(const std::string& name, const char* defaultValue, ...); 40 | void setValueByName(const std::string& name, const std::string& value); 41 | void setValueByName(const std::string& name, const char* format, ...); 42 | bool isSet(const std::string& name); 43 | std::string getFilename() {return this->filename;} 44 | int32_t readConfig(); 45 | int32_t writeConfig(bool overwriteExistingFile = false); 46 | 47 | private: 48 | std::string filename; 49 | std::map parameters; 50 | }; 51 | 52 | #endif // CONFIGFILE_H 53 | -------------------------------------------------------------------------------- /tasks/ObcOdometer/ObcOdometer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "ObcOdometer.h" 27 | #include 28 | #include 29 | 30 | ObcOdometer::ObcOdometer(OpenOBC& obc) : ObcUITask(obc), timer(obc.interruptManager) 31 | { 32 | setDisplay("ObcOdometer"); 33 | currentKm = strtof(obc.config->getValueByNameWithDefault("ObcOdometerCurrentKm", "%f", 0).c_str(), NULL); 34 | } 35 | 36 | ObcOdometer::~ObcOdometer() 37 | { 38 | 39 | } 40 | 41 | void ObcOdometer::wake() 42 | { 43 | runTask(); 44 | } 45 | 46 | void ObcOdometer::sleep() 47 | { 48 | obc.config->setValueByName("ObcOdometerCurrentKm", "%f", currentKm); 49 | } 50 | 51 | 52 | void ObcOdometer::runTask() 53 | { 54 | if(timer.read() >= 1) 55 | { 56 | timer.start(); 57 | currentKm += obc.speed->getKmh() / 60 / 60; 58 | } 59 | obc.currentKm = currentKm; 60 | } 61 | 62 | void ObcOdometer::buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask) 63 | { 64 | 65 | } 66 | -------------------------------------------------------------------------------- /cmsis/system_LPC17xx.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file system_LPC17xx.h 3 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer Header File 4 | * for the NXP LPC17xx Device Series 5 | * @version V1.02 6 | * @date 08. September 2009 7 | * 8 | * @note 9 | * Copyright (C) 2009 ARM Limited. All rights reserved. 10 | * 11 | * @par 12 | * ARM Limited (ARM) is supplying this software for use with Cortex-M 13 | * processor based microcontrollers. This file can be freely distributed 14 | * within development tools that are supporting such ARM based processors. 15 | * 16 | * @par 17 | * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED 18 | * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. 20 | * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR 21 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 22 | * 23 | ******************************************************************************/ 24 | 25 | 26 | #ifndef __SYSTEM_LPC17xx_H 27 | #define __SYSTEM_LPC17xx_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include 34 | 35 | /** @addtogroup LPC17xx_System 36 | * @{ 37 | */ 38 | 39 | 40 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 41 | 42 | 43 | /** 44 | * Initialize the system 45 | * 46 | * @param none 47 | * @return none 48 | * 49 | * @brief Setup the microcontroller system. 50 | * Initialize the System and update the SystemCoreClock variable. 51 | */ 52 | extern void SystemInit (void); 53 | 54 | /** 55 | * Update SystemCoreClock variable 56 | * 57 | * @param none 58 | * @return none 59 | * 60 | * @brief Updates the SystemCoreClock with current core Clock 61 | * retrieved from cpu registers. 62 | */ 63 | extern void SystemCoreClockUpdate (void); 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | #endif /* __SYSTEM_LPC17xx_H */ 73 | -------------------------------------------------------------------------------- /lib/AnalogIn/AnalogIn.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef ANALOGIN_H 27 | #define ANALOGIN_H 28 | 29 | #include 30 | 31 | class AnalogIn 32 | { 33 | public: 34 | AnalogIn(uint8_t port, uint8_t pin, float referenceVoltage = 3.0f, float scaleVoltage = 0.0f, float calibrationScale = 1.0f); 35 | 36 | float read(); 37 | float readPercent(); 38 | uint16_t readBits(); 39 | 40 | uint8_t getPort() const {return port;} 41 | uint8_t getPin() const {return pin;} 42 | float getReferenceVoltage() const {return referenceVoltage;} 43 | float getScaleVoltage() const {return scaleVoltage;} 44 | float getCalibrationScale() const {return calibrationScale;} 45 | float setCalibrationScale(float calibrationScale) {this->calibrationScale = calibrationScale;} 46 | 47 | private: 48 | uint8_t port; 49 | uint8_t pin; 50 | float referenceVoltage; 51 | float scaleVoltage; 52 | float calibrationScale; 53 | ADC_CHANNEL_SELECTION channel; 54 | ADC_TYPE_INT_OPT interrupt; 55 | }; 56 | 57 | #endif // ANALOGIN_H 58 | -------------------------------------------------------------------------------- /lib/IO/IO.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef IO_H 27 | #define IO_H 28 | #include 29 | 30 | class IO 31 | { 32 | public: 33 | IO(uint8_t port, uint8_t pin, bool isOn = false, bool onIsHigh = true); 34 | 35 | virtual void setState(bool on); 36 | virtual bool getState() const; 37 | void on(); 38 | void off(); 39 | void toggle(); 40 | virtual void setOpenDrain(bool isOpenDrain); 41 | virtual void setInput(); 42 | virtual void setOutput(); 43 | virtual void setPullup(); 44 | virtual void setPulldown(); 45 | virtual void setTristate(); 46 | void setOnIsHigh(bool onIsHigh) {this->onIsHigh = onIsHigh;} 47 | bool getOnIsHigh() const {return this->onIsHigh;} 48 | 49 | uint8_t getPort() const {return port;} 50 | uint8_t getPin() const {return pin;} 51 | 52 | IO& operator=(bool state); 53 | IO& operator=(IO& io); 54 | operator bool() const { return getState();} 55 | 56 | protected: 57 | bool onIsHigh; 58 | bool isOn; 59 | 60 | private: 61 | uint8_t port; 62 | uint8_t pin; 63 | bool isOpenDrain; 64 | 65 | }; 66 | 67 | #endif // IO_H 68 | -------------------------------------------------------------------------------- /cmsis/lpc17xx_nvic.h: -------------------------------------------------------------------------------- 1 | /***********************************************************************//** 2 | * @file lpc17xx_nvic.h 3 | * @brief Contains all macro definitions and function prototypes 4 | * support for Nesting Vectored Interrupt firmware library 5 | * on LPC17xx 6 | * @version 2.0 7 | * @date 21. May. 2010 8 | * @author NXP MCU SW Application Team 9 | ************************************************************************** 10 | * Software that is described herein is for illustrative purposes only 11 | * which provides customers with programming information regarding the 12 | * products. This software is supplied "AS IS" without any warranties. 13 | * NXP Semiconductors assumes no responsibility or liability for the 14 | * use of the software, conveys no license or title under any patent, 15 | * copyright, or mask work right to the product. NXP Semiconductors 16 | * reserves the right to make changes in the software without 17 | * notification. NXP Semiconductors also make no representation or 18 | * warranty that such application will be suitable for the specified 19 | * use without further testing or modification. 20 | **************************************************************************/ 21 | 22 | /* Peripheral group ----------------------------------------------------------- */ 23 | /** @defgroup NVIC NVIC 24 | * @ingroup LPC1700CMSIS_FwLib_Drivers 25 | * @{ 26 | */ 27 | 28 | #ifndef LPC17XX_NVIC_H_ 29 | #define LPC17XX_NVIC_H_ 30 | 31 | /* Includes ------------------------------------------------------------------- */ 32 | #include "LPC17xx.h" 33 | #include "lpc_types.h" 34 | 35 | #ifdef __cplusplus 36 | extern "C" 37 | { 38 | #endif 39 | 40 | 41 | /* Public Functions ----------------------------------------------------------- */ 42 | /** @defgroup NVIC_Public_Functions NVIC Public Functions 43 | * @{ 44 | */ 45 | 46 | void NVIC_DeInit(void); 47 | void NVIC_SCBDeInit(void); 48 | void NVIC_SetVTOR(uint32_t offset); 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* LPC17XX_NVIC_H_ */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | /* --------------------------------- End Of File ------------------------------ */ 65 | -------------------------------------------------------------------------------- /CheckControlModule.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "CheckControlModule.h" 27 | #include "delay.h" 28 | 29 | CheckControlModule::CheckControlModule(Input& data, IO& clock, IO& latch, uint8_t disableMask, uint8_t invertMask) : data(data), clock(clock), latch(latch), invertMask(invertMask), disableMask(disableMask) 30 | { 31 | clock = false; 32 | latch = false; 33 | updateStatus(); 34 | } 35 | 36 | void CheckControlModule::task() 37 | { 38 | updateStatus(); 39 | } 40 | 41 | void CheckControlModule::updateStatus() 42 | { 43 | uint8_t status = 0; 44 | clock = true; 45 | latch = true; 46 | for(uint8_t bit = 8; bit; bit--) 47 | { 48 | delay(1); //TODO shorten these delays 49 | clock = false; 50 | delay(1); 51 | clock = true; 52 | delay(1); 53 | if(data) 54 | status += (1<<(bit-1)); 55 | } 56 | latch = false; 57 | clock = false; 58 | rawByte = status; 59 | } 60 | 61 | uint8_t CheckControlModule::getRawByte() 62 | { 63 | return rawByte; 64 | } 65 | 66 | uint8_t CheckControlModule::getCCMByte() 67 | { 68 | return (getRawByte() ^ invertMask) & ~disableMask; 69 | } 70 | -------------------------------------------------------------------------------- /lib/PCA95xx/PCA95xxPin.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | #include "PCA95xxPin.h" 28 | 29 | PCA95xxPin::PCA95xxPin(PCA95xx& pca, uint8_t port, uint8_t pin, bool isOutput, bool isOn, bool onIsHigh) : IO(0xff, 0, isOutput, onIsHigh), pca(pca), port(port), pin(pin), isOutput(isOutput) 30 | { 31 | bitmask = (1 << pin) << (port * 8); 32 | 33 | setState(isOn); 34 | if(isOutput) 35 | setOutput(); 36 | } 37 | 38 | PCA95xxPin::~PCA95xxPin() 39 | { 40 | setInput(); 41 | setState(false); 42 | } 43 | 44 | void PCA95xxPin::setState(bool state) 45 | { 46 | this->state = state; 47 | uint16_t bits = pca.getCurrentOutputBits(); 48 | bits &= ~bitmask; 49 | if(state ^ !onIsHigh) 50 | bits |= bitmask; 51 | pca.writeBits(bits); 52 | } 53 | 54 | bool PCA95xxPin::getState() const 55 | { 56 | if(isOutput) 57 | return state; 58 | uint16_t bits = pca.readBits(); 59 | return (bits >> (port * 8)) & (1< 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "E36Kombi.h" 27 | 28 | #define CMD_QUERY {0x00} 29 | #define CMD_READ_STATUS {0x08} 30 | 31 | #define STATUS_BYTE_COOLANT_TEMPERATURE (5) 32 | 33 | E36Kombi::E36Kombi(DS2& diagnosticInterface) : diag(diagnosticInterface) 34 | { 35 | address = 0x0d; 36 | packetType = DS2_16BIT; 37 | } 38 | 39 | bool E36Kombi::query() 40 | { 41 | const uint8_t cmd[] = CMD_QUERY; 42 | DS2Packet query(address, cmd, sizeof(cmd), packetType); 43 | DS2Packet* reply = diag.query(query); 44 | if(reply != NULL) 45 | { 46 | delete reply; 47 | return true; 48 | } 49 | return false; 50 | } 51 | 52 | float E36Kombi::getCoolantTemperature() 53 | { 54 | const uint8_t cmd[] = CMD_READ_STATUS; 55 | DS2Packet query(address, cmd, sizeof(cmd), packetType); 56 | DS2Packet* reply = diag.query(query, DS2_L); 57 | if(reply != NULL) 58 | { 59 | uint8_t* statusData = reply->getData(); 60 | uint8_t index = STATUS_BYTE_COOLANT_TEMPERATURE; 61 | if(index >= reply->getDataLength()) 62 | return -273.15f; 63 | 64 | uint8_t rawTemp = statusData[index]; 65 | delete reply; 66 | float temperature = coolant_temp_table[rawTemp]; 67 | return temperature; 68 | } 69 | return -273.15f; 70 | } 71 | -------------------------------------------------------------------------------- /tasks/ObcRange/ObcRange.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "ObcRange.h" 27 | #include 28 | 29 | ObcRange::ObcRange(OpenOBC& obc) : ObcUITask(obc) 30 | { 31 | setDisplay("ObcRange"); 32 | } 33 | 34 | ObcRange::~ObcRange() 35 | { 36 | 37 | } 38 | 39 | void ObcRange::wake() 40 | { 41 | runTask(); 42 | } 43 | 44 | void ObcRange::runTask() 45 | { 46 | float fuelLevelLitres = obc.fuelLevel->getLitres(); 47 | float fuelLevelGallons = obc.fuelLevel->getGallons(); 48 | float rangeKm = fuelLevelLitres / obc.averageLitresPer100km * 100; 49 | 50 | if(obc.ui->getMeasurementSystem() == ObcUIMeasurementSystem::Both) 51 | setDisplay("%.0f km %.0f miles", rangeKm, rangeKm * 0.621371f); 52 | if(obc.ui->getMeasurementSystem() == ObcUIMeasurementSystem::Metric) 53 | setDisplay("%.0f km %.1f L", rangeKm, fuelLevelLitres); 54 | if(obc.ui->getMeasurementSystem() == ObcUIMeasurementSystem::Imperial) 55 | setDisplay("%.0f miles %.2f gal", rangeKm * 0.621371f, fuelLevelGallons); 56 | } 57 | 58 | void ObcRange::buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask) 59 | { 60 | if(focus == ObcUITaskFocus::background) 61 | { 62 | if(buttonMask == BUTTON_RANGE_MASK) 63 | obc.ui->setActiveTask(this); 64 | return; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /lib/fatfs/diskio.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "diskio.h" 27 | #include "ff.h" 28 | #include "FatFS.h" 29 | #include 30 | 31 | DSTATUS disk_initialize(BYTE volume) 32 | { 33 | return FatFS::disk_initialise(volume); 34 | } 35 | 36 | DSTATUS disk_status(BYTE volume) 37 | { 38 | return FatFS::disk_status(volume); 39 | } 40 | 41 | DRESULT disk_ioctl(BYTE volume, BYTE ctrl, void* buff) 42 | { 43 | return FatFS::disk_ioctl(volume, ctrl, buff); 44 | } 45 | 46 | DRESULT disk_read(BYTE volume, BYTE* buffer, DWORD startSector, BYTE count) 47 | { 48 | return FatFS::disk_read(volume, buffer, startSector, count); 49 | } 50 | 51 | DRESULT disk_write(BYTE volume, const BYTE* data, DWORD startSector, BYTE count) 52 | { 53 | return FatFS::disk_write(volume, data, startSector, count); 54 | } 55 | 56 | extern "C" DWORD get_fattime() 57 | { 58 | RTC_TIME_Type time; 59 | RTC_GetFullTime(LPC_RTC, &time); 60 | 61 | DWORD fattime = 0; 62 | fattime += ((time.YEAR - 1980) & 0x7f) << 25; 63 | fattime += time.MONTH << 21; 64 | fattime += time.DOM << 16; 65 | fattime += time.HOUR << 11; 66 | fattime += time.MIN << 5; 67 | fattime += time.SEC / 2; 68 | return fattime; 69 | } 70 | -------------------------------------------------------------------------------- /CheckControlModule.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef CHECKCONTROLMODULE_H 27 | #define CHECKCONTROLMODULE_H 28 | #include 29 | #include "Input.h" 30 | #include "IO.h" 31 | 32 | /* thanks veskobx 33 | bit 7 L 1 Brake Light Fail 34 | bit 6 L 1 Brake Light Fail 35 | bit 5 H Tail Light Failure 36 | bit 4 H Lic Plate Light Fail 37 | bit 3 H Low Beam 38 | bit 2 L Coolant level 39 | bit 1 L Washer Fluid 40 | bit 0 H Pulldown 41 | */ 42 | 43 | namespace ObcCCMBits 44 | { 45 | enum bits { 46 | Pulldown = 0x1, 47 | WasherFluid = 0x2, 48 | CoolantLevel = 0x4, 49 | LowBeam = 0x8, 50 | LicensePlateLight = 0x10, 51 | TailLight = 0x20, 52 | BrakeLight1 = 0x40, 53 | BrakeLight2 = 0x80 54 | }; 55 | } 56 | 57 | class CheckControlModule 58 | { 59 | 60 | public: 61 | CheckControlModule(Input& data, IO& clock, IO& latch, uint8_t disableMask = 0x0, uint8_t invertMask = (ObcCCMBits::WasherFluid | ObcCCMBits::CoolantLevel | ObcCCMBits::BrakeLight1 | ObcCCMBits::BrakeLight2)); 62 | 63 | void task(); 64 | 65 | uint8_t getCCMByte(); 66 | uint8_t getRawByte(); 67 | 68 | private: 69 | void updateStatus(); 70 | 71 | Input& data; 72 | IO& clock; 73 | IO& latch; 74 | uint8_t rawByte; 75 | uint8_t invertMask; 76 | uint8_t disableMask; 77 | }; 78 | 79 | #endif // CHECKCONTROLMODULE_H 80 | -------------------------------------------------------------------------------- /lib/MMA845x/MMA845x.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef MMA845X_H 27 | #define MMA845X_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #define MMA845X_REG_CTRL_REG1 (0x2a) 34 | #define MMA845X_REG_CTRL_REG2 (0x2b) 35 | #define MMA845X_REG_CTRL_REG3 (0x2c) 36 | #define MMA845X_REG_CTRL_REG4 (0x2d) 37 | #define MMA845X_REG_CTRL_REG5 (0x2e) 38 | #define MMA845X_REG_OUT_X_MSB (0x01) 39 | #define MMA845X_REG_OUT_X_LSB (0x02) 40 | #define MMA845X_REG_OUT_Y_MSB (0x03) 41 | #define MMA845X_REG_OUT_Y_LSB (0x04) 42 | #define MMA845X_REG_OUT_Z_MSB (0x05) 43 | #define MMA845X_REG_OUT_Z_LSB (0x06) 44 | #define MMA845X_REG_XYZ_DATA_CFG (0x0e) 45 | 46 | class MMA845x 47 | { 48 | 49 | public: 50 | MMA845x(I2C& i2c, uint8_t address, Input& interrupt, InterruptManager& interruptManager, uint32_t hz = 400000); 51 | ~MMA845x(); 52 | 53 | MMA845x& setFrequency(uint32_t hz); 54 | float getX(); 55 | float getY(); 56 | float getZ(); 57 | 58 | MMA845x& enable(); 59 | MMA845x& disable(); 60 | 61 | private: 62 | uint8_t readRegister(uint8_t reg); 63 | void writeRegister(uint8_t reg, uint8_t data); 64 | 65 | I2C& i2c; 66 | uint8_t address; 67 | uint32_t hz; 68 | Input& interrupt; 69 | InterruptManager& interruptManager; 70 | }; 71 | 72 | #endif // MMA845X_H 73 | -------------------------------------------------------------------------------- /lib/Callback/Callback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | #include "Callback.h" 28 | 29 | Callback::Callback() 30 | { 31 | 32 | } 33 | 34 | Callback::~Callback() 35 | { 36 | std::deque*>::iterator function = functions.begin(); 37 | std::deque::iterator timer = timers.begin(); 38 | std::deque::iterator time = times.begin(); 39 | 40 | while(function != functions.end()) 41 | { 42 | delete *function; 43 | delete * timer; 44 | ++function; 45 | ++timer; 46 | } 47 | } 48 | 49 | void Callback::task() 50 | { 51 | std::deque*>::iterator function = functions.begin(); 52 | std::deque::iterator timer = timers.begin(); 53 | std::deque::iterator time = times.begin(); 54 | 55 | while(function != functions.end()) 56 | { 57 | if((*timer)->read_ms() >= *time) 58 | { 59 | FunctionPointer* f = *function; 60 | Timer* t = *timer; 61 | functions.erase(function); 62 | timers.erase(timer); 63 | times.erase(time); 64 | 65 | f->call(); 66 | delete f; 67 | delete t; 68 | 69 | function = functions.begin(); 70 | timer = timers.begin(); 71 | time = times.begin(); 72 | } 73 | else 74 | { 75 | ++function; 76 | ++timer; 77 | ++time; 78 | } 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /lib/E36Diag/E36ZKE4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "E36ZKE4.h" 27 | #include "DS2.h" 28 | 29 | #define CMD_QUERY {0x00} 30 | #define CMD_LOCK {0x0c, 0x5c, 0x01} 31 | #define CMD_UNLOCK {0x0c, 0x5d, 0x01} 32 | #define CMD_TEST {0xa0, 0x88, 0x35, 0x30, 0x95, 0x11, 0x02, 0x01, 0x00, 0x50, 0x93, 0x02, 0x11} 33 | 34 | E36ZKE4::E36ZKE4(DS2& diagnosticInterface) : diag(diagnosticInterface) 35 | { 36 | address = 0x00; 37 | packetType = DS2_8BIT; 38 | } 39 | 40 | E36ZKE4& E36ZKE4::lock() 41 | { 42 | const uint8_t cmd[] = CMD_LOCK; 43 | DS2Packet query(address, cmd, sizeof(cmd), packetType); 44 | DS2Packet* reply = diag.query(query); 45 | if(reply != NULL) 46 | { 47 | delete reply; 48 | } 49 | 50 | return *this; 51 | } 52 | 53 | E36ZKE4& E36ZKE4::unlock() 54 | { 55 | const uint8_t cmd[] = CMD_UNLOCK; 56 | DS2Packet query(address, cmd, sizeof(cmd), packetType); 57 | DS2Packet* reply = diag.query(query); 58 | if(reply != NULL) 59 | { 60 | delete reply; 61 | } 62 | 63 | return *this; 64 | } 65 | 66 | bool E36ZKE4::query() 67 | { 68 | const uint8_t cmd[] = CMD_QUERY; 69 | DS2Packet txPacket(address, cmd, sizeof(cmd), packetType); 70 | DS2Packet* reply = diag.query(txPacket, DS2_BOTH); 71 | if(reply != NULL) 72 | { 73 | delete reply; 74 | return true; 75 | } 76 | return false; 77 | } 78 | -------------------------------------------------------------------------------- /lib/PCA95xx/PCA95xx.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef PCA95XX_H 27 | #define PCA95XX_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | #define PCA95XX_REG_I0 (0) 36 | #define PCA95XX_REG_I1 (1) 37 | #define PCA95XX_REG_O0 (2) 38 | #define PCA95XX_REG_O1 (3) 39 | #define PCA95XX_REG_N0 (4) 40 | #define PCA95XX_REG_N1 (5) 41 | #define PCA95XX_REG_C0 (6) 42 | #define PCA95XX_REG_C1 (7) 43 | 44 | class PCA95xx 45 | { 46 | public: 47 | PCA95xx(I2C& i2c, uint8_t address, Input& interrupt, uint32_t hz = 400000); 48 | ~PCA95xx(); 49 | 50 | uint16_t readBits(); 51 | PCA95xx& writeBits(uint16_t outputBits); 52 | uint16_t getCurrentOutputBits() {return outputBits;} 53 | 54 | void setInput(uint8_t port, uint8_t pin); 55 | void setOutput(uint8_t port, uint8_t pin); 56 | 57 | PCA95xx& setFrequency(uint32_t hz); 58 | 59 | 60 | private: 61 | uint16_t readRegister(uint8_t reg); 62 | void writeRegister(uint8_t reg, uint8_t data); 63 | 64 | I2C& i2c; 65 | uint8_t address; 66 | Input& interrupt; 67 | uint16_t outputBits; 68 | uint32_t hz; 69 | uint16_t currentOutputBits; 70 | InterruptManager& interruptManager; 71 | uint8_t regO0; 72 | uint8_t regO1; 73 | uint8_t regN0; 74 | uint8_t regN1; 75 | uint8_t regC0; 76 | uint8_t regC1; 77 | }; 78 | 79 | #endif // PCA95XX_H 80 | -------------------------------------------------------------------------------- /lib/SDFS/SDFS.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef SDCARD_H 27 | #define SDCARD_H 28 | 29 | #include "SPI.h" 30 | #include "IO.h" 31 | #include "ff.h" 32 | #include "FatFS.h" 33 | 34 | #include 35 | 36 | class SDFS : public FatFSDisk 37 | { 38 | public: 39 | SDFS(SPI& spi, IO& cs, uint32_t spiClockrateHz = 10000000); 40 | ~SDFS(); 41 | 42 | int32_t mount(const char* mountpath); 43 | int32_t unmount(); 44 | std::string getMountpath() {return this->mountpath;} 45 | 46 | virtual int32_t disk_initialise(); 47 | virtual int32_t disk_status(); 48 | virtual int32_t disk_read(uint8_t* buffer, uint32_t startSector, uint32_t count); 49 | virtual int32_t disk_write(const uint8_t* data, uint32_t startSector, uint32_t count); 50 | virtual int32_t disk_ioctl(uint8_t ctrl, void* buffer); 51 | 52 | int disk_sync(); 53 | int disk_sectors(); 54 | 55 | 56 | private: 57 | int _cmd(int cmd, int arg); 58 | int _cmdx(int cmd, int arg); 59 | int _cmd8(); 60 | int _cmd58(); 61 | int initialise_card(); 62 | int initialise_card_v1(); 63 | int initialise_card_v2(); 64 | 65 | int _read(char *buffer, int length); 66 | int _write(const char *buffer, int length); 67 | int _sd_sectors(); 68 | int _sectors; 69 | 70 | 71 | SPI& spi; 72 | IO& cs; 73 | std::string mountpath; 74 | int cdv; 75 | bool isMounted; 76 | uint32_t spiClockrate; 77 | }; 78 | 79 | 80 | #endif // SDCARD_H 81 | -------------------------------------------------------------------------------- /SpeedInput.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "SpeedInput.h" 27 | #include 28 | 29 | #define MAX_PERIOD (2000000) //2000000us == ~0.24mph 30 | 31 | SpeedInput::SpeedInput(Input& input, InterruptManager& interruptManager) : input(input), interruptManager(interruptManager) 32 | { 33 | currentSpeed = 0.0f; 34 | periodTimer = new Timer(interruptManager); 35 | interruptManager.attach(IRQ_EINT3, this, &SpeedInput::interruptHandler); 36 | GPIO_IntEnable(input.getPort(), (1<read_us(); 51 | if(currentPeriod > MAX_PERIOD) 52 | currentSpeed = 0.0f; 53 | return currentSpeed; 54 | } 55 | 56 | void SpeedInput::interruptHandler() 57 | { 58 | if(GPIO_GetIntStatus(input.getPort(), input.getPin(), 1)) 59 | { 60 | uint32_t currentPeriod = periodTimer->read_us(); 61 | periodTimer->start(); 62 | GPIO_ClearInt(input.getPort(), (1< MAX_PERIOD) 64 | currentSpeed = 0.0f; 65 | else 66 | currentSpeed = (float)1000000 / currentPeriod / 4712 * 60 * 60; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /lib/fatfs/FatFS.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | 28 | #ifndef FATFS_H 29 | #define FATFS_H 30 | 31 | #include "diskio.h" 32 | #include "ff.h" 33 | #include 34 | #include 35 | #include 36 | 37 | class FatFSDisk 38 | { 39 | public: 40 | virtual int32_t disk_initialise() = 0; 41 | virtual int32_t disk_status() = 0; 42 | virtual int32_t disk_read(uint8_t* buffer, uint32_t startSector, uint32_t count) = 0; 43 | virtual int32_t disk_write(const uint8_t* data, uint32_t startSector, uint32_t count) = 0; 44 | virtual int32_t disk_ioctl(uint8_t ctrl, void* buffer) = 0; 45 | }; 46 | 47 | class FatFS 48 | { 49 | public: 50 | static DSTATUS disk_mount(FatFSDisk* disk, const char* mountpath); 51 | static DSTATUS disk_umount(FatFSDisk* disk); 52 | static DSTATUS disk_initialise(BYTE volume); 53 | static DSTATUS disk_status(BYTE volume); 54 | static DRESULT disk_read(BYTE volume, BYTE* buffer, DWORD startSector, BYTE count); 55 | static DRESULT disk_write(BYTE volume, const BYTE* data, DWORD startSector, BYTE count); 56 | static DRESULT disk_ioctl(BYTE volume, BYTE ctrl, void* buffer); 57 | 58 | static int8_t volumeFromMountpath(const char* mountpath); 59 | static int errnoFromFResult(FRESULT result); 60 | 61 | private: 62 | static std::vector disks; 63 | static std::vector mountpaths; 64 | static std::vector fatfsStructs; 65 | static std::vector fatfsVolumeNumbersInUse; 66 | }; 67 | 68 | #endif // FATFS_H 69 | -------------------------------------------------------------------------------- /lib/DS2/DS2Bus.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef DS2BUS_H 27 | #define DS2BUS_H 28 | 29 | #define RECEIVE_BUFFER_SIZE (0x100) 30 | #include 31 | 32 | class DS2Bus 33 | { 34 | 35 | public: 36 | DS2Bus(); 37 | 38 | int read(uint8_t* buffer, int maxLength); 39 | int write( const uint8_t* data, int dataLength); 40 | bool readable() {return bufferReadP != bufferWriteP;} 41 | 42 | void receiveHandler(); 43 | 44 | template 45 | void attach(T* classPointer, void (T::*methodPointer)()) 46 | { 47 | if((methodPointer != 0) && (classPointer != 0)) 48 | { 49 | callback.attach(classPointer, methodPointer); 50 | } 51 | } 52 | template 53 | void detach(T* classPointer, void (T::*methodPointer)()) 54 | { 55 | if((methodPointer != 0) && (classPointer != 0)) 56 | { 57 | callback.detach(classPointer, methodPointer); 58 | } 59 | } 60 | void attach(void (*functionPointer)()) 61 | { 62 | callback.attach(functionPointer); 63 | } 64 | void detach(void (*functionPointer)()) 65 | { 66 | callback.detach(functionPointer); 67 | } 68 | 69 | private: 70 | virtual int _bus_read(uint8_t* buffer, int maxLength) = 0; 71 | virtual int _bus_write( const uint8_t* data, int dataLength) = 0; 72 | virtual bool _bus_readable() = 0; 73 | 74 | volatile uint32_t bufferWriteP; 75 | volatile uint32_t bufferReadP; 76 | volatile uint8_t receiveBuffer[RECEIVE_BUFFER_SIZE]; 77 | FunctionPointer callback; 78 | }; 79 | 80 | #endif // DS2BUS_H 81 | -------------------------------------------------------------------------------- /tasks/ObcKmmls/ObcKmmls.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "ObcKmmls.h" 27 | #include 28 | 29 | ObcKmmls::ObcKmmls(OpenOBC& obc) : ObcUITask(obc) 30 | { 31 | 32 | } 33 | 34 | ObcKmmls::~ObcKmmls() 35 | { 36 | 37 | } 38 | 39 | void ObcKmmls::wake() 40 | { 41 | runTask(); 42 | } 43 | 44 | void ObcKmmls::runTask() 45 | { 46 | ObcUIMeasurementSystem::system measurementSystem = obc.ui->getMeasurementSystem(); 47 | if(measurementSystem == ObcUIMeasurementSystem::Metric) 48 | setDisplay("metric"); 49 | else if(measurementSystem == ObcUIMeasurementSystem::Imperial) 50 | setDisplay("imperial"); 51 | else if(measurementSystem == ObcUIMeasurementSystem::Both) 52 | setDisplay("metric / imperial"); 53 | } 54 | 55 | void ObcKmmls::buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask) 56 | { 57 | if(buttonMask == BUTTON_KMMLS_MASK) 58 | { 59 | obc.ui->setActiveTask(this, 1); 60 | if(focus == ObcUITaskFocus::active) 61 | { 62 | ObcUIMeasurementSystem::system measurementSystem = obc.ui->getMeasurementSystem(); 63 | if(measurementSystem == ObcUIMeasurementSystem::Both) 64 | measurementSystem = ObcUIMeasurementSystem::Metric; 65 | else if(measurementSystem == ObcUIMeasurementSystem::Metric) 66 | measurementSystem = ObcUIMeasurementSystem::Imperial; 67 | else if(measurementSystem == ObcUIMeasurementSystem::Imperial) 68 | measurementSystem = ObcUIMeasurementSystem::Both; 69 | obc.ui->setMeasurementSystem(measurementSystem); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /lib/AnalogOut/AnalogOut.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | #include "AnalogOut.h" 28 | #include 29 | #include 30 | 31 | #define MAX_RAW_VALUE (0x3ff) 32 | 33 | AnalogOut::AnalogOut(uint8_t port, uint8_t pin, float maxScaleVoltage) : port(port), pin(pin), maxScaleVoltage(maxScaleVoltage) 34 | { 35 | PINSEL_CFG_Type PinCfg; 36 | if(port == 0 && pin == 26) 37 | { 38 | PinCfg.Funcnum = PINSEL_FUNC_2; 39 | peripheral = LPC_DAC; 40 | } 41 | else 42 | { 43 | //invalid port/pin specified 44 | while(1); 45 | } 46 | 47 | PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; 48 | PinCfg.Pinmode = PINSEL_PINMODE_TRISTATE; 49 | PinCfg.Portnum = port; 50 | PinCfg.Pinnum = pin; 51 | PINSEL_ConfigPin(&PinCfg); 52 | 53 | DAC_Init(peripheral); 54 | currentRawValue = 0; 55 | writeRaw(0x000); 56 | } 57 | 58 | AnalogOut::~AnalogOut() 59 | { 60 | // DAC_DeInit(); 61 | } 62 | 63 | uint16_t AnalogOut::readRaw() 64 | { 65 | return currentRawValue; 66 | } 67 | void AnalogOut::writeRaw(uint16_t rawValue) 68 | { 69 | DAC_UpdateValue(peripheral, rawValue); 70 | } 71 | 72 | float AnalogOut::readVoltage() 73 | { 74 | return (float)readRaw() * maxScaleVoltage; 75 | } 76 | 77 | float AnalogOut::readPercent() 78 | { 79 | return (float)currentRawValue / MAX_RAW_VALUE; 80 | } 81 | 82 | void AnalogOut::writeVoltage(float voltage) 83 | { 84 | writePercent(voltage / maxScaleVoltage); 85 | } 86 | 87 | void AnalogOut::writePercent(float percent) 88 | { 89 | uint16_t rawValue = percent * MAX_RAW_VALUE; 90 | writeRaw(rawValue); 91 | } 92 | -------------------------------------------------------------------------------- /lib/E36Diag/E36Kombi.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | 28 | #ifndef E36KOMBI_H 29 | #define E36KOMBI_H 30 | #include 31 | 32 | const uint8_t coolant_temp_table[256] = {200, 199, 196, 192, 189, 185, 182, 179, 175, 172, 169, 165, 162, 158, 155, 152, 148, 145, 142, 138, 135, 131, 33 | 130, 128, 126, 125, 123, 121, 120, 118, 116, 115, 114, 113, 112, 111, 110, 108, 107, 106, 104, 103, 102, 101, 101, 99, 99, 98, 97, 97, 96, 95, 94, 93, 93, 34 | 92, 91, 90, 89, 88, 88, 87, 86, 85, 85, 84, 84, 83, 83, 82, 81, 81, 80, 80, 79, 79, 78, 77, 76, 76, 75, 75, 74, 74, 73, 72, 72, 71, 71, 71, 70, 70, 69, 69, 69, 68, 35 | 67, 67, 67, 66, 66, 65, 65, 65, 64, 63, 63, 62, 62, 62, 61, 61, 60, 60, 60, 59, 58, 58, 57, 57, 57, 56, 55, 54, 54, 53, 53, 52, 52, 51, 51, 50, 50, 49, 49, 48, 48, 36 | 47, 47, 46, 46, 45, 44, 44, 43, 43, 42, 42, 41, 40, 40, 40, 39, 39, 38, 38, 37, 37, 36, 35, 35, 34, 34, 33, 33, 32, 31, 31, 30, 30, 30, 29, 29, 28, 28, 27, 26, 26, 37 | 25, 25, 24, 24, 23, 22, 22, 21, 21, 20, 20, 20, 19, 19, 18, 17, 17, 16, 16, 15, 15, 15, 15, 15, 14, 14, 14, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 11, 11, 11, 11, 38 | 11, 10, 10, 10, 10, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0}; 39 | 40 | class E36Kombi 41 | { 42 | public: 43 | E36Kombi(DS2& diagnosticInterface); 44 | 45 | bool query(); 46 | float getCoolantTemperature(); //returns coolant temperature in degrees celsius 47 | 48 | private: 49 | DS2& diag; 50 | int address; 51 | DS2PacketType packetType; 52 | }; 53 | 54 | #endif // E36KOMBI_H 55 | -------------------------------------------------------------------------------- /lib/DS2/DS2Bus.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "DS2Bus.h" 27 | #include "DS2.h" 28 | #include "debugpretty.h" 29 | #include 30 | 31 | DS2Bus::DS2Bus() 32 | { 33 | this->bufferReadP = 0; 34 | this->bufferWriteP = 0; 35 | } 36 | 37 | int DS2Bus::read(uint8_t* buffer, int maxLength) 38 | { 39 | int bytesRead = 0; 40 | while(bufferReadP != bufferWriteP && bytesRead < maxLength) 41 | { 42 | buffer[bytesRead++] = receiveBuffer[bufferReadP]; 43 | // DEBUG("reading {0x%02x} from ring buffer: 0x%x 0x%x\r\n", receiveBuffer[bufferReadP], bufferReadP, bufferWriteP); 44 | bufferReadP = (bufferReadP + 1) & (RECEIVE_BUFFER_SIZE - 1); 45 | } 46 | return bytesRead; 47 | } 48 | 49 | int DS2Bus::write(const uint8_t* data, int dataLength) 50 | { 51 | if(_bus_write(data, dataLength) != dataLength) 52 | { 53 | //TODO retry write 54 | } 55 | return dataLength; 56 | } 57 | 58 | void DS2Bus::receiveHandler() 59 | { 60 | //add the new bytes to the ring buffer 61 | if(!_bus_readable()) 62 | return; 63 | 64 | while(_bus_readable()) 65 | { 66 | if(((bufferWriteP + 1) & (RECEIVE_BUFFER_SIZE - 1)) != (bufferReadP & (RECEIVE_BUFFER_SIZE - 1))) 67 | { 68 | uint8_t c; 69 | _bus_read(&c, 1); 70 | receiveBuffer[bufferWriteP] = c; 71 | // DEBUG("putting 0x%02x into DS2Bus ring buffer: 0x%x 0x%x\r\n", receiveBuffer[bufferWriteP], bufferReadP, bufferWriteP); 72 | bufferWriteP = (bufferWriteP + 1) & (RECEIVE_BUFFER_SIZE - 1); 73 | } 74 | else 75 | { 76 | // DEBUG("DS2Bus ring buffer overflow\r\n"); 77 | break; 78 | } 79 | } 80 | 81 | callback.call(); 82 | } 83 | -------------------------------------------------------------------------------- /lib/Debug/Debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef DEBUG_H 27 | #define DEBUG_H 28 | 29 | #include "Uart.h" 30 | #include "Stream.h" 31 | 32 | class Debug : public Stream 33 | { 34 | public: 35 | Debug(int8_t txPort, int8_t txPin, int8_t rxPort, int8_t rxPin, uint32_t baud, InterruptManager* interruptManager); 36 | 37 | void receiveHandler(); 38 | 39 | size_t puts(const void* txbuf, uint32_t buflen); 40 | size_t puts(const char* string); 41 | size_t put(char c); 42 | int32_t get(); 43 | bool readable() {return uart.readable();}; 44 | 45 | template 46 | void attach(T* classPointer, void (T::*methodPointer)()) 47 | { 48 | if((methodPointer != 0) && (classPointer != 0)) 49 | { 50 | callback.attach(classPointer, methodPointer); 51 | } 52 | } 53 | template 54 | void detach(T* classPointer, void (T::*methodPointer)()) 55 | { 56 | if((methodPointer != 0) && (classPointer != 0)) 57 | { 58 | callback.detach(classPointer, methodPointer); 59 | } 60 | } 61 | void attach(void (*functionPointer)()) 62 | { 63 | callback.attach(functionPointer); 64 | } 65 | void detach(void (*functionPointer)()) 66 | { 67 | callback.detach(functionPointer); 68 | } 69 | 70 | private: 71 | virtual void streamIn(const char* string); 72 | virtual void streamIn(uint32_t i); 73 | virtual void streamIn(int32_t i); 74 | virtual void streamIn(float f); 75 | virtual void streamIn(char c); 76 | virtual void streamIn(uint8_t c); 77 | 78 | virtual void streamOut(char* buffer); 79 | virtual void streamOut(char& c); 80 | 81 | Uart uart; 82 | FunctionPointer callback; 83 | 84 | }; 85 | 86 | #endif // DEBUG_H 87 | -------------------------------------------------------------------------------- /lib/Input/Input.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "Input.h" 27 | #include 28 | #include 29 | 30 | Input::Input(uint8_t port, uint8_t pin, bool onIsHigh) : port(port), pin(pin), onIsHigh(onIsHigh) 31 | { 32 | PINSEL_CFG_Type PinCfg; 33 | PinCfg.Funcnum = PINSEL_FUNC_0; 34 | PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; 35 | PinCfg.Pinmode = PINSEL_PINMODE_TRISTATE; 36 | PinCfg.Portnum = this->port; 37 | PinCfg.Pinnum = this->pin; 38 | PINSEL_ConfigPin(&PinCfg); 39 | 40 | GPIO_SetDir(port, (1<onIsHigh) 46 | return (GPIO_ReadValue(this->port) & (1<pin)); 47 | else 48 | return !(GPIO_ReadValue(this->port) & (1<pin)); 49 | } 50 | 51 | void Input::setPullup() 52 | { 53 | PINSEL_CFG_Type PinCfg; 54 | PinCfg.Funcnum = PINSEL_FUNC_0; 55 | PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; 56 | PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; 57 | PinCfg.Portnum = this->port; 58 | PinCfg.Pinnum = this->pin; 59 | PINSEL_ConfigPin(&PinCfg); 60 | } 61 | 62 | void Input::setPulldown() 63 | { 64 | PINSEL_CFG_Type PinCfg; 65 | PinCfg.Funcnum = PINSEL_FUNC_0; 66 | PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; 67 | PinCfg.Pinmode = PINSEL_PINMODE_PULLDOWN; 68 | PinCfg.Portnum = this->port; 69 | PinCfg.Pinnum = this->pin; 70 | PINSEL_ConfigPin(&PinCfg); 71 | } 72 | 73 | void Input::setTristate() 74 | { 75 | PINSEL_CFG_Type PinCfg; 76 | PinCfg.Funcnum = PINSEL_FUNC_0; 77 | PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; 78 | PinCfg.Pinmode = PINSEL_PINMODE_TRISTATE; 79 | PinCfg.Portnum = this->port; 80 | PinCfg.Pinnum = this->pin; 81 | PINSEL_ConfigPin(&PinCfg); 82 | } 83 | -------------------------------------------------------------------------------- /lib/Debug/Debug.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "Debug.h" 27 | 28 | #include "stdio.h" 29 | 30 | #undef getc(_fp) 31 | #undef putc(_fp) 32 | 33 | Debug::Debug(int8_t txPort, int8_t txPin, int8_t rxPort, int8_t rxPin, uint32_t baud, InterruptManager* interruptManager) : uart(txPort, txPin, rxPort, rxPin, baud, UART_PARITY_NONE, interruptManager) 34 | { 35 | uart.attach(this, &Debug::receiveHandler); 36 | } 37 | 38 | void Debug::streamIn(const char* string) 39 | { 40 | uart.puts(string); 41 | } 42 | void Debug::streamIn(uint32_t i) 43 | { 44 | char buffer[16]; 45 | sprintf(buffer, "%i", i); 46 | streamIn(buffer); 47 | } 48 | void Debug::streamIn(int32_t i) 49 | { 50 | char buffer[16]; 51 | sprintf(buffer, "%i", i); 52 | streamIn(buffer); 53 | } 54 | void Debug::streamIn(float f) 55 | { 56 | char buffer[16]; 57 | sprintf(buffer, "%0.1f", f); 58 | streamIn(buffer); 59 | } 60 | void Debug::streamIn(char c) 61 | { 62 | uart.putc(c); 63 | } 64 | void Debug::streamIn(uint8_t c) 65 | { 66 | uart.putc(c); 67 | } 68 | void Debug::streamOut(char* buffer) 69 | { 70 | *buffer = (char)get(); 71 | } 72 | void Debug::streamOut(char& c) 73 | { 74 | c = (char)get(); 75 | } 76 | 77 | void Debug::receiveHandler() 78 | { 79 | callback.call(); 80 | } 81 | 82 | size_t Debug::put(char c) 83 | { 84 | uart.putc(c); 85 | } 86 | 87 | size_t Debug::puts(const void* txbuf, uint32_t buflen) 88 | { 89 | uart.puts(txbuf, buflen); 90 | } 91 | 92 | size_t Debug::puts(const char* string) 93 | { 94 | uart.puts(string); 95 | } 96 | 97 | int32_t Debug::get() 98 | { 99 | return uart.getc(); 100 | } 101 | -------------------------------------------------------------------------------- /ObcUI.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCUI_H 27 | #define OBCUI_H 28 | 29 | #include "ObcUITask.h" 30 | #include "ObcLcd.h" 31 | #include "ObcKeypad.h" 32 | #include 33 | #include 34 | #include 35 | 36 | namespace ObcUIMeasurementSystem 37 | { 38 | enum system {Metric, Imperial, Both}; 39 | } 40 | 41 | class ObcUI 42 | { 43 | 44 | public: 45 | ObcUI(ObcLcd& lcd, ObcKeypad& keypad, ConfigFile& config); 46 | ~ObcUI(); 47 | 48 | void handleButtonEvent(uint32_t buttonMask); 49 | 50 | void task(); 51 | 52 | void addTask(ObcUITask* task); 53 | void removeTask(ObcUITask* task); 54 | 55 | void setActiveTask(ObcUITask* task, float forSeconds = 0); 56 | ObcUITask* getActiveTask() {return activeTask;} 57 | ObcUITask* popActiveTask(ObcUITask* task = NULL); 58 | void setActiveTaskClock(ObcUITask* task) {activeTaskClock = task;} 59 | ObcUITask* getActiveTaskClock() {return activeTaskClock;} 60 | 61 | void registerButton(ObcUITask* task, ObcUITaskFocus::type focus, uint32_t buttonMask); 62 | void unregisterButton(ObcUITask* task, ObcUITaskFocus::type focus, uint32_t buttonMask); 63 | 64 | void wake(); 65 | void sleep(); 66 | 67 | void setMeasurementSystem(ObcUIMeasurementSystem::system system) {measurementSystem = system;} 68 | ObcUIMeasurementSystem::system getMeasurementSystem() {return measurementSystem;} 69 | 70 | Callback callback; 71 | ConfigFile& config; 72 | 73 | private: 74 | ObcLcd& lcd; 75 | ObcKeypad& keypad; 76 | std::vector tasks; 77 | ObcUITask* activeTask; 78 | ObcUITask* activeTaskClock; 79 | ObcUIMeasurementSystem::system measurementSystem; 80 | Timer activeTaskTimeout; 81 | std::deque activeTaskList; 82 | }; 83 | 84 | #endif // OBCUI_H 85 | -------------------------------------------------------------------------------- /ObcUITask.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | #include "ObcUITask.h" 28 | 29 | ObcUITask::ObcUITask(OpenOBC& obc) : obc(obc) 30 | { 31 | setDisplayRefreshPeriod(0.100); 32 | _isActive = false; 33 | activeTaskTimeout = 0; 34 | } 35 | 36 | ObcUITask::~ObcUITask() 37 | { 38 | 39 | } 40 | 41 | void ObcUITask::registerButton(ObcUITaskFocus::type focus, uint32_t buttonMask) 42 | { 43 | //FIXME TODO 44 | } 45 | 46 | void ObcUITask::unregisterButton(ObcUITaskFocus::type focus, uint32_t buttonMask) 47 | { 48 | //FIXME TODO 49 | } 50 | 51 | void ObcUITask::setDisplay(char* format, ...) 52 | { 53 | va_list args; 54 | va_start(args, format); 55 | vsnprintf(displayBuffer, sizeof(displayBuffer), format, args); 56 | va_end(args); 57 | } 58 | 59 | void ObcUITask::setDisplayClock(char* format, ... ) 60 | { 61 | va_list args; 62 | va_start(args, format); 63 | vsnprintf(displayClockBuffer, sizeof(displayClockBuffer), format, args); 64 | va_end(args); 65 | } 66 | 67 | void ObcUITask::createButtonEvent(ObcUITaskFocus::type focus, uint32_t buttonMask) 68 | { 69 | if(focus == ObcUITaskFocus::active) 70 | buttonEventsActive.push_back(buttonMask); 71 | else if(focus == ObcUITaskFocus::background) 72 | buttonEventsBackground.push_back(buttonMask); 73 | } 74 | 75 | void ObcUITask::runButtonEvents() 76 | { 77 | for(std::vector::iterator buttonMask = buttonEventsActive.begin(); buttonMask != buttonEventsActive.end(); buttonEventsActive.erase(buttonMask)) 78 | { 79 | buttonHandler(ObcUITaskFocus::active, *buttonMask); 80 | } 81 | for(std::vector::iterator buttonMask = buttonEventsBackground.begin(); buttonMask != buttonEventsBackground.end(); buttonEventsBackground.erase(buttonMask)) 82 | { 83 | buttonHandler(ObcUITaskFocus::background, *buttonMask); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /lib/DS2/DS2Packet.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef DS2PACKET_H 27 | #define DS2PACKET_H 28 | 29 | #include 30 | #include 31 | #include "DS2Bus.h" 32 | 33 | typedef enum 34 | { 35 | DS2_K, 36 | DS2_L, 37 | DS2_BOTH 38 | } DS2BusType; 39 | 40 | typedef enum 41 | { 42 | DS2_8BIT, 43 | DS2_16BIT 44 | } DS2PacketType; 45 | 46 | typedef enum 47 | { 48 | DS2_PSTATUS_OK, 49 | DS2_PSTATUS_INVALID, 50 | DS2_PSTATUS_CHECKSUM_ERROR, 51 | DS2_PSTATUS_INSUFFICIENT_DATA 52 | } DS2PStatus; 53 | 54 | class DS2Packet 55 | { 56 | public: 57 | DS2Packet(DS2PacketType type = DS2_16BIT); 58 | DS2Packet(int address, DS2PacketType type = DS2_16BIT); 59 | DS2Packet(int address, const uint8_t* data, int dataLength, DS2PacketType type = DS2_16BIT); 60 | DS2Packet(const uint8_t* rawPacket, int length, DS2PacketType type); 61 | ~DS2Packet(); 62 | 63 | int getAddress() const {return address;} 64 | uint8_t* getData() const {return dataPtr;} 65 | int getDataLength() const {return dataLength;} 66 | uint8_t getChecksum() const {return checksum;} 67 | int getPacketLength() const {return packetLength;} 68 | DS2PacketType getType() const {return type;} 69 | uint8_t* getRawPacket() const {return rawPacketPtr;} 70 | DS2PStatus getStatus(); 71 | 72 | DS2Packet& setAddress(int address); 73 | DS2Packet& setData(const uint8_t* data, uint16_t length); 74 | 75 | DS2PStatus packetFromRawPacket(const uint8_t* rawPacketData, uint16_t length, DS2PacketType type); 76 | void printPacket(FILE* file) const; 77 | 78 | private: 79 | void generatePacket(); 80 | uint8_t _checksum() const; 81 | 82 | int address; 83 | uint16_t packetLength; 84 | uint16_t dataLength; 85 | uint8_t* dataPtr; 86 | uint8_t* rawPacketPtr; 87 | uint8_t checksum; 88 | DS2PacketType type; 89 | }; 90 | 91 | #endif // DS2PACKET_H 92 | -------------------------------------------------------------------------------- /lib/Stream/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef STREAM_H 27 | #define STREAM_H 28 | #include 29 | 30 | class Stream 31 | { 32 | friend Stream& operator<<(Stream& stream, const char* string) 33 | { 34 | stream.streamIn(string); 35 | return stream; 36 | } 37 | friend Stream& operator<<(Stream& stream, uint32_t i) 38 | { 39 | stream.streamIn(i); 40 | return stream; 41 | } 42 | friend Stream& operator<<(Stream& stream, int32_t i) 43 | { 44 | stream.streamIn(i); 45 | return stream; 46 | } 47 | friend Stream& operator<<(Stream& stream, float f) 48 | { 49 | stream.streamIn(f); 50 | return stream; 51 | } 52 | friend Stream& operator<<(Stream& stream, char c) 53 | { 54 | stream.streamIn(c); 55 | return stream; 56 | } 57 | friend Stream& operator<<(Stream& stream, uint8_t c) 58 | { 59 | stream.streamIn(c); 60 | return stream; 61 | } 62 | 63 | friend Stream& operator>>(Stream& stream, char* buffer) 64 | { 65 | stream.streamOut(buffer); 66 | return stream; 67 | } 68 | friend Stream& operator>>(Stream& stream, char& c) 69 | { 70 | stream.streamOut(c); 71 | return stream; 72 | } 73 | 74 | public: 75 | virtual void seek(uint32_t offset) {}; 76 | virtual uint32_t write(const void* data, uint32_t length) {}; 77 | virtual uint32_t read(void* buffer, uint32_t maxlength) {}; 78 | virtual uint32_t gets(void* buffer, uint32_t maxlength) {}; 79 | 80 | private: 81 | virtual void streamIn(const char* string) = 0; 82 | virtual void streamIn(uint32_t i) = 0; 83 | virtual void streamIn(int32_t i) = 0; 84 | virtual void streamIn(float f) = 0; 85 | virtual void streamIn(char c) = 0; 86 | virtual void streamIn(uint8_t c) = 0; 87 | 88 | virtual void streamOut(char* buffer) = 0; 89 | virtual void streamOut(char& c) = 0; 90 | 91 | 92 | }; 93 | 94 | #endif // STREAM_H 95 | -------------------------------------------------------------------------------- /lib/fatfs/diskio.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | / Low level disk interface modlue include file (C)ChaN, 2012 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO_DEFINED 6 | #define _DISKIO_DEFINED 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define _USE_WRITE 1 /* 1: Enable disk_write function */ 13 | #define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */ 14 | 15 | #include "integer.h" 16 | 17 | 18 | /* Status of Disk Functions */ 19 | typedef BYTE DSTATUS; 20 | 21 | /* Results of Disk Functions */ 22 | typedef enum { 23 | RES_OK = 0, /* 0: Successful */ 24 | RES_ERROR, /* 1: R/W Error */ 25 | RES_WRPRT, /* 2: Write Protected */ 26 | RES_NOTRDY, /* 3: Not Ready */ 27 | RES_PARERR /* 4: Invalid Parameter */ 28 | } DRESULT; 29 | 30 | 31 | /*---------------------------------------*/ 32 | /* Prototypes for disk control functions */ 33 | 34 | 35 | DSTATUS disk_initialize (BYTE); 36 | DSTATUS disk_status (BYTE); 37 | DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); 38 | DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); 39 | DRESULT disk_ioctl (BYTE, BYTE, void*); 40 | 41 | 42 | /* Disk Status Bits (DSTATUS) */ 43 | #define STA_NOINIT 0x01 /* Drive not initialized */ 44 | #define STA_NODISK 0x02 /* No medium in the drive */ 45 | #define STA_PROTECT 0x04 /* Write protected */ 46 | 47 | 48 | /* Command code for disk_ioctrl fucntion */ 49 | 50 | /* Generic command (used by FatFs) */ 51 | #define CTRL_SYNC 0 /* Flush disk cache (for write functions) */ 52 | #define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */ 53 | #define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */ 54 | #define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */ 55 | #define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */ 56 | 57 | /* Generic command (not used by FatFs) */ 58 | #define CTRL_POWER 5 /* Get/Set power status */ 59 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 60 | #define CTRL_EJECT 7 /* Eject media */ 61 | #define CTRL_FORMAT 8 /* Create physical format on the media */ 62 | 63 | /* MMC/SDC specific ioctl command */ 64 | #define MMC_GET_TYPE 10 /* Get card type */ 65 | #define MMC_GET_CSD 11 /* Get CSD */ 66 | #define MMC_GET_CID 12 /* Get CID */ 67 | #define MMC_GET_OCR 13 /* Get OCR */ 68 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 69 | 70 | /* ATA/CF specific ioctl command */ 71 | #define ATA_GET_REV 20 /* Get F/W revision */ 72 | #define ATA_GET_MODEL 21 /* Get model name */ 73 | #define ATA_GET_SN 22 /* Get serial number */ 74 | 75 | 76 | /* MMC card type flags (MMC_GET_TYPE) */ 77 | #define CT_MMC 0x01 /* MMC ver 3 */ 78 | #define CT_SD1 0x02 /* SD ver 1 */ 79 | #define CT_SD2 0x04 /* SD ver 2 */ 80 | #define CT_SDC (CT_SD1|CT_SD2) /* SD */ 81 | #define CT_BLOCK 0x08 /* Block addressing */ 82 | 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /tasks/ObcSpeed/ObcSpeed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "ObcSpeed.h" 27 | #include 28 | #include 29 | 30 | ObcSpeed::ObcSpeed(OpenOBC& obc) : ObcUITask(obc) 31 | { 32 | averageSpeedKmh = strtof(obc.config->getValueByNameWithDefault("ObcSpeedAverageKmh", "%f", 0).c_str(), NULL); 33 | averageSeconds = 300; 34 | } 35 | 36 | ObcSpeed::~ObcSpeed() 37 | { 38 | 39 | } 40 | 41 | void ObcSpeed::wake() 42 | { 43 | runTask(); 44 | } 45 | 46 | void ObcSpeed::runTask() 47 | { 48 | float currentSpeedKmh = obc.speed->getKmh(); 49 | if(averageSpeedKmh == 0) 50 | averageSpeedKmh = currentSpeedKmh; 51 | static Timer timer(obc.interruptManager); 52 | if(timer.read() >= 1) 53 | { 54 | timer.start(); 55 | float alpha = 1.0 / averageSeconds; 56 | averageSpeedKmh = alpha * currentSpeedKmh + (1.0 - alpha) * averageSpeedKmh; 57 | } 58 | 59 | obc.averageKmh = averageSpeedKmh; 60 | 61 | if(obc.ui->getMeasurementSystem() == ObcUIMeasurementSystem::Metric) 62 | setDisplay("% 3u km/h % 3u avg", (uint32_t)currentSpeedKmh, (uint32_t)averageSpeedKmh); 63 | else if(obc.ui->getMeasurementSystem() == ObcUIMeasurementSystem::Imperial) 64 | setDisplay("% 3u mph % 3u avg", (uint32_t)(currentSpeedKmh * 0.621371), (uint32_t)(averageSpeedKmh * 0.621371)); 65 | else if(obc.ui->getMeasurementSystem() == ObcUIMeasurementSystem::Both) 66 | setDisplay("avg: % 3u kmh % 3u mph", (uint32_t)averageSpeedKmh, (uint32_t)(averageSpeedKmh * 0.621371)); 67 | 68 | } 69 | 70 | void ObcSpeed::buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask) 71 | { 72 | if(focus == ObcUITaskFocus::background) 73 | { 74 | if(buttonMask == BUTTON_SPEED_MASK) 75 | obc.ui->setActiveTask(this); 76 | return; 77 | } 78 | 79 | if(buttonMask == BUTTON_SET_MASK) 80 | { 81 | averageSpeedKmh = obc.speed->getKmh(); 82 | } 83 | } 84 | 85 | void ObcSpeed::sleep() 86 | { 87 | obc.config->setValueByName("ObcSpeedAverageKmh", "%f", averageSpeedKmh); 88 | } 89 | -------------------------------------------------------------------------------- /lib/MMA845x/MMA845x.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | #include "MMA845x.h" 28 | 29 | MMA845x::MMA845x(I2C& i2c, uint8_t address, Input& interrupt, InterruptManager& interruptManager, uint32_t hz) : interruptManager(interruptManager), i2c(i2c), address(address), hz(hz), interrupt(interrupt) 30 | { 31 | enable(); 32 | } 33 | 34 | MMA845x::~MMA845x() 35 | { 36 | disable(); 37 | } 38 | 39 | uint8_t MMA845x::readRegister(uint8_t reg) 40 | { 41 | i2c.setFrequency(hz); 42 | uint8_t writeBuf; 43 | uint8_t readBuf; 44 | writeBuf = reg; 45 | if(i2c.readwrite(address, &writeBuf, 1, &readBuf, 1) == 1) 46 | { 47 | return readBuf; 48 | } 49 | return 0xff; 50 | } 51 | 52 | void MMA845x::writeRegister(uint8_t reg, uint8_t data) 53 | { 54 | i2c.setFrequency(hz); 55 | uint8_t buf[2]; 56 | buf[0] = reg; 57 | buf[1] = data; 58 | i2c.write(address, buf, 2); 59 | } 60 | 61 | MMA845x& MMA845x::setFrequency(uint32_t hz) 62 | { 63 | this->hz = hz; 64 | return *this; 65 | } 66 | 67 | MMA845x& MMA845x::enable() 68 | { 69 | writeRegister(MMA845X_REG_CTRL_REG1, 0x01); //enable sampling 70 | 71 | } 72 | 73 | MMA845x& MMA845x::disable() 74 | { 75 | writeRegister(MMA845X_REG_CTRL_REG1, 0x00); //disable sampling 76 | } 77 | 78 | float MMA845x::getX() 79 | { 80 | int16_t x = ((int16_t)readRegister(MMA845X_REG_OUT_X_MSB) << 8); 81 | x /= (1<<4); 82 | x += (uint16_t)readRegister(MMA845X_REG_OUT_X_LSB) >> 4; 83 | return (float)x / 2048 * 2; 84 | } 85 | 86 | float MMA845x::getY() 87 | { 88 | int16_t y = ((int16_t)readRegister(MMA845X_REG_OUT_Y_MSB) << 8); 89 | y /= (1<<4); 90 | y += (uint16_t)readRegister(MMA845X_REG_OUT_Y_LSB) >> 4; 91 | return (float)y / 2048 * 2; 92 | } 93 | 94 | float MMA845x::getZ() 95 | { 96 | int16_t z = ((int16_t)readRegister(MMA845X_REG_OUT_Z_MSB) << 8); 97 | z /= (1<<4); 98 | z += (int16_t)readRegister(MMA845X_REG_OUT_Z_LSB) >> 4; 99 | return (float)z / 2048 * 2; 100 | } 101 | -------------------------------------------------------------------------------- /tasks/ObcMemo/ObcMemo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "ObcMemo.h" 27 | #include 28 | 29 | using namespace ObcMemoState; 30 | 31 | ObcMemo::ObcMemo(OpenOBC& obc) : ObcUITask(obc) 32 | { 33 | setDisplay("ObcMemo"); 34 | std::string configState = obc.config->getValueByNameWithDefault("ObcMemoState", "Voltage"); 35 | if(configState == "Voltage") 36 | state = Voltage; 37 | else if(configState == "FreeMem") 38 | state = FreeMem; 39 | else if(configState == "Accelerometer") 40 | state = Accelerometer; 41 | } 42 | 43 | ObcMemo::~ObcMemo() 44 | { 45 | 46 | } 47 | 48 | void ObcMemo::wake() 49 | { 50 | runTask(); 51 | } 52 | 53 | void ObcMemo::sleep() 54 | { 55 | std::string configState; 56 | if(state == Voltage) 57 | configState = "Voltage"; 58 | else if(state == FreeMem) 59 | configState = "FreeMem"; 60 | else if(state == Accelerometer) 61 | configState = "Accelerometer"; 62 | obc.config->setValueByName("ObcMemoState", configState); 63 | } 64 | 65 | void ObcMemo::runTask() 66 | { 67 | if(state == Voltage) 68 | setDisplay("%.2fV %.2fV %.2fV", obc.batteryVoltage->read(), obc.analogIn1->read(), obc.analogIn2->read()); 69 | else if(state == FreeMem) 70 | setDisplay("free memory: %i", get_mem_free()); 71 | else if(state == Accelerometer) 72 | { 73 | float x = obc.accel->getX(); 74 | float y = obc.accel->getY(); 75 | float z = obc.accel->getZ(); 76 | setDisplay("x% 2.2f y% 2.2f z% 2.2f", x, y, z); 77 | } 78 | } 79 | 80 | void ObcMemo::buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask) 81 | { 82 | if(focus == ObcUITaskFocus::background) 83 | { 84 | if(buttonMask == BUTTON_MEMO_MASK) 85 | obc.ui->setActiveTask(this); 86 | return; 87 | } 88 | 89 | if(buttonMask == BUTTON_MEMO_MASK) 90 | { 91 | if(state == Voltage) 92 | state = FreeMem; 93 | else if(state == FreeMem) 94 | state = Accelerometer; 95 | else if(state == Accelerometer) 96 | state = Voltage; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /ObcUITask.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef OBCUITASK_H 27 | #define OBCUITASK_H 28 | 29 | #include 30 | #include 31 | #include "OpenOBC.h" 32 | #include 33 | 34 | class OpenOBC; 35 | 36 | namespace ObcUITaskFocus { 37 | enum type {active, background}; 38 | } 39 | 40 | class ObcUITask 41 | { 42 | 43 | public: 44 | ObcUITask(OpenOBC& obc); 45 | ~ObcUITask(); 46 | 47 | //required methods 48 | virtual void runTask() = 0; //mainloop code goes here 49 | virtual void buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask) = 0; //this is called once for each button press 50 | 51 | //optional methods 52 | virtual void wake() {}; //run once on startup before entering main loop 53 | virtual void sleep() {}; //run once just before switching to sleep state 54 | 55 | char* getDisplay() {return displayBuffer;} 56 | char* getDisplayClock() {return displayClockBuffer;} 57 | float getDisplayRefreshPeriod() {return displayRefreshPeriod;} 58 | void setActive(bool isActive) {_isActive = isActive;} 59 | void runButtonEvents(); 60 | 61 | void createButtonEvent(ObcUITaskFocus::type focus, uint32_t buttonMask); 62 | void setActiveTaskTimeout(float seconds) {activeTaskTimeout = seconds;} 63 | float getActiveTaskTimeout() {return activeTaskTimeout;} 64 | 65 | protected: 66 | void registerButton(ObcUITaskFocus::type focus, uint32_t buttonMask); 67 | void unregisterButton(ObcUITaskFocus::type focus, uint32_t buttonMask); 68 | void setDisplay(char* format, ...); 69 | void setDisplayClock(char* format, ...); 70 | bool isActive() {return _isActive;} 71 | void setDisplayRefreshPeriod(float seconds) {displayRefreshPeriod = seconds;} 72 | 73 | OpenOBC& obc; 74 | 75 | private: 76 | std::vector buttonEventsActive; 77 | std::vector buttonEventsBackground; 78 | char displayBuffer[21]; 79 | char displayClockBuffer[5]; 80 | bool _isActive; 81 | float displayRefreshPeriod; 82 | float activeTaskTimeout; 83 | }; 84 | 85 | #endif // OBCUITASK_H 86 | -------------------------------------------------------------------------------- /lib/Uart/Uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef UART_H 27 | #define UART_H 28 | 29 | #include "FunctionPointer.h" 30 | 31 | #include 32 | #include 33 | #include 34 | #include "InterruptManager.h" 35 | 36 | 37 | #define RB_SIZE (256) 38 | #define RB_MASK (RB_SIZE - 1) 39 | 40 | class Uart 41 | { 42 | public: 43 | Uart(int8_t txPort, int8_t txPin, int8_t rxPort, int8_t rxPin, uint32_t baud, UART_PARITY_Type parity, InterruptManager* interruptManager); 44 | 45 | bool available(); 46 | bool readable(); 47 | bool writable(); 48 | void begin(int32_t baud); 49 | void listen(); 50 | void flush(); 51 | void setBaud(uint32_t baud); 52 | 53 | size_t getdata(uint8_t* rxbuf, uint32_t buflen); 54 | char getc(); 55 | size_t putc(char c); 56 | size_t puts(const char* string); 57 | size_t puts(const void* txbuf, uint32_t buflen); 58 | size_t printf(const char* format, ...); 59 | 60 | 61 | void receiveHandler(); 62 | 63 | 64 | template 65 | void attach(T* classPointer, void (T::*methodPointer)()) 66 | { 67 | if((methodPointer != 0) && (classPointer != 0)) 68 | { 69 | callback.attach(classPointer, methodPointer); 70 | } 71 | } 72 | template 73 | void detach(T* classPointer, void (T::*methodPointer)()) 74 | { 75 | if((methodPointer != 0) && (classPointer != 0)) 76 | { 77 | callback.detach(classPointer, methodPointer); 78 | } 79 | } 80 | void attach(void (*functionPointer)()) 81 | { 82 | callback.attach(functionPointer); 83 | } 84 | void detach(void (*functionPointer)()) 85 | { 86 | callback.detach(functionPointer); 87 | } 88 | 89 | private: 90 | LPC_UART_TypeDef* uartPeripheral; 91 | int8_t txPort; 92 | int8_t txPin; 93 | int8_t rxPort; 94 | int8_t rxPin; 95 | volatile uint32_t bufferWriteP; 96 | volatile uint32_t bufferReadP; 97 | char ringBuffer[RB_SIZE]; 98 | uint32_t baud; 99 | FunctionPointer callback; 100 | 101 | 102 | }; 103 | 104 | 105 | #endif // UART_H 106 | -------------------------------------------------------------------------------- /lib/DS2/Bus.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "Bus.h" 27 | #include "delay.h" 28 | #include "debugpretty.h" 29 | #include 30 | 31 | Bus::Bus(Uart& uart) : uart(uart) 32 | { 33 | readEnabled = true; 34 | uart.attach(this, &Bus::receiveHandler); 35 | } 36 | 37 | int Bus::_bus_read(uint8_t* buffer, int maxLength) 38 | { 39 | if(!readEnabled) 40 | return 0; 41 | return uart.getdata(buffer, maxLength); 42 | } 43 | 44 | int Bus::_bus_write(const uint8_t* data, int dataLength) 45 | { 46 | //disable reading so the echo stays here 47 | readEnabled = false; 48 | 49 | uart.puts(data, dataLength); 50 | delay(10); //FIXME more intelligent delay 51 | 52 | //receive and check echo 53 | uint8_t* echo = new uint8_t[dataLength]; 54 | int length = uart.getdata(echo, dataLength); 55 | if(length > 0 && length < dataLength) 56 | { 57 | //wait a bit longer and check for the echo again 58 | delay(20); 59 | length = length + uart.getdata(echo + length, dataLength - length); 60 | } 61 | readEnabled = true; 62 | if(length == dataLength) 63 | { 64 | if(!memcmp(data, echo, dataLength)) 65 | { 66 | // DEBUG("echo ok\r\n"); 67 | } 68 | else 69 | { 70 | DEBUG("echo not ok\r\n"); //TODO flush rx buffer and retry 71 | } 72 | } 73 | 74 | else 75 | { 76 | DEBUG("no echo\r\n"); 77 | //TODO flush rx buffer and retry 78 | } 79 | delete[] echo; 80 | 81 | //if there's still more data after the echo, call the handler to receive it 82 | if(uart.readable()) 83 | { 84 | DEBUG("still have data after echo; calling DS2Bus::receiveHandler()\r\n"); 85 | 86 | uart.detach(this, &Bus::receiveHandler); 87 | this->DS2Bus::receiveHandler(); //incoming bytes can be missed if they arrive during here; they won't be processed until the next interrupt 88 | uart.attach(this, &Bus::receiveHandler); 89 | } 90 | return length; 91 | } 92 | 93 | bool Bus::_bus_readable() 94 | { 95 | if(!readEnabled) 96 | return false; 97 | return uart.readable(); 98 | } 99 | 100 | void Bus::receiveHandler() 101 | { 102 | if(!readEnabled) 103 | return; 104 | this->DS2Bus::receiveHandler(); 105 | } 106 | -------------------------------------------------------------------------------- /lib/Callback/Callback.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | #ifndef CALLBACK_H 28 | #define CALLBACK_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | class Callback 36 | { 37 | 38 | public: 39 | Callback(); 40 | ~Callback(); 41 | void task(); 42 | 43 | 44 | template 45 | uint32_t addCallback(T* classPointer, void (T::*methodPointer)(), uint32_t milliseconds) 46 | { 47 | if((methodPointer != 0) && (classPointer != 0)) 48 | { 49 | functions.push_back(new FunctionPointer); 50 | functions.back()->attach(classPointer, methodPointer); 51 | 52 | timers.push_back(new Timer); 53 | times.push_back(milliseconds); 54 | } 55 | } 56 | template 57 | uint32_t addRepeatingCallback(T* classPointer, void (T::*methodPointer)(), uint32_t milliseconds) 58 | { 59 | if((methodPointer != 0) && (classPointer != 0)) 60 | { 61 | functions.push_back(new FunctionPointer); 62 | functions.back()->attach(classPointer, methodPointer); 63 | 64 | timers.push_back(new Timer); 65 | times.push_back(milliseconds); 66 | } 67 | } 68 | uint32_t addCallback(void (*functionPointer)()) 69 | { 70 | functions.push_back(new FunctionPointer); 71 | functions.back()->attach(functionPointer); 72 | } 73 | 74 | template 75 | uint32_t deleteCallback(T* classPointer, void (T::*methodPointer)()) 76 | { 77 | if((methodPointer != 0) && (classPointer != 0)) 78 | { 79 | for(uint16_t numFunctions = functions.size(); numFunctions; --numFunctions) 80 | { 81 | functions[numFunctions-1]->detach(classPointer, methodPointer); 82 | } 83 | } 84 | } 85 | uint32_t deleteCallback(void (*functionPointer)()) 86 | { 87 | for(uint16_t numFunctions = functions.size(); numFunctions; --numFunctions) 88 | { 89 | functions[numFunctions-1]->detach(functionPointer); 90 | } 91 | } 92 | 93 | private: 94 | std::deque*> functions; 95 | std::deque timers; 96 | std::deque times; 97 | }; 98 | 99 | #endif // CALLBACK_H 100 | -------------------------------------------------------------------------------- /cmsis/debug_frmwrk.h: -------------------------------------------------------------------------------- 1 | /***********************************************************************//** 2 | * @file debug_frmwrk.h 3 | * @brief Contains some utilities that used for debugging through UART 4 | * @version 2.0 5 | * @date 21. May. 2010 6 | * @author NXP MCU SW Application Team 7 | *---------------------------------------------------------------------------- 8 | * Software that is described herein is for illustrative purposes only 9 | * which provides customers with programming information regarding the 10 | * products. This software is supplied "AS IS" without any warranties. 11 | * NXP Semiconductors assumes no responsibility or liability for the 12 | * use of the software, conveys no license or title under any patent, 13 | * copyright, or mask work right to the product. NXP Semiconductors 14 | * reserves the right to make changes in the software without 15 | * notification. NXP Semiconductors also make no representation or 16 | * warranty that such application will be suitable for the specified 17 | * use without further testing or modification. 18 | **********************************************************************/ 19 | 20 | #ifndef DEBUG_FRMWRK_H_ 21 | #define DEBUG_FRMWRK_H_ 22 | 23 | //#include 24 | #include "lpc17xx_uart.h" 25 | 26 | #define USED_UART_DEBUG_PORT 0 27 | 28 | #if (USED_UART_DEBUG_PORT==0) 29 | #define DEBUG_UART_PORT LPC_UART0 30 | #elif (USED_UART_DEBUG_PORT==1) 31 | #define DEBUG_UART_PORT LPC_UART1 32 | #endif 33 | 34 | #define _DBG(x) _db_msg(DEBUG_UART_PORT, x) 35 | #define _DBG_(x) _db_msg_(DEBUG_UART_PORT, x) 36 | #define _DBC(x) _db_char(DEBUG_UART_PORT, x) 37 | #define _DBD(x) _db_dec(DEBUG_UART_PORT, x) 38 | #define _DBD16(x) _db_dec_16(DEBUG_UART_PORT, x) 39 | #define _DBD32(x) _db_dec_32(DEBUG_UART_PORT, x) 40 | #define _DBH(x) _db_hex(DEBUG_UART_PORT, x) 41 | #define _DBH16(x) _db_hex_16(DEBUG_UART_PORT, x) 42 | #define _DBH32(x) _db_hex_32(DEBUG_UART_PORT, x) 43 | #define _DG _db_get_char(DEBUG_UART_PORT) 44 | //void _printf (const char *format, ...); 45 | 46 | extern void (*_db_msg)(LPC_UART_TypeDef *UARTx, const void *s); 47 | extern void (*_db_msg_)(LPC_UART_TypeDef *UARTx, const void *s); 48 | extern void (*_db_char)(LPC_UART_TypeDef *UARTx, uint8_t ch); 49 | extern void (*_db_dec)(LPC_UART_TypeDef *UARTx, uint8_t decn); 50 | extern void (*_db_dec_16)(LPC_UART_TypeDef *UARTx, uint16_t decn); 51 | extern void (*_db_dec_32)(LPC_UART_TypeDef *UARTx, uint32_t decn); 52 | extern void (*_db_hex)(LPC_UART_TypeDef *UARTx, uint8_t hexn); 53 | extern void (*_db_hex_16)(LPC_UART_TypeDef *UARTx, uint16_t hexn); 54 | extern void (*_db_hex_32)(LPC_UART_TypeDef *UARTx, uint32_t hexn); 55 | extern uint8_t (*_db_get_char)(LPC_UART_TypeDef *UARTx); 56 | 57 | void UARTPutChar (LPC_UART_TypeDef *UARTx, uint8_t ch); 58 | void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str); 59 | void UARTPuts_(LPC_UART_TypeDef *UARTx, const void *str); 60 | void UARTPutDec(LPC_UART_TypeDef *UARTx, uint8_t decnum); 61 | void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum); 62 | void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum); 63 | void UARTPutHex (LPC_UART_TypeDef *UARTx, uint8_t hexnum); 64 | void UARTPutHex16 (LPC_UART_TypeDef *UARTx, uint16_t hexnum); 65 | void UARTPutHex32 (LPC_UART_TypeDef *UARTx, uint32_t hexnum); 66 | uint8_t UARTGetChar (LPC_UART_TypeDef *UARTx); 67 | void debug_frmwrk_init(void); 68 | 69 | #endif /* DEBUG_FRMWRK_H_ */ 70 | -------------------------------------------------------------------------------- /lib/AnalogIn/AnalogIn.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "AnalogIn.h" 27 | #include 28 | #include 29 | 30 | AnalogIn::AnalogIn(uint8_t port, uint8_t pin, float referenceVoltage, float scaleVoltage, float calibrationScale) : port(port), pin(pin), referenceVoltage(referenceVoltage), scaleVoltage(scaleVoltage) 31 | { 32 | if(this->scaleVoltage == 0.0f) 33 | this->scaleVoltage = referenceVoltage; 34 | this->calibrationScale = calibrationScale; 35 | 36 | uint8_t funcnum; 37 | if(port == 0 && pin == 23) 38 | { 39 | funcnum = 1; 40 | channel = ADC_CHANNEL_0; 41 | interrupt = ADC_ADINTEN0; 42 | } 43 | else if(port == 0 && pin == 24) 44 | { 45 | funcnum = 1; 46 | channel = ADC_CHANNEL_1; 47 | interrupt = ADC_ADINTEN1; 48 | } 49 | else if(port == 0 && pin == 25) 50 | { 51 | funcnum = 1; 52 | channel = ADC_CHANNEL_2; 53 | interrupt = ADC_ADINTEN2; 54 | } 55 | else if(port == 0 && pin == 26) 56 | { 57 | funcnum = 1; 58 | channel = ADC_CHANNEL_3; 59 | interrupt = ADC_ADINTEN3; 60 | } 61 | else if(port == 1 && pin == 30) 62 | { 63 | funcnum = 3; 64 | channel = ADC_CHANNEL_4; 65 | interrupt = ADC_ADINTEN4; 66 | } 67 | else if(port == 1 && pin == 31) 68 | { 69 | funcnum = 3; 70 | channel = ADC_CHANNEL_5; 71 | interrupt = ADC_ADINTEN5; 72 | } 73 | else 74 | { 75 | //invalid port/pin 76 | fprintf(stderr, "invalid pin specified\r\n"); 77 | throw; 78 | } 79 | 80 | PINSEL_CFG_Type PinCfg; 81 | PinCfg.Funcnum = funcnum; 82 | PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; 83 | PinCfg.Pinmode = PINSEL_PINMODE_TRISTATE; 84 | PinCfg.Portnum = port; 85 | PinCfg.Pinnum = pin; 86 | PINSEL_ConfigPin(&PinCfg); 87 | 88 | ADC_Init(LPC_ADC, 200000); 89 | ADC_IntConfig(LPC_ADC,interrupt,DISABLE); 90 | } 91 | 92 | float AnalogIn::read() 93 | { 94 | return readPercent() * scaleVoltage * calibrationScale; 95 | } 96 | 97 | float AnalogIn::readPercent() 98 | { 99 | return (float)readBits() / 0xfff; 100 | } 101 | 102 | uint16_t AnalogIn::readBits() 103 | { 104 | ADC_ChannelCmd(LPC_ADC, channel, ENABLE); 105 | ADC_StartCmd(LPC_ADC, ADC_START_NOW); 106 | while(!(ADC_ChannelGetStatus(LPC_ADC, channel, ADC_DATA_DONE))); 107 | uint16_t bits = ADC_ChannelGetData(LPC_ADC, channel); 108 | ADC_ChannelCmd(LPC_ADC, channel, DISABLE); 109 | return bits; 110 | } 111 | -------------------------------------------------------------------------------- /FuelConsumption.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "FuelConsumption.h" 27 | #include 28 | 29 | #define MAX_PERIOD (500000) //us 30 | 31 | FuelConsumption::FuelConsumption(Input& input, InterruptManager& interruptManager) : input(input), interruptManager(interruptManager), timeSinceLastFallingEdge(interruptManager) 32 | { 33 | period_us = 0; 34 | ontime_us = 0; 35 | interruptManager.attach(IRQ_EINT3, this, &FuelConsumption::interruptHandler); 36 | GPIO_IntEnable(input.getPort(), (1< MAX_PERIOD) 68 | return 0; 69 | return period_us; 70 | } 71 | 72 | uint32_t FuelConsumption::getOntime_us() 73 | { 74 | if(timeSinceLastFallingEdge.read_us() > MAX_PERIOD) 75 | return 0; 76 | return ontime_us; 77 | } 78 | 79 | void FuelConsumption::interruptHandler() 80 | { 81 | bool edgeIsRising; 82 | if(GPIO_GetIntStatus(input.getPort(), input.getPin(), 1)) //falling edge 83 | edgeIsRising = false; 84 | else if(GPIO_GetIntStatus(input.getPort(), input.getPin(), 0)) //rising edge 85 | edgeIsRising = true; 86 | else 87 | return; 88 | // if(isLast) 89 | { 90 | GPIO_ClearInt(input.getPort(), (1<period_us = timeSinceLastFallingEdge.read_us(); 96 | timeSinceLastFallingEdge.start(); 97 | return; 98 | } 99 | 100 | if(edgeIsRising) 101 | { 102 | this->ontime_us = timeSinceLastFallingEdge.read_us(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /ObcLcd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "ObcLcd.h" 27 | 28 | #include 29 | #include 30 | #include "delay.h" 31 | #include 32 | 33 | ObcLcd::ObcLcd(SPI& spi, IO& cs, IO& refresh, IO& unk0, IO& unk1, uint32_t spiClockrateHz) : spi(spi), cs(cs), refresh(refresh), unk0(unk0), unk1(unk1), spiClockrate(spiClockrateHz) 34 | { 35 | this->cs = true; 36 | this->refresh = false; 37 | this->unk0 = true; 38 | this->unk1 = false; 39 | *lcdBuffer = '\0'; 40 | *clockBuffer = '\0'; 41 | } 42 | 43 | void ObcLcd::printf(char* format, ...) 44 | { 45 | va_list args; 46 | va_start(args, format); 47 | vsnprintf(lcdBuffer, LCD_MAX_CHARACTERS+1, format, args); 48 | va_end(args); 49 | update(); 50 | } 51 | 52 | void ObcLcd::printfClock(char* format, ...) 53 | { 54 | va_list args; 55 | va_start(args, format); 56 | vsnprintf(clockBuffer, CLOCK_MAX_CHARACTERS+1, format, args); 57 | va_end(args); 58 | update(); 59 | } 60 | 61 | void ObcLcd::clear() 62 | { 63 | printf(""); 64 | } 65 | 66 | void ObcLcd::clearClock() 67 | { 68 | printfClock(""); 69 | } 70 | 71 | void ObcLcd::update() 72 | { 73 | spi.setClockRate(spiClockrate); 74 | cs = false; 75 | 76 | //center the lcd text within LCD_MAX_CHARACTERS characters 77 | uint32_t length = (LCD_MAX_CHARACTERS - strlen(lcdBuffer)); 78 | uint32_t spaces = length / 2; 79 | if(length % 2) //if an odd length makes it uncenterable, shifting to the right looks better 80 | ++spaces; 81 | for(uint8_t i = spaces; i; i--) 82 | spi.readWrite(' '); 83 | 84 | //send the lcd buffer; fill to LCD_MAX_CHARACTERS characters with spaces 85 | uint8_t i; 86 | for(i = 0; i < (LCD_MAX_CHARACTERS - spaces); i++) 87 | { 88 | if(lcdBuffer[i] == '\0') 89 | break; 90 | spi.readWrite((uint8_t)lcdBuffer[i]); 91 | } 92 | while(i++ < (LCD_MAX_CHARACTERS - spaces)) 93 | spi.readWrite(' '); 94 | 95 | //send the clock buffer; fill to CLOCK_MAX_CHARACTERS characters with spaces 96 | for(i = 0; i < CLOCK_MAX_CHARACTERS; i++) 97 | { 98 | if(clockBuffer[i] == '\0') 99 | break; 100 | spi.readWrite((uint8_t)clockBuffer[i]); 101 | } 102 | while(i++ < CLOCK_MAX_CHARACTERS) 103 | spi.readWrite(' '); 104 | 105 | //I forget what or why this is 106 | spi.readWrite(0x00); 107 | spi.readWrite(' '); 108 | spi.readWrite(' '); 109 | spi.readWrite(' '); 110 | 111 | refresh = true; 112 | delay(1); 113 | refresh = false; 114 | cs = true; 115 | } 116 | 117 | 118 | -------------------------------------------------------------------------------- /lib/RTC/RTC.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "RTC.h" 27 | 28 | #include "lpc17xx_rtc.h" 29 | 30 | RTC::RTC() 31 | { 32 | RTC_Init(LPC_RTC); 33 | RTC_ResetClockTickCounter(LPC_RTC); 34 | RTC_Cmd(LPC_RTC, ENABLE); 35 | 36 | 37 | /* Setting Timer calibration 38 | * Calibration value = 5s; 39 | * Direction = Forward calibration 40 | * So after each 5s, calibration logic can periodically adjust the time counter by 41 | * incrementing the counter by 2 instead of 1 42 | */ 43 | RTC_CalibConfig(LPC_RTC, 9000, RTC_CALIB_DIR_FORWARD); 44 | //leave calibration disabled 45 | RTC_CalibCounterCmd(LPC_RTC, DISABLE); 46 | } 47 | 48 | //TODO utc, timezone, dst 49 | void RTC::getTime(RTC_TIME_Type* time) 50 | { 51 | RTC_GetFullTime(LPC_RTC, time); 52 | } 53 | 54 | void RTC::setTime(RTC_TIME_Type* time) 55 | { 56 | RTC_SetFullTime(LPC_RTC, time); 57 | } 58 | 59 | uint8_t RTC::getSecond() 60 | { 61 | RTC_GetFullTime(LPC_RTC, &time); 62 | return time.SEC; 63 | } 64 | 65 | uint8_t RTC::getMinute() 66 | { 67 | RTC_GetFullTime(LPC_RTC, &time); 68 | return time.MIN; 69 | } 70 | 71 | uint8_t RTC::getHour() 72 | { 73 | RTC_GetFullTime(LPC_RTC, &time); 74 | return time.HOUR; 75 | } 76 | 77 | uint8_t RTC::getDay() 78 | { 79 | RTC_GetFullTime(LPC_RTC, &time); 80 | return time.DOM; 81 | } 82 | 83 | uint8_t RTC::getMonth() 84 | { 85 | RTC_GetFullTime(LPC_RTC, &time); 86 | return time.MONTH; 87 | } 88 | 89 | uint16_t RTC::getYear() 90 | { 91 | RTC_GetFullTime(LPC_RTC, &time); 92 | return time.YEAR; 93 | } 94 | 95 | void RTC::setSecond(uint8_t second) 96 | { 97 | second %= 60; 98 | RTC_SetTime(LPC_RTC, RTC_TIMETYPE_SECOND, second); 99 | } 100 | 101 | void RTC::setMinute(uint8_t minute) 102 | { 103 | minute %= 60; 104 | RTC_SetTime(LPC_RTC, RTC_TIMETYPE_SECOND, 0); 105 | RTC_SetTime(LPC_RTC, RTC_TIMETYPE_MINUTE, minute); 106 | } 107 | 108 | void RTC::setHour(uint8_t hour) 109 | { 110 | hour %= 24; 111 | RTC_SetTime(LPC_RTC, RTC_TIMETYPE_HOUR, hour); 112 | } 113 | 114 | void RTC::setDay(uint8_t day) 115 | { 116 | day %= 32; 117 | if(day == 0) 118 | day = 1; 119 | RTC_SetTime(LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, day); 120 | } 121 | 122 | void RTC::setMonth(uint8_t month) 123 | { 124 | month %= 13; 125 | if(month == 0) 126 | month = 1; 127 | RTC_SetTime(LPC_RTC, RTC_TIMETYPE_MONTH, month); 128 | } 129 | 130 | void RTC::setYear(uint16_t year) 131 | { 132 | year %= 4096; 133 | RTC_SetTime(LPC_RTC, RTC_TIMETYPE_YEAR, year); 134 | } 135 | -------------------------------------------------------------------------------- /lib/PCA95xx/PCA95xx.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | 27 | #include "PCA95xx.h" 28 | 29 | PCA95xx::PCA95xx(I2C& i2c, uint8_t address, Input& interrupt, uint32_t hz) : interruptManager(interruptManager), i2c(i2c), address(address), interrupt(interrupt), hz(hz) 30 | { 31 | regO0 = 0x00; 32 | regO1 = 0x00; 33 | regC0 = 0xff; 34 | regC1 = 0xff; 35 | regN0 = 0x00; 36 | regN1 = 0x00; 37 | writeRegister(PCA95XX_REG_C0, regC0); 38 | writeRegister(PCA95XX_REG_C1, regC1); 39 | writeRegister(PCA95XX_REG_N0, regN0); 40 | writeRegister(PCA95XX_REG_N1, regN1); 41 | outputBits = 0x0000; 42 | writeBits(outputBits); 43 | } 44 | 45 | PCA95xx::~PCA95xx() 46 | { 47 | writeRegister(PCA95XX_REG_C0, 0xff); 48 | writeRegister(PCA95XX_REG_C1, 0xff); 49 | writeRegister(PCA95XX_REG_N0, 0x00); 50 | writeRegister(PCA95XX_REG_N1, 0x00); 51 | writeBits(0x0000); 52 | } 53 | 54 | uint16_t PCA95xx::readRegister(uint8_t reg) 55 | { 56 | i2c.setFrequency(hz); 57 | uint8_t writeBuf[1]; 58 | uint8_t readBuf[2]; 59 | writeBuf[0] = reg; 60 | if(i2c.readwrite(address, writeBuf, 1, readBuf, 2) == sizeof(readBuf)) 61 | { 62 | uint16_t bits = readBuf[0]; 63 | bits += (readBuf[1] << 8); 64 | return bits; 65 | } 66 | return 0xffff; 67 | } 68 | 69 | void PCA95xx::writeRegister(uint8_t reg, uint8_t data) 70 | { 71 | i2c.setFrequency(hz); 72 | uint8_t buf[2]; 73 | buf[0] = reg; 74 | buf[1] = data; 75 | i2c.write(address, buf, 2); 76 | } 77 | 78 | uint16_t PCA95xx::readBits() 79 | { 80 | return readRegister(PCA95XX_REG_I0); 81 | } 82 | 83 | PCA95xx& PCA95xx::writeBits(uint16_t outputBits) 84 | { 85 | this->outputBits = outputBits; 86 | i2c.setFrequency(hz); 87 | 88 | uint8_t buf[3]; 89 | buf[0] = PCA95XX_REG_O0; 90 | buf[1] = outputBits & 0xff; 91 | buf[2] = (outputBits >> 8) & 0xff; 92 | i2c.write(address, buf, 3); 93 | return *this; 94 | } 95 | 96 | PCA95xx& PCA95xx::setFrequency(uint32_t hz) 97 | { 98 | this->hz = hz; 99 | return *this; 100 | } 101 | 102 | void PCA95xx::setInput(uint8_t port, uint8_t pin) 103 | { 104 | if(port == 0) 105 | { 106 | regC0 |= (1< 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "ObcTimer.h" 27 | #include 28 | #include 29 | 30 | using namespace ObcTimerState; 31 | 32 | ObcTimer::ObcTimer(OpenOBC& obc) : ObcUITask(obc), timer(obc.interruptManager) 33 | { 34 | setDisplay("ObcTimer"); 35 | state = Inactive; 36 | timedValue = strtof(obc.config->getValueByNameWithDefault("ObcTimerTimedValue", "%f", 0).c_str(), NULL); 37 | setDisplayRefreshPeriod(0.100); 38 | } 39 | 40 | ObcTimer::~ObcTimer() 41 | { 42 | 43 | } 44 | 45 | void ObcTimer::wake() 46 | { 47 | runTask(); 48 | } 49 | 50 | void ObcTimer::sleep() 51 | { 52 | obc.config->setValueByName("ObcTimerTimedValue", "%f", timedValue); 53 | } 54 | 55 | void ObcTimer::runTask() 56 | { 57 | if(state == Armed && obc.speed->getKmh() != 0) 58 | { 59 | timer.start(); 60 | state = Timing; 61 | } 62 | 63 | if(state == Timing && obc.speed->getKmh() >= 100) 64 | { 65 | timedValue = timer.read(); 66 | state = Inactive; 67 | } 68 | 69 | if(state == Timing && timer.read() >= 100) 70 | { 71 | state = Inactive; 72 | } 73 | 74 | if(state == Inactive) 75 | { 76 | // setDisplay("0-100 % 3u km/h % 2.1f", 0, timedValue); 77 | //work around broken printf float implementation 78 | uint32_t seconds = timedValue; 79 | uint32_t tenths = (timedValue - seconds) * 10; 80 | setDisplay("0-100 % 3u km/h % 2u.%u", 0, seconds, tenths); 81 | } 82 | else if(state == Armed) 83 | { 84 | setDisplay("0-100 % 3u km/h % 2.1f", 0, 0); 85 | } 86 | else if(state == Timing) 87 | { 88 | // setDisplay("0-100 % 3u km/h % 2.1f", (uint32_t)(obc.speed->getKmh()), timer.read()); 89 | //work around broken printf float implementation 90 | float currentTimerValue = timer.read(); 91 | uint32_t seconds = currentTimerValue; 92 | uint32_t tenths = (currentTimerValue - seconds) * 10; 93 | setDisplay("0-100 % 3u km/h % 2u.%u", (uint32_t)(obc.speed->getKmh()), seconds, tenths); 94 | } 95 | 96 | if(state == Armed) 97 | obc.timerLed->on(); 98 | else 99 | obc.timerLed->off(); 100 | //TODO flash led while Timing 101 | } 102 | 103 | void ObcTimer::buttonHandler(ObcUITaskFocus::type focus, uint32_t buttonMask) 104 | { 105 | if(focus == ObcUITaskFocus::background) 106 | { 107 | if(buttonMask == BUTTON_TIMER_MASK) 108 | obc.ui->setActiveTask(this); 109 | return; 110 | } 111 | 112 | if(buttonMask == BUTTON_SET_MASK) 113 | { 114 | if(state == Inactive && obc.speed->getKmh() < 10) 115 | { 116 | state = Armed; 117 | } 118 | else if(state == Armed) 119 | { 120 | state = Inactive; 121 | } 122 | else if(state == Timing) 123 | { 124 | state = Inactive; 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /lib/Timer/Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef TIMER_H 27 | #define TIMER_H 28 | 29 | #include 30 | #include "InterruptManager.h" 31 | #include 32 | #include 33 | 34 | #define TIMER_PERIPHERAL (LPC_TIM0) 35 | #define TIMER_INTERRUPT (TIMER0_IRQn) 36 | #define TIMER_MANAGED_INTERRUPT (IRQ_TIMER0) 37 | 38 | class Timer 39 | { 40 | public: 41 | Timer(); 42 | Timer(InterruptManager& interruptManager); //required to use timer past 171 second overflow 43 | ~Timer(); 44 | void start(); 45 | float read(); 46 | uint32_t read_raw(); 47 | uint32_t read_ms(); 48 | uint32_t read_us(); 49 | void interruptHandler(); 50 | 51 | uint32_t getOverflowCount() {return overflows;} 52 | void setStartCount(uint32_t count) {startCount = count;} 53 | 54 | template 55 | uint32_t setCallback(T* classPointer, void (T::*methodPointer)(), uint32_t milliseconds) 56 | { 57 | setCallbackUs(classPointer, methodPointer, milliseconds * 1000); 58 | } 59 | template 60 | uint32_t setCallbackUs(T* classPointer, void (T::*methodPointer)(), uint32_t microseconds) 61 | { 62 | if(interruptManager == NULL) 63 | { 64 | DEBUG("interruptManager required\r\n"); 65 | while(1); 66 | } 67 | if((methodPointer != 0) && (classPointer != 0)) 68 | { 69 | callbackFunction->detachAll(); 70 | callbackFunction->attach(classPointer, methodPointer); 71 | setCallbackDelay(microseconds); 72 | callbackActive = true; 73 | } 74 | } 75 | 76 | uint32_t setCallback(void (*functionPointer)(), uint32_t milliseconds) 77 | { 78 | setCallbackUs(functionPointer, milliseconds * 1000); 79 | } 80 | uint32_t setCallbackUs(void (*functionPointer)(), uint32_t microseconds) 81 | { 82 | callbackFunction->detachAll(); 83 | callbackFunction->attach(functionPointer); 84 | setCallbackDelay(microseconds); 85 | callbackActive = true; 86 | } 87 | void deleteCallback(); 88 | 89 | 90 | protected: 91 | void initialize(); 92 | void setCallbackDelay(uint32_t microseconds); 93 | void _insertMatch(uint32_t timerMatchValue); 94 | void _removeMatch(uint32_t timerMatchValue); 95 | void _updateMatch(); 96 | void _setMatch(uint32_t timerMatchValue); 97 | void _clearMatch(); 98 | uint32_t _computeMatchValue(uint32_t microseconds); 99 | 100 | static bool timerInitialized; 101 | uint32_t startCount; 102 | volatile uint32_t overflows; 103 | InterruptManager* interruptManager; 104 | bool overflowed; //FIXME this is really dirty 105 | FunctionPointer* callbackFunction; 106 | uint32_t callbackDelay; 107 | uint32_t matchValue; 108 | static std::list matchValues; 109 | bool callbackActive; 110 | uint32_t frozenTimerValue; 111 | }; 112 | 113 | #endif // TIMER_H 114 | -------------------------------------------------------------------------------- /FuelLevel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "FuelLevel.h" 27 | #include "Timer.h" 28 | #include 29 | 30 | #define TIMEOUT (10000) //us 31 | #define BIT_PERIOD (4000) //us 32 | 33 | FuelLevel::FuelLevel(Input& dataPin, InterruptManager& interruptManager) : dataPin(dataPin), interruptManager(interruptManager) 34 | { 35 | decilitres = 0; 36 | interruptManager.attach(IRQ_EINT3, this, &FuelLevel::interruptHandler); 37 | GPIO_IntEnable(dataPin.getPort(), (1<= BIT_PERIOD * 15) //packet timeout 73 | haveStartBit = false; 74 | 75 | if(!haveStartBit) //start new packet 76 | { 77 | haveStartBit = true; 78 | currentLogicState = false; 79 | currentBit = 0; 80 | rxData = 0; 81 | return; 82 | } 83 | //else continue existing packet 84 | 85 | //count up the number of bit periods since the last edge and set the bits 86 | if(currentBit > 0) 87 | currentBit = currentBit; 88 | uint8_t state = currentLogicState ? 1 : 0; 89 | while(currentPeriod >= BIT_PERIOD/2) 90 | { 91 | rxData += (state<>= 1; //shift off the start bit 112 | this->decilitres = rxData; 113 | } 114 | if(currentBit >= 13) //end of packet; set up to start a new packet at the next edge 115 | { 116 | haveStartBit = false; 117 | } 118 | 119 | currentLogicState = edgeIsHigh; 120 | } 121 | -------------------------------------------------------------------------------- /lib/DS2/DS2.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef DS2_H 27 | #define DS2_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include "DS2Packet.h" 33 | #include "DS2Bus.h" 34 | #include "Timer.h" 35 | 36 | #define MAX_PACKET_COUNT (64) 37 | #define MAX_PACKET_LENGTH (RECEIVE_BUFFER_SIZE) 38 | 39 | #if MAX_PACKET_LENGTH > RECEIVE_BUFFER_SIZE 40 | #error MAX_PACKET_LENGTH cannot be greater than RECEIVE_BUFFER_SIZE 41 | #endif 42 | 43 | class DS2 44 | { 45 | public: 46 | DS2(DS2Bus& k, DS2Bus& l); 47 | 48 | /** 49 | * Write a packet to the specified bus 50 | * 51 | * @param txPacket packet to be transmitted 52 | * @param txBus which bus to transmit on 53 | * @return true if packet was transmitted successfully 54 | */ 55 | bool write(const DS2Packet& txPacket, DS2BusType txBus = DS2_BOTH); 56 | 57 | /** 58 | * Returns a packet from the specified packet buffer, or null if none. 59 | * 60 | * @param bus which packet buffer to read from 61 | * @return pointer to new packet 62 | */ 63 | DS2Packet* read(DS2BusType bus = DS2_BOTH); 64 | 65 | /** 66 | * Sends a packet on the specified bus and waits for a reply. 67 | * Returns a new packet on the heap or null if no reply. 68 | * Return pointer must be deleted if not null. 69 | * 70 | * @param txPacket packet to be transmitted 71 | * @param txBus which bus to transmit on 72 | * @param timeout_ms time to wait for reply 73 | * @return reply packet 74 | */ 75 | DS2Packet* query(const DS2Packet& txPacket, DS2BusType txBus = DS2_BOTH, int timeout_ms = 200); 76 | 77 | /** 78 | * Check for new packets in receive buffers, validate them, pop them onto 79 | * the packet buffer, and call any attached callbacks. 80 | * Must be run often enough to prevent receive buffer overruns. 81 | */ 82 | void task(); 83 | 84 | void receiveHandlerK(); 85 | void receiveHandlerL(); 86 | 87 | template 88 | void attach(T* classPointer, void (T::*methodPointer)()) 89 | { 90 | if((methodPointer != 0) && (classPointer != 0)) 91 | { 92 | callback.attach(classPointer, methodPointer); 93 | } 94 | } 95 | template 96 | void detach(T* classPointer, void (T::*methodPointer)()) 97 | { 98 | if((methodPointer != 0) && (classPointer != 0)) 99 | { 100 | callback.detach(classPointer, methodPointer); 101 | } 102 | } 103 | void attach(void (*functionPointer)()) 104 | { 105 | callback.attach(functionPointer); 106 | } 107 | void detach(void (*functionPointer)()) 108 | { 109 | callback.detach(functionPointer); 110 | } 111 | 112 | private: 113 | DS2Packet* getPacketFromBus(DS2BusType bus); 114 | 115 | DS2Bus& k; 116 | DS2Bus& l; 117 | Timer receiveTimeoutK; 118 | Timer receiveTimeoutL; 119 | std::deque packetBufferK; 120 | std::deque packetBufferL; 121 | FunctionPointer callback; 122 | volatile bool taskEnabled; 123 | bool interceptPackets; 124 | std::deque* bufferK; 125 | std::deque* bufferL; 126 | }; 127 | 128 | #endif // DS2_H 129 | --------------------------------------------------------------------------------