├── .gitignore ├── .travis.yml ├── Arduino_Pedelec_Controller ├── BMP085.cpp ├── BMP085.h ├── CMakeLists.txt ├── DSPC01_nano.cpp ├── DSPC01_nano.h ├── DallasTemp.cpp ├── DallasTemp.h ├── Display │ ├── .DS_Store │ ├── BaseComponent.cpp │ ├── BaseComponent.h │ ├── BaseView.cpp │ ├── BaseView.h │ ├── Components.cpp │ ├── Components.h │ ├── DataModel.cpp │ ├── DataModel.h │ ├── DiagramComponent.cpp │ ├── DiagramComponent.h │ ├── DisplayController.cpp │ ├── DisplayController.h │ ├── Font │ │ ├── Size2 │ │ │ ├── %.png │ │ │ ├── 0.png │ │ │ ├── 1.png │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.png │ │ │ ├── 8.png │ │ │ ├── 9.png │ │ │ ├── a.png │ │ │ ├── ae.png │ │ │ ├── b.png │ │ │ ├── c.png │ │ │ ├── d.png │ │ │ ├── e.png │ │ │ ├── f.png │ │ │ ├── g.png │ │ │ ├── h.png │ │ │ ├── i.png │ │ │ ├── j.png │ │ │ ├── k.png │ │ │ ├── l.png │ │ │ ├── m.png │ │ │ ├── n.png │ │ │ ├── o.png │ │ │ ├── oe.png │ │ │ ├── p.png │ │ │ ├── point.png │ │ │ ├── q.png │ │ │ ├── r.png │ │ │ ├── s.png │ │ │ ├── slash.png │ │ │ ├── t.png │ │ │ ├── u.png │ │ │ ├── ue.png │ │ │ ├── v.png │ │ │ ├── w.png │ │ │ ├── x.png │ │ │ ├── y.png │ │ │ └── z.png │ │ └── Size4 │ │ │ ├── 0.png │ │ │ ├── 1.png │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.png │ │ │ ├── 8.png │ │ │ ├── 9.png │ │ │ └── point.png │ ├── IconComponent.cpp │ ├── IconComponent.h │ ├── Images │ │ ├── Demo Main screen.JPG │ │ ├── Demo Menu.JPG │ │ ├── edit-main1.jpg │ │ ├── edit-main2.JPG │ │ └── edit-main3.jpg │ ├── MainView.cpp │ ├── MainView.h │ ├── MainViewEdit.cpp │ ├── MainViewEdit.h │ ├── MenuEntries.cpp │ ├── MenuEntries.h │ ├── MenuView.cpp │ ├── MenuView.h │ ├── SeparatorComponent.cpp │ ├── SeparatorComponent.h │ ├── TextComponent.cpp │ ├── TextComponent.h │ ├── TimeComponent.cpp │ ├── TimeComponent.h │ ├── defines.h │ └── font.h ├── Encoder │ ├── Encoder.cpp │ ├── Encoder.h │ ├── keywords.txt │ └── utility │ │ ├── direct_pin_read.h │ │ ├── interrupt_config.h │ │ └── interrupt_pins.h ├── HX711.cpp ├── HX711.h ├── HX711_license.txt ├── HX711_readme.txt ├── LiquidCrystalDogm.cpp ├── LiquidCrystalDogm.h ├── MenuSystem.cpp ├── MenuSystem.h ├── PCD8544_charset.cpp ├── PCD8544_nano.cpp ├── PCD8544_nano.h ├── PID_v1_nano.cpp ├── PID_v1_nano.h ├── VESC │ ├── buffer.cpp │ ├── buffer.h │ ├── config.h │ ├── crc.cpp │ ├── crc.h │ ├── datatypes.h │ ├── vesc_uart.cpp │ └── vesc_uart.h ├── config.h ├── display.cpp ├── display.h ├── display_backlight.cpp ├── display_backlight.h ├── display_bafang.cpp ├── display_bafang.h ├── display_kingmeter.cpp ├── display_kingmeter.h ├── ds1307.cpp ├── ds1307.h ├── globals.h ├── hrmi_funcs.cpp ├── hrmi_funcs.h ├── main.cpp ├── menu.cpp ├── menu.h ├── serial_command.cpp ├── serial_command.h ├── serial_lcd.cpp ├── serial_lcd.h ├── switches.cpp ├── switches.h └── switches_action.h ├── Bluetooth_Setup └── Bluetooth_Setup.ino ├── CMakeLists.txt ├── Hardware_Test ├── CMakeLists.txt ├── EEPROMAnything.h ├── LiquidCrystalDogm.cpp ├── LiquidCrystalDogm.h ├── PCD8544_charset.cpp ├── PCD8544_nano.cpp ├── PCD8544_nano.h ├── VESC │ ├── buffer.cpp │ ├── buffer.h │ ├── config.h │ ├── crc.cpp │ ├── crc.h │ ├── datatypes.h │ ├── vesc_uart.cpp │ └── vesc_uart.h ├── main.cpp └── printf.h ├── cmake ├── Arduino.inc.in ├── Teensy.cmake └── teensy-arm.toolchain.cmake ├── cmake_arduino ├── ArduinoToolchain.cmake └── Platform │ └── Arduino.cmake ├── docs ├── Doxyfile.in ├── README_breadboard.md ├── README_cmake.txt ├── README_hacking.txt └── README_menu.txt ├── readme.md └── tools ├── code_reformat.sh └── compile_test.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.idea 2 | *.DS_STORE 3 | # Backup files and stuff from patches 4 | *.orig 5 | *.rej 6 | *~ 7 | .*.swp 8 | 9 | # CMake 10 | build/ 11 | CMakeCache.txt 12 | cmake_install.cmake 13 | CMakeFiles 14 | Arduino_Pedelec_Controller/Arduino_Pedelec_Controller.pde 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | sudo: required 3 | dist: trusty 4 | 5 | language: 6 | - c 7 | 8 | cache: 9 | - ccache 10 | 11 | addons: 12 | apt: 13 | packages: 14 | - gcc-avr 15 | - binutils-avr 16 | - avr-libc 17 | - arduino 18 | - python3.4 19 | 20 | script: tools/compile_test.py 21 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/BMP085.h: -------------------------------------------------------------------------------- 1 | #ifndef BMP085_H 2 | #define BMP085_H 3 | // BMP085 Pressure/Temperature (Altimeter) sensor 4 | 5 | // MIT license 6 | 7 | #if (ARDUINO >= 100) 8 | #include "Arduino.h" 9 | #else 10 | #include "WProgram.h" 11 | #endif 12 | #include "Wire.h" 13 | 14 | #define BMP085_DEBUG 0 15 | 16 | #define BMP085_I2CADDR 0x77 17 | 18 | #define BMP085_ULTRALOWPOWER 0 19 | #define BMP085_STANDARD 1 20 | #define BMP085_HIGHRES 2 21 | #define BMP085_ULTRAHIGHRES 3 22 | #define BMP085_CAL_AC1 0xAA // R Calibration data (16 bits) 23 | #define BMP085_CAL_AC2 0xAC // R Calibration data (16 bits) 24 | #define BMP085_CAL_AC3 0xAE // R Calibration data (16 bits) 25 | #define BMP085_CAL_AC4 0xB0 // R Calibration data (16 bits) 26 | #define BMP085_CAL_AC5 0xB2 // R Calibration data (16 bits) 27 | #define BMP085_CAL_AC6 0xB4 // R Calibration data (16 bits) 28 | #define BMP085_CAL_B1 0xB6 // R Calibration data (16 bits) 29 | #define BMP085_CAL_B2 0xB8 // R Calibration data (16 bits) 30 | #define BMP085_CAL_MB 0xBA // R Calibration data (16 bits) 31 | #define BMP085_CAL_MC 0xBC // R Calibration data (16 bits) 32 | #define BMP085_CAL_MD 0xBE // R Calibration data (16 bits) 33 | 34 | #define BMP085_CONTROL 0xF4 35 | #define BMP085_TEMPDATA 0xF6 36 | #define BMP085_PRESSUREDATA 0xF6 37 | #define BMP085_READTEMPCMD 0x2E 38 | #define BMP085_READPRESSURECMD 0x34 39 | 40 | 41 | class BMP085 42 | { 43 | public: 44 | BMP085(); 45 | void begin(uint8_t mode = BMP085_ULTRAHIGHRES); // by default go highres 46 | float readTemperature(void); 47 | int32_t readPressure(void); 48 | float readAltitude(void); // std atmosphere 49 | uint16_t readRawTemperature(void); 50 | uint32_t readRawPressure(void); 51 | 52 | private: 53 | uint8_t read8(uint8_t addr); 54 | uint16_t read16(uint8_t addr); 55 | void write8(uint8_t addr, uint8_t data); 56 | 57 | uint8_t oversampling; 58 | 59 | int16_t ac1, ac2, ac3, b1, b2, mb, mc, md; 60 | uint16_t ac4, ac5, ac6; 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #=============================================================================# 2 | # Author: Thomas Jarosch # 3 | # Date: 24.04.2012 # 4 | # # 5 | # Description: Pedelec controller cmake project # 6 | # # 7 | #=============================================================================# 8 | include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} 9 | ${CMAKE_SOURCE_DIR}/Arduino_Pedelec_Controller) 10 | 11 | set(FIRMWARE_NAME pcontroller) 12 | 13 | #set(${FIRMWARE_NAME}_BOARD ${FC_PROCESSOR}) 14 | #set(${FIRMWARE_NAME}_PORT /dev/ttyUSB0) # Serial upload port 15 | 16 | # special compile flags for the Travis CI environment 17 | # (avr-gcc is rather outdated and outputs crazy warnings) 18 | if("$ENV{TRAVIS}" STREQUAL "true") 19 | message(STATUS "Detected Travis CI environment") 20 | 21 | # disable compiler invocation output since Travis CI has a 4MB log output limit 22 | set_property(GLOBAL PROPERTY RULE_MESSAGES off) 23 | endif("$ENV{TRAVIS}" STREQUAL "true") 24 | 25 | # Hack until we replace the .ino file with a stub 26 | # and move everything to main.cpp 27 | #configure_file(main.cpp main.cpp COPYONLY) 28 | 29 | 30 | import_arduino_library(EEPROM) 31 | import_arduino_library(SPI) 32 | import_arduino_library(ILI9341_t3) 33 | import_arduino_library(OneWire) 34 | import_arduino_library(Wire) 35 | 36 | 37 | set(${FIRMWARE_NAME}_SRCS 38 | main.cpp 39 | BMP085.cpp 40 | #BMP085.h 41 | DSPC01_nano.cpp 42 | #DSPC01_nano.h 43 | DallasTemp.cpp 44 | #DallasTemp.h 45 | HX711.cpp 46 | #HX711.h 47 | LiquidCrystalDogm.cpp 48 | #LiquidCrystalDogm.h 49 | MenuSystem.cpp 50 | #MenuSystem.h 51 | PCD8544_charset.cpp 52 | PCD8544_nano.cpp 53 | #PCD8544_nano.h 54 | PID_v1_nano.cpp 55 | #PID_v1_nano.h 56 | #config.h 57 | display.cpp 58 | #display.h 59 | display_backlight.cpp 60 | #display_backlight.h 61 | display_bafang.cpp 62 | #display_bafang.h 63 | display_kingmeter.cpp 64 | #display_kingmeter.h 65 | ds1307.cpp 66 | #ds1307.h 67 | #globals.h 68 | hrmi_funcs.cpp 69 | #hrmi_funcs.h 70 | menu.cpp 71 | #menu.h 72 | serial_command.cpp 73 | #serial_command.h 74 | serial_lcd.cpp 75 | #serial_lcd.h 76 | switches.cpp 77 | #switches.h 78 | switches_action.h 79 | VESC/buffer.cpp 80 | #VESC/buffer.h 81 | VESC/crc.cpp 82 | #VESC/crc.h 83 | #VESC/config.h 84 | #VESC/datatypes.h 85 | VESC/vesc_uart.cpp 86 | Display/BaseComponent.cpp 87 | Display/BaseView.cpp 88 | Display/Components.cpp 89 | Display/DataModel.cpp 90 | Display/DiagramComponent.cpp 91 | Display/DisplayController.cpp 92 | Display/IconComponent.cpp 93 | Display/MainView.cpp 94 | Display/MainViewEdit.cpp 95 | Display/MenuEntries.cpp 96 | Display/MenuView.cpp 97 | Display/SeparatorComponent.cpp 98 | Display/TextComponent.cpp 99 | Display/TimeComponent.cpp 100 | Encoder/Encoder.cpp 101 | ) 102 | 103 | add_teensy_executable(${FIRMWARE_NAME} "${${FIRMWARE_NAME}_SRCS}") 104 | 105 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/DSPC01_nano.h: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino Library for the Dorji DSPC01 module 3 | written by Jens Kießling 4 | For more Information see 5 | http://www.dorji.com/pro/sensor-module/Compass_pressure_sensor.html 6 | Copyright (C) 2013 7 | 8 | This program is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software Foundation, 20 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #define COMMUNI_SUCCEED 1 24 | #define COMMUNI_FAILED 0 25 | 26 | #define noACK 0 27 | #define ACK 1 28 | 29 | #define COMPASS_CALIBRATION_COMMAND 0xe0 30 | #define PRESS_WRITE_COMMAND 0xB0 31 | #define TEMPERATURE_WRITE_COMMAND 0x80 32 | #define ALTITUDE_WRITE_COMMAND 0xA0 33 | #define COMPASS_WRITE_COMMAND 0xC0 34 | 35 | class DSPC01 36 | { 37 | public: 38 | DSPC01(); 39 | void request_pressure(void); 40 | void request_altitude(void); 41 | void request_temperature(void); 42 | void request_compass(void); 43 | void calibrate_compass(void); 44 | unsigned long int pressure(void); 45 | long int altitude(void); 46 | long int temperature(void); 47 | unsigned int compass(void); 48 | void begin(int SCK_pin,int DATA_pin); 49 | 50 | private: 51 | int SCK_PIN; 52 | int DATA_PIN; 53 | unsigned char communicate_status; 54 | void send_SPC01_write_command(unsigned char command); 55 | void IIC_SCL_HIGH(void); 56 | void IIC_SCL_LOW(void); 57 | void IIC_Start(void); 58 | void IIC_Stop(void); 59 | void IIC_ACK(void); 60 | void IIC_NoAck(void); 61 | unsigned char IIC_ReadByte(void); 62 | unsigned char IIC_WriteByte( unsigned char ucData ); 63 | }; 64 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/.DS_Store -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/BaseComponent.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | /** 23 | * Base class for customizeable components 24 | */ 25 | 26 | #include "BaseComponent.h" 27 | 28 | //! Constructor 29 | BaseComponent::BaseComponent() 30 | : m_y(0), 31 | m_active(false) 32 | { 33 | } 34 | 35 | //! Destructor 36 | BaseComponent::~BaseComponent() { 37 | } 38 | 39 | //! Y Position on display 40 | void BaseComponent::setY(uint16_t y) { 41 | m_y = y; 42 | } 43 | 44 | //! Y Position on display 45 | uint16_t BaseComponent::getY() { 46 | return m_y; 47 | } 48 | 49 | //! If this component is active drawed on update 50 | void BaseComponent::setActive(bool active) { 51 | m_active = active; 52 | } 53 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/BaseComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef BASECOMPONENT_H_ 23 | #define BASECOMPONENT_H_ 24 | 25 | #include "Arduino.h" 26 | #include "Print.h" 27 | #include "ILI9341_t3.h" 28 | #include "DataModel.h" 29 | 30 | /** 31 | * Base class for customizeable components 32 | */ 33 | 34 | // Don't use a member, use this extern declared reference 35 | // Not a nice coding practice, but saves about 300 Bytes of Flash 36 | 37 | class BaseComponent { 38 | // Constructor / Destructor 39 | public: 40 | //! Constructor 41 | BaseComponent(); 42 | 43 | //! Destructor 44 | virtual ~BaseComponent(); 45 | 46 | // public API 47 | public: 48 | //! Return the height in pixel 49 | virtual uint8_t getHeight() = 0; 50 | 51 | //! Draw the component to the display 52 | virtual void draw(bool repaint) = 0; 53 | 54 | //! Y Position on display 55 | void setY(uint16_t y); 56 | 57 | //! Y Position on display 58 | uint16_t getY(); 59 | 60 | //! If this component is active drawed on update 61 | void setActive(bool active); 62 | 63 | // Member 64 | protected: 65 | //! Y Position on display 66 | uint16_t m_y; 67 | 68 | public: 69 | bool is_active() const { 70 | return m_active; 71 | } 72 | 73 | protected: 74 | //! Flag if active / not active 75 | bool m_active; 76 | }; 77 | 78 | #endif -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/BaseView.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "BaseView.h" 23 | #include "defines.h" 24 | 25 | /** 26 | * Base class for a display view 27 | */ 28 | 29 | const uint16_t LINE_GRAY = RGB_TO_565(150, 150, 150); 30 | 31 | //! Constructor 32 | BaseView::BaseView() 33 | : m_active(false) 34 | { 35 | } 36 | 37 | //! Destructor 38 | BaseView::~BaseView() { 39 | } 40 | 41 | //! This view is now enabled and displayed 42 | void BaseView::activate() { 43 | m_active = true; 44 | 45 | updateDisplay(true); 46 | } 47 | 48 | //! This view is now disabled and not displayed 49 | void BaseView::deactivate() { 50 | m_active = false; 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/BaseView.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef BASE_VIEW_H_ 23 | #define BASE_VIEW_H_ 24 | 25 | #include "Arduino.h" 26 | #include "Print.h" 27 | #include "ILI9341_t3.h" 28 | #include "DataModel.h" 29 | 30 | /** 31 | * Base class for a display view 32 | */ 33 | 34 | // Don't use a member, use this extern declared reference 35 | // Not a nice coding practice, but saves about 300 Bytes of Flash (only for TFT!) 36 | extern const uint16_t LINE_GRAY; 37 | 38 | //! The view is still alive, nothing to do 39 | #define VIEW_RESULT_NOTHING 0 40 | 41 | //! Menu exited with back 42 | #define VIEW_RESULT_BACK 1 43 | 44 | //! Show a menu, the menu root ID is in ViewResult.value 45 | #define VIEW_RESULT_MENU 2 46 | 47 | //! An entry was selected, selected ID is return in ViewResult.value 48 | #define VIEW_RESULT_SELECTED 3 49 | 50 | //! Checkbox toggled 51 | #define VIEW_RESULT_CHECKBOX_CHECKED 4 52 | 53 | //! Checkbox toggled 54 | #define VIEW_RESULT_CHECKBOX_UNCHECKED 5 55 | 56 | typedef struct { 57 | uint8_t result; 58 | uint8_t value; 59 | } ViewResult; 60 | 61 | class BaseView { 62 | // Constructor / Destructor 63 | public: 64 | //! Constructor 65 | BaseView(); 66 | 67 | //! Destructor 68 | virtual ~BaseView(); 69 | 70 | // public API 71 | public: 72 | //! This view is now enabled and displayed 73 | virtual void activate(); 74 | 75 | //! This view is now disabled and not displayed 76 | virtual void deactivate(); 77 | 78 | //! Update full display 79 | virtual void updateDisplay(bool repaint) = 0; 80 | 81 | //! UP / DOWN Key 82 | virtual void movePosition(int8_t diff) = 0; 83 | 84 | //! Key (OK) pressed 85 | virtual ViewResult keyPressed() = 0; 86 | 87 | // Member 88 | protected: 89 | //! Flag if active / not active 90 | bool m_active; 91 | }; 92 | 93 | #endif -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Components.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #ifndef COMPONENT_H_ 22 | #define COMPONENT_H_ 23 | 24 | #include "BaseComponent.h" 25 | #include "TextComponent.h" 26 | #include "TimeComponent.h" 27 | #include "DiagramComponent.h" 28 | #include "IconComponent.h" 29 | #include "SeparatorComponent.h" 30 | 31 | /** 32 | * List with the customized components 33 | */ 34 | 35 | //! Max. 10 Components on the screen (should be enough, there isn't more space) 36 | #define MAX_COMP_ACTIVE 10 37 | #define COMP_ID_NONE -1 38 | 39 | typedef struct _View { 40 | int8_t active_components_ids[MAX_COMP_ACTIVE]; 41 | String diagram_string; 42 | ValueId diagram_val; 43 | int16_t diagram_precision; 44 | float_t diagram_min; 45 | float_t diagram_max; 46 | } View; 47 | 48 | 49 | enum { 50 | COMP_ID_SEP = 0, 51 | COMP_ID_ICON, 52 | COMP_ID_DIAG, 53 | COMP_ID_BAT_MAH, 54 | COMP_ID_BAT_VOLT, 55 | COMP_ID_ODO_TOTAL, 56 | COMP_ID_REMAINING_KM, 57 | COMP_ID_TIME_DRIVEN, 58 | COMP_ID_VESC_TEMP, 59 | COMP_ID_MOTOR_CURRENT, 60 | COMP_ID_MOTOR_RPM, 61 | COMP_ID_THROTTLE_POTI, 62 | COMP_ID_THROTTLE_WRITE, 63 | COMP_ID_SUPPORT_POTI, 64 | COMP_ID_CADENCE, 65 | COMP_COUNT}; 66 | 67 | 68 | class Components { 69 | // Constructor / Destructor 70 | public: 71 | //! Constructor 72 | Components(); 73 | 74 | //! Destructor 75 | virtual ~Components(); 76 | 77 | // public API 78 | public: 79 | //! Draw all components 80 | void draw(bool repaint); 81 | 82 | BaseComponent* g_components[COMP_COUNT]; 83 | 84 | //! Return the component at position index 85 | BaseComponent* get(uint8_t index); 86 | uint16_t getY(uint8_t index); 87 | 88 | //! remove the element at index, but does not delete it 89 | void remove(uint8_t index); 90 | 91 | void changeView(int8_t diff); 92 | //! Activate / Deactivate children 93 | void deActivateChilren(bool enabled); 94 | 95 | private: 96 | //! Update the Y position of all elements, and remove invisible elements from the list 97 | void updatePositionAndRemoveInvisible(); 98 | void activateView(uint8_t num); 99 | // Member 100 | private: 101 | //! List with the components 102 | 103 | // BaseComponent* m_components[COMP_COUNT]; 104 | int8_t m_active_components_ids[MAX_COMP_ACTIVE]; 105 | uint16_t m_y_top[MAX_COMP_ACTIVE]; 106 | int8_t m_cur_view; 107 | DiagramComponent* diagramComponent; 108 | }; 109 | #endif //COMPONENT_H -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/DataModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "DataModel.h" 23 | 24 | /** 25 | * Model with all data which can be displayed by the different views 26 | */ 27 | 28 | 29 | 30 | //! Constructor 31 | DataModel::DataModel() 32 | : m_iconState(0), 33 | m_listener{0}, 34 | m_values{0} 35 | { 36 | } 37 | 38 | void DataModel::setIcon(uint8_t icon, boolean value) { 39 | boolean old_val = m_iconState & icon; 40 | if (old_val != value) { 41 | if (value) { 42 | m_iconState |= icon; 43 | } 44 | else { 45 | m_iconState &= ~icon; 46 | } 47 | fireIconUpdate(icon); 48 | } 49 | } 50 | 51 | //! Clear an icon 52 | void DataModel::clearIcon(uint8_t icon) { 53 | setIcon(icon, false); 54 | } 55 | 56 | //! Show an icon 57 | void DataModel::showIcon(uint8_t icon) { 58 | setIcon(icon, true); 59 | } 60 | 61 | //! Set the value 62 | void DataModel::setValue(uint8_t valueId, uint16_t value) { 63 | if (value != m_values[valueId]) { 64 | m_values[valueId] = value; 65 | fireValueUpdate(valueId); 66 | } 67 | } 68 | 69 | //! Get a value 70 | uint16_t DataModel::getValue(uint8_t valueId) { 71 | return m_values[valueId]; 72 | } 73 | 74 | //! Bitmask with icon state 75 | uint8_t DataModel::getIcon() { 76 | return m_iconState; 77 | } 78 | 79 | //! Add a listener to get informed about changes 80 | void DataModel::addListener(DataListener* listener) { 81 | for (uint8_t i = 0; i < sizeof(m_listener) / sizeof(DataListener*); i++) { 82 | if (m_listener[i] == NULL) { 83 | m_listener[i] = listener; 84 | break; 85 | } 86 | } 87 | } 88 | 89 | //! Remove a listener 90 | void DataModel::removeListener(DataListener* listener) { 91 | for (uint8_t i = 0; i < sizeof(m_listener) / sizeof(DataListener*); i++) { 92 | if (m_listener[i] == listener) { 93 | m_listener[i] = NULL; 94 | break; 95 | } 96 | } 97 | } 98 | 99 | //! fire an icon state change 100 | void DataModel::fireIconUpdate(uint8_t iconId) { 101 | for (uint8_t i = 0; i < sizeof(m_listener) / sizeof(DataListener*); i++) { 102 | if (m_listener[i] != NULL) { 103 | m_listener[i]->onIconUpdate(iconId); 104 | } 105 | } 106 | } 107 | 108 | //! fire a value changed 109 | void DataModel::fireValueUpdate(uint8_t valueId) { 110 | for (uint8_t i = 0; i < sizeof(m_listener) / sizeof(DataListener*); i++) { 111 | if (m_listener[i] != NULL) { 112 | m_listener[i]->onValueChanged(valueId); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/DataModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef DATAMODEL_H_ 23 | #define DATAMODEL_H_ 24 | /** 25 | * Model with all data which can be displayed by the different views 26 | */ 27 | 28 | #include "Arduino.h" 29 | #include "defines.h" 30 | 31 | 32 | 33 | 34 | class DataListener { 35 | public: 36 | //! Icon changed 37 | virtual void onIconUpdate(uint8_t iconId) {}; 38 | 39 | //! a value was changed 40 | virtual void onValueChanged(uint8_t valueId) {}; 41 | 42 | }; 43 | 44 | class DataModel { 45 | // Constructor / Destructor 46 | public: 47 | //! Constructor 48 | DataModel(); 49 | 50 | // public API 51 | public: 52 | //! Clear an icon 53 | void clearIcon(uint8_t icon); 54 | 55 | void setIcon(uint8_t icon, boolean value); 56 | 57 | //! Show an icon 58 | void showIcon(uint8_t icon); 59 | 60 | //! Bitmask with icon state 61 | uint8_t getIcon(); 62 | 63 | //! Set the value 64 | void setValue(uint8_t valueId, uint16_t value); 65 | 66 | //! Get a value 67 | uint16_t getValue(uint8_t valueId); 68 | 69 | public: 70 | //! Add a listener to get informed about changes 71 | void addListener(DataListener* listener); 72 | 73 | //! Remove a listener 74 | void removeListener(DataListener* listener); 75 | 76 | private: 77 | //! fire an icon state change 78 | void fireIconUpdate(uint8_t iconId); 79 | 80 | //! fire a value changed 81 | void fireValueUpdate(uint8_t valueId); 82 | 83 | // Member 84 | private: 85 | //! Bitmask with icon state 86 | uint8_t m_iconState; 87 | 88 | //! Listener list 89 | DataListener* m_listener[VALUE_COUNT * 2]; //maximum two listeners per value 90 | 91 | //! Values 92 | uint16_t m_values[VALUE_COUNT]; 93 | }; 94 | #endif -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/DiagramComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #pragma once 23 | #define DATA_LENGTH 120 24 | #define UPDATE_PERIOD_S 1.0 * 1000 25 | 26 | #include "BaseComponent.h" 27 | 28 | /** 29 | * Display a diagram with a history of the value 30 | */ 31 | 32 | class DiagramComponent: public BaseComponent, public DataListener { 33 | // Constructor / Destructor 34 | public: 35 | //! Constructor 36 | DiagramComponent(String text, ValueId value, float_t min, float_t max); 37 | 38 | 39 | //! Destructor 40 | virtual ~DiagramComponent(); 41 | 42 | //! Return the height in pixel 43 | virtual uint8_t getHeight(); 44 | 45 | //! Draw the component to the display 46 | virtual void draw(bool repaint); 47 | 48 | virtual void onValueChanged(uint8_t valueId); 49 | 50 | void set_text(const String &m_text); 51 | void set_display_value_id(ValueId m_display_value_id); 52 | void set_min_max(float_t min, float_t max); 53 | void set_precision(int16_t precision); 54 | 55 | // Member 56 | private: 57 | //! Diagram data (the display is 240px wide / 2px) 58 | String m_text; 59 | 60 | 61 | private: 62 | ValueId m_display_value_id; 63 | float_t m_data[DATA_LENGTH]; 64 | uint8_t m_cur_pose_index; 65 | int16_t m_precision; 66 | long m_last_draw; 67 | float current_value; 68 | uint16_t current_count; 69 | float min_value; 70 | float max_value; 71 | }; 72 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/DisplayController.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #ifndef DISPLAY_CONTROLLER_H_ 22 | #define DISPLAY_CONTROLLER_H_ 23 | 24 | #include "Arduino.h" 25 | 26 | /** 27 | * Control the whole display Navigation and output 28 | */ 29 | 30 | //! Call once on startup 31 | void displayControllerSetup(); 32 | 33 | //! Call in the main loop 34 | int keyPressed(); 35 | 36 | void exitMenu(); 37 | 38 | void updatePosition(int8_t diff); 39 | 40 | void updateDisplay(); 41 | 42 | void updateDataModel(uint8_t value_id, uint16_t value); 43 | 44 | void updateIconModel(uint8_t icon_id, boolean value); 45 | 46 | #endif -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/%.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/%.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/0.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/1.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/2.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/3.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/4.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/5.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/6.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/7.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/8.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/9.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/a.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/ae.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/ae.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/b.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/c.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/d.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/e.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/f.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/g.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/g.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/h.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/i.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/i.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/j.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/k.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/k.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/l.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/m.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/n.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/o.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/oe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/oe.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/p.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/point.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/point.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/q.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/q.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/r.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/s.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/slash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/slash.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/t.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/t.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/u.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/u.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/ue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/ue.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/v.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/v.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/w.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/w.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/x.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/y.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/y.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size2/z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size2/z.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/0.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/1.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/2.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/3.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/4.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/5.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/6.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/7.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/8.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/9.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Font/Size4/point.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Font/Size4/point.png -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/IconComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "BaseComponent.h" 25 | 26 | /** 27 | * Display a text with value on the display 28 | */ 29 | 30 | class IconComponent: public BaseComponent, public DataListener { 31 | // Constructor / Destructor 32 | public: 33 | //! Constructor 34 | IconComponent(); 35 | 36 | //! Destructor 37 | virtual ~IconComponent(); 38 | 39 | // public API 40 | public: 41 | //! Return the height in pixel 42 | virtual uint8_t getHeight(); 43 | 44 | //! Draw the component to the display 45 | virtual void draw(bool repaint); 46 | 47 | private: 48 | //! Draw Bluetooth Icon 49 | void drawBluetooth(bool repaint); 50 | 51 | //! Draw Brakes Icon 52 | void drawBrakes(bool repaint); 53 | 54 | //! Draw PAS Icon 55 | void drawPAS(bool repaint); 56 | 57 | //! Draw Light Icon 58 | void drawLight(bool repaint); 59 | 60 | //! Draw Profile Icon 61 | void drawProfile(bool repaint); 62 | 63 | //! DataListener 64 | public: 65 | //! Icon changed 66 | virtual void onIconUpdate(uint8_t iconId); 67 | 68 | // Member 69 | private: 70 | }; 71 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Images/Demo Main screen.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Images/Demo Main screen.JPG -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Images/Demo Menu.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Images/Demo Menu.JPG -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Images/edit-main1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Images/edit-main1.jpg -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Images/edit-main2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Images/edit-main2.JPG -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/Images/edit-main3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daenny/Arduino-Pedelec-Controller/102d806b40df2de028aed0ae485f933dfd78234a/Arduino_Pedelec_Controller/Display/Images/edit-main3.jpg -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/MainView.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "BaseView.h" 25 | #include "ILI9341_t3.h" 26 | #include "defines.h" 27 | 28 | 29 | /** 30 | * Main view 31 | */ 32 | 33 | class Components; 34 | 35 | class MainView : public BaseView, public DataListener { 36 | // Constructor / Destructor 37 | public: 38 | //! Constructor 39 | MainView(Components* components); 40 | 41 | //! Destructor 42 | virtual ~MainView(); 43 | 44 | // public API 45 | public: 46 | //! Update full display 47 | virtual void updateDisplay(bool repaint); 48 | 49 | //! This view is now enabled and displayed 50 | virtual void activate(); 51 | 52 | //! This view is now disabled and not displayed 53 | virtual void deactivate(); 54 | 55 | //! UP / DOWN Key 56 | virtual void movePosition(int8_t diff); 57 | 58 | //! Key (OK) pressed 59 | virtual ViewResult keyPressed(); 60 | 61 | // DataListener 62 | public: 63 | //! a value was changed 64 | virtual void onValueChanged(uint8_t valueId); 65 | 66 | private: 67 | //! Draw speed 68 | void drawSpeed(bool repaint); 69 | 70 | //! Draw battery 71 | void drawBattery(bool repaint); 72 | 73 | //! Draw wattage bar 74 | void drawWattage(bool repaint); 75 | 76 | void drawKM(bool repaint); 77 | 78 | // Member 79 | protected: 80 | //! Customizeable components on the screen 81 | Components* m_components; 82 | }; 83 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/MainViewEdit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "MainViewEdit.h" 23 | #include "MenuEntries.h" 24 | #include "Components.h" 25 | 26 | 27 | /** 28 | * Custmize main view 29 | */ 30 | 31 | //! Constructor 32 | MainViewEdit::MainViewEdit(Components* components) 33 | : MainView(components), 34 | m_selectedId(0), 35 | m_lastSelectedId(-1), 36 | m_selectionPosition(0) 37 | { 38 | } 39 | 40 | //! Destructor 41 | MainViewEdit::~MainViewEdit() { 42 | } 43 | 44 | //! UP / DOWN Key 45 | void MainViewEdit::movePosition(int8_t diff) { 46 | m_lastSelectedId = m_selectedId; 47 | 48 | m_selectedId += diff; 49 | if (m_selectedId < 0) { 50 | m_selectedId = 0; 51 | } 52 | 53 | if (m_selectedId - 1 >= MAX_COMP_ACTIVE) { 54 | m_selectedId = MAX_COMP_ACTIVE - 1; 55 | } 56 | 57 | while (m_components->get(m_selectedId) == NULL && m_selectedId > 0) { 58 | m_selectedId--; 59 | } 60 | drawSelection(); 61 | } 62 | 63 | //! draw the selection mark 64 | void MainViewEdit::drawSelection() { 65 | if (!m_active) { 66 | return; 67 | } 68 | 69 | if (m_lastSelectedId != -1) { 70 | BaseComponent* component = m_components->get(m_lastSelectedId); 71 | if (component != NULL) { 72 | lcd.fillRect(0, m_components->getY(m_lastSelectedId) - 1, 240, component->getHeight() + 2, ILI9341_BLACK); 73 | component->setY(m_components->getY(m_lastSelectedId)); 74 | component->draw(true); 75 | } 76 | } 77 | m_lastSelectedId = -1; 78 | 79 | BaseComponent* component = m_components->get(m_selectedId); 80 | if (component == NULL) { 81 | return; 82 | } 83 | 84 | for (uint8_t i = 0; i <= 1; i++) { 85 | lcd.drawRect(i, m_components->getY(m_selectedId) + i, 240 - 2 * i, component->getHeight() + 1 - 2 * i, ILI9341_MAGENTA); 86 | } 87 | } 88 | 89 | //! Update full display 90 | void MainViewEdit::updateDisplay(bool repaint) { 91 | if (!m_active) { 92 | return; 93 | } 94 | 95 | MainView::updateDisplay(repaint); 96 | 97 | drawSelection(); 98 | } 99 | 100 | //! remove the selected component 101 | void MainViewEdit::removeSelected() { 102 | m_components->remove(m_selectedId); 103 | updateDisplay(true); 104 | } 105 | 106 | //! Key (OK) pressed 107 | ViewResult MainViewEdit::keyPressed() { 108 | ViewResult result; 109 | result.result = VIEW_RESULT_NOTHING; 110 | result.value = 0; 111 | 112 | if (m_selectedId != -1) { 113 | BaseComponent* component = m_components->get(m_selectedId); 114 | if (component != NULL) { 115 | result.result = VIEW_RESULT_MENU; 116 | result.value = MENU_ID_COMPONENT; 117 | } 118 | } 119 | 120 | return result; 121 | } 122 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/MainViewEdit.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "MainView.h" 25 | 26 | /** 27 | * Custmize main view 28 | */ 29 | 30 | class MainViewEdit : public MainView { 31 | // Constructor / Destructor 32 | public: 33 | //! Constructor 34 | MainViewEdit(Components* components); 35 | 36 | //! Destructor 37 | virtual ~MainViewEdit(); 38 | 39 | // public API 40 | public: 41 | //! Update full display 42 | virtual void updateDisplay(bool repaint); 43 | 44 | //! UP / DOWN Key 45 | virtual void movePosition(int8_t diff); 46 | 47 | //! Key (OK) pressed 48 | virtual ViewResult keyPressed(); 49 | 50 | //! remove the selected component 51 | void removeSelected(); 52 | 53 | private: 54 | //! draw the selection mark 55 | void drawSelection(); 56 | 57 | // Member 58 | private: 59 | //! Selected element 60 | int8_t m_selectedId; 61 | 62 | //! Last selected element to repaint, -1 for none 63 | int8_t m_lastSelectedId; 64 | 65 | //! Positino, -1 top, 0 Element, 1 bottom 66 | int8_t m_selectionPosition; 67 | }; 68 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/MenuEntries.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "Arduino.h" 25 | #include "defines.h" 26 | /** 27 | * Definition for Menu Entry texts 28 | */ 29 | 30 | typedef struct _DisplayMenuItem { 31 | uint8_t id; 32 | uint8_t parentId; 33 | const char* text; 34 | uint8_t flags; 35 | } DisplayMenuItem; 36 | 37 | #define MENU_DEFAULT 0 38 | #define MENU_CHECKBOX 1 39 | #define MENU_BACK 2 40 | #define MENU_WITH_SUBMENU 4 41 | 42 | enum { 43 | MENU_ID_NONE = 0, 44 | 45 | // ------------- 46 | 47 | MENU_ID_ROOT, 48 | MENU_ID_VIEW, 49 | MENU_ID_VIEW_EDIT, 50 | MENU_ID_RESET_WH, 51 | MENU_ID_RESET_KM, 52 | MENU_ID_BACK_VIEW, 53 | MENU_ID_LIGHT_CB, 54 | MENU_ID_BLUETOOTH_CB, 55 | MENU_ID_PROFIL_CB, 56 | MENU_ID_EMERGENCY, 57 | MENU_ID_EM_BRAKE_CB, 58 | MENU_ID_EM_PEDAL_CB, 59 | MENU_ID_EM_SPEED_CB, 60 | MENU_ID_EM_SPEEDCTRL_CB, 61 | MENU_ID_EM_POTI_CB, 62 | 63 | MENU_ID_ADD_POTI_CB, 64 | MENU_ID_DEC_POTI_CB, 65 | MENU_ID_BACK_EMERGENCY, 66 | MENU_ID_TURN_OFF, 67 | MENU_ID_BACK_MAIN, 68 | 69 | // ------------- 70 | 71 | MENU_ID_COMPONENT = 40, 72 | MENU_ID_COMPONENT_REPLACE, 73 | MENU_ID_COMPONENT_REMOVE, 74 | MENU_ID_COMPONENT_BACK, 75 | 76 | // ------------- 77 | 78 | MENU_ID_COMPONENT_SELECTION = 60, 79 | 80 | }; 81 | 82 | extern const DisplayMenuItem PROGMEM Menu[]; 83 | 84 | extern uint8_t Menu_Count; 85 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/MenuView.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "BaseView.h" 25 | #include "MenuEntries.h" 26 | 27 | /** 28 | * Display a single menu 29 | */ 30 | 31 | class MenuView : public BaseView { 32 | // Constructor / Destructor 33 | public: 34 | //! Constructor 35 | MenuView(); 36 | 37 | //! Destructor 38 | virtual ~MenuView(); 39 | 40 | // public API 41 | public: 42 | //! Update full display 43 | virtual void updateDisplay(bool repaint); 44 | 45 | //! UP / DOWN Key 46 | virtual void movePosition(int8_t diff); 47 | 48 | //! Key (OK) pressed 49 | virtual ViewResult keyPressed(); 50 | 51 | //! Set the root menu ID 52 | void setRootMenuId(uint8_t menu); 53 | 54 | private: 55 | //! Read the menu item from const memory (for AVR only) 56 | void readMenuItem(const void* p, DisplayMenuItem* current); 57 | 58 | //! Draw the menu to the display 59 | void drawMenu(bool repaint); 60 | 61 | //! Draw a single menuitem 62 | void drawMenuItem(DisplayMenuItem* menuItem, uint8_t menuIndex, uint16_t y, bool repaint); 63 | 64 | //! if a checkbox is selected 65 | bool isSelected(uint8_t index); 66 | 67 | //! Mark a checkbox as selected 68 | void selectCheckbox(uint8_t index); 69 | 70 | //! Mark a checkbox as not selected 71 | void unselectCheckbox(uint8_t index); 72 | 73 | // Member 74 | private: 75 | //! Root menu index 76 | uint8_t m_menu; 77 | 78 | //! Last selected index, to also repaint 79 | int8_t m_lastSelectedMenuIndex; 80 | 81 | //! Count of currently visible items, -1 for not initialized 82 | int8_t m_itemCount; 83 | 84 | //! Selected menu index, 0 for first menu 85 | int8_t m_selectedMenuIndex; 86 | 87 | //! Selected menu 88 | DisplayMenuItem m_selectedMenu; 89 | 90 | // Menu index to go back 91 | int8_t m_backIndex; 92 | 93 | //! Selected checkboxes indexes, 0 is an empty field 94 | uint8_t m_selectedCheckboxes[30]; 95 | }; 96 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/SeparatorComponent.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | /** 23 | * Display a separator line 24 | */ 25 | 26 | #include "SeparatorComponent.h" 27 | #include "defines.h" 28 | 29 | const uint16_t SEPARATOR_COLOR = RGB_TO_565(120, 120, 120); 30 | 31 | //! Constructor 32 | SeparatorComponent::SeparatorComponent() { 33 | } 34 | 35 | //! Destructor 36 | SeparatorComponent::~SeparatorComponent() { 37 | } 38 | 39 | //! Y Position on display 40 | uint8_t SeparatorComponent::getHeight() { 41 | return 4; 42 | } 43 | 44 | //! Draw the component to the display 45 | void SeparatorComponent::draw(bool repaint) { 46 | if (repaint) 47 | for (uint8_t i = 1; i <= 2; i++) { 48 | lcd.drawLine(0, m_y + i, 240, m_y + i, SEPARATOR_COLOR); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/SeparatorComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "BaseComponent.h" 25 | 26 | /** 27 | * Display a separator line 28 | */ 29 | 30 | class SeparatorComponent: public BaseComponent { 31 | // Constructor / Destructor 32 | public: 33 | //! Constructor 34 | SeparatorComponent(); 35 | 36 | //! Destructor 37 | virtual ~SeparatorComponent(); 38 | 39 | // public API 40 | public: 41 | //! Return the height in pixel 42 | virtual uint8_t getHeight(); 43 | 44 | //! Draw the component to the display 45 | virtual void draw(bool repaint); 46 | }; 47 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/TextComponent.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | /** 23 | * Display a text with value on the display 24 | */ 25 | 26 | #include "TextComponent.h" 27 | 28 | //! Constructor 29 | TextComponent::TextComponent(String text, ValueId value, int precision) 30 | : m_text(text), 31 | m_display_value_id(value), 32 | m_precision(precision) 33 | { 34 | model.addListener(this); 35 | } 36 | 37 | //! Destructor 38 | TextComponent::~TextComponent() { 39 | //model.removeListener(this); 40 | } 41 | 42 | //! Y Position on display 43 | uint8_t TextComponent::getHeight() { 44 | return 18; 45 | } 46 | 47 | void TextComponent::onValueChanged(uint8_t valueId){ 48 | if (valueId == m_display_value_id) 49 | this->draw(false); 50 | } 51 | 52 | //! Draw the component to the display 53 | void TextComponent::draw(bool repaint) { 54 | if (!m_active) 55 | return; 56 | lcd.setTextSize(2); 57 | lcd.setTextColor(ILI9341_WHITE, ILI9341_BLACK); 58 | 59 | //if (repaint){ 60 | lcd.setCursor(0, m_y + 2); 61 | lcd.print(m_text.c_str()); 62 | 63 | //} 64 | lcd.setTextColor(ILI9341_YELLOW, ILI9341_BLACK); 65 | 66 | uint16_t value = model.getValue(m_display_value_id); 67 | //uint16_t value = 0; 68 | 69 | //right align 70 | String num = String(value); 71 | int num_chars = num.length(); 72 | if (m_precision > 0) 73 | num_chars = max(m_precision + 2, num_chars - m_precision + 2); 74 | 75 | 76 | for (int y = m_text.length() * 12; y < 240 - num_chars * 12; y+=12) { 77 | lcd.print(" "); 78 | } 79 | lcd.setCursor(240 - num_chars*12, m_y + 2); 80 | 81 | 82 | if (m_precision > 0) { 83 | int factor = (int)pow(10, m_precision); 84 | lcd.print(value/factor); 85 | lcd.print("."); 86 | lcd.printf("%0*d",m_precision, value - (value/factor)*factor); 87 | } 88 | else { 89 | lcd.print(value); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/TextComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "BaseComponent.h" 25 | 26 | /** 27 | * Display a text with value on the display 28 | */ 29 | 30 | class TextComponent: public BaseComponent, public DataListener { 31 | // Constructor / Destructor 32 | public: 33 | //! Constructor 34 | TextComponent(String text, ValueId display_val, int precision); 35 | //! Destructor 36 | virtual ~TextComponent(); 37 | 38 | // public API 39 | public: 40 | //! Return the height in pixel 41 | virtual uint8_t getHeight(); 42 | 43 | //! Draw the component to the display 44 | virtual void draw(bool repaint); 45 | 46 | // Member 47 | protected: 48 | //! Text to display 49 | String m_text; 50 | ValueId m_display_value_id; 51 | int16_t m_precision; 52 | //! DataListener 53 | public: 54 | //! Data changed 55 | virtual void onValueChanged(uint8_t valueId); 56 | 57 | }; 58 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/TimeComponent.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by daniel on 03/08/16. 3 | // 4 | 5 | #include "TimeComponent.h" 6 | 7 | 8 | //! Draw the component to the display 9 | void TimeComponent::draw(bool repaint) { 10 | if (!m_active) 11 | return; 12 | lcd.setTextSize(2); 13 | lcd.setTextColor(ILI9341_WHITE, ILI9341_BLACK); 14 | 15 | //if (repaint){ 16 | lcd.setCursor(0, m_y + 2); 17 | lcd.print(m_text.c_str()); 18 | 19 | //} 20 | lcd.setTextColor(ILI9341_YELLOW, ILI9341_BLACK); 21 | 22 | uint16_t value = model.getValue(m_display_value_id); 23 | 24 | int num_chars = 8; //hh:mm:ss 25 | 26 | for (int y = m_text.length() * 12; y < 240 - num_chars * 12; y+=12) { 27 | lcd.print(" "); 28 | } 29 | lcd.setCursor(240 - num_chars*12, m_y + 2); 30 | //hours 31 | lcd.printf("%02d", value/(60*60)); 32 | lcd.print(":"); 33 | value-= value/(60*60) * 60 * 60; 34 | 35 | //minutes 36 | lcd.printf("%02d", value/(60)); 37 | lcd.print(":"); 38 | value-= value/(60) * 60; 39 | 40 | //seconds 41 | lcd.printf("%02d", value); 42 | 43 | } -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/TimeComponent.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by daniel on 03/08/16. 3 | // 4 | 5 | #ifndef PEDELEC_CONTROLLER_TIMECOMPONENT_H 6 | #define PEDELEC_CONTROLLER_TIMECOMPONENT_H 7 | 8 | #include "TextComponent.h" 9 | 10 | class TimeComponent: public TextComponent { 11 | public: 12 | //! Constructor 13 | TimeComponent(String text, ValueId display_val): 14 | TextComponent(text, display_val, 0) {}; 15 | 16 | //! Destructor 17 | virtual void draw(bool repaint); 18 | 19 | }; 20 | 21 | #endif //PEDELEC_CONTROLLER_TIMECOMPONENT_H 22 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Display/defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | ILI9341 LCD Display controller for Arduino_Pedelec_Controller 3 | 4 | Copyright (C) 2016 5 | Andreas Butti, andreas.b242 at gmail dot com 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | /** 23 | * Defines, e.g. for Umlauts 24 | */ 25 | #ifndef DEFINES_H_ 26 | #define DEFINES_H_ 27 | 28 | #include "ILI9341_t3.h" 29 | 30 | #define UE "\x81" 31 | #define OE "\x99" 32 | #define AE "\x83" 33 | 34 | #define ae "\x84" 35 | #define oe "\x94" 36 | #define ue "\xa3" 37 | 38 | #define RGB_TO_565(r, g, b) ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3) 39 | 40 | extern ILI9341_t3 lcd; 41 | extern boolean repaint; 42 | 43 | class DataModel; 44 | extern DataModel model; 45 | 46 | enum IconId { 47 | ICON_ID_BLUETOOTH = (1 << 0), 48 | ICON_ID_BRAKE = (1 << 1), 49 | ICON_ID_LIGHT = (1 << 2), 50 | ICON_ID_PROFILE = (1 << 3), 51 | ICON_ID_PAS = (1 << 4), 52 | ICON_ID_HEART = (1 << 5) 53 | }; 54 | 55 | enum ValueId { 56 | VALUE_ID_NONE = 0, 57 | //! the speed in 0.1 km/h and update display if needed 58 | VALUE_ID_SPEED, 59 | //power in W; 60 | VALUE_ID_POWER, 61 | VALUE_ID_MAX_POWER, 62 | 63 | //! Current voltage 64 | VALUE_ID_BATTERY_VOLTAGE_CURRENT, 65 | //Cuurent bat perc 66 | VALUE_ID_BATTERY_PERC_CURRENT, 67 | //Current Bat mah 68 | VALUE_ID_BATTERY_MAH_USED, 69 | VALUE_ID_BATTERY_CURRENT, 70 | VALUE_ID_THROTTLE_POTI, 71 | VALUE_ID_THROTTLE_WRITE, 72 | VALUE_ID_SUPPORT_POTI, 73 | VALUE_ID_ODO_TOTAL, 74 | VALUE_ID_ODO_CURRENT, 75 | VALUE_ID_REMAINING_KM, 76 | VALUE_ID_TIME_DRIVEN, 77 | VALUE_ID_VESC_TEMP, 78 | VALUE_ID_MOTOR_CURRENT, 79 | VALUE_ID_MOTOR_RPM, 80 | VALUE_ID_ENC, 81 | VALUE_ID_CADENCE, 82 | VALUE_COUNT 83 | }; 84 | 85 | enum { 86 | DISPLAY_ACTION_NONE = 0, 87 | DISPLAY_ACTION_SHUTDOWN, 88 | DISPLAY_ACTION_MENU_DISABLED, 89 | DISPLAY_ACTION_RESET_ODO, 90 | DISPLAY_ACTION_RESET_MAH, 91 | DISPLAY_ACTION_TOGGLE_LIGHTS, 92 | DISPLAY_ACTION_TOGGLE_BLUETOOTH, 93 | DISPLAY_ACTION_TOGGLE_ACTIVE_PROFILE, 94 | DISPLAY_ACTION_POTI_UP, 95 | DISPLAY_ACTION_POTI_DOWN, 96 | DISPLAY_ACTION_DISABLE_POTI, 97 | DISPLAY_ACTION_DISABLE_WHEEL, 98 | DISPLAY_ACTION_DISABLE_BRAKE, 99 | DISPLAY_ACTION_DISABLE_PAS, 100 | DISPLAY_ACTION_DISABLE_THROTTLE, 101 | DISPLAY_ACTION_ENABLE_POTI, 102 | DISPLAY_ACTION_ENABLE_WHEEL, 103 | DISPLAY_ACTION_ENABLE_BRAKE, 104 | DISPLAY_ACTION_ENABLE_PAS, 105 | DISPLAY_ACTION_ENABLE_THROTTLE 106 | }; 107 | 108 | #endif -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Encoder/Encoder.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Encoder.h" 3 | 4 | // Yes, all the code is in the header file, to provide the user 5 | // configure options with #define (before they include it), and 6 | // to facilitate some crafty optimizations! 7 | 8 | Encoder_internal_state_t * Encoder::interruptArgs[]; 9 | 10 | 11 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Encoder/keywords.txt: -------------------------------------------------------------------------------- 1 | ENCODER_USE_INTERRUPTS LITERAL1 2 | ENCODER_OPTIMIZE_INTERRUPTS LITERAL1 3 | ENCODER_DO_NOT_USE_INTERRUPTS LITERAL1 4 | Encoder KEYWORD1 5 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Encoder/utility/direct_pin_read.h: -------------------------------------------------------------------------------- 1 | #ifndef direct_pin_read_h_ 2 | #define direct_pin_read_h_ 3 | 4 | #if defined(__AVR__) || defined(__MK20DX128__) || defined(__MK20DX256__) 5 | 6 | #define IO_REG_TYPE uint8_t 7 | #define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin))) 8 | #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 9 | #define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0) 10 | 11 | #elif defined(__SAM3X8E__) 12 | 13 | #define IO_REG_TYPE uint32_t 14 | #define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin))) 15 | #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 16 | #define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0) 17 | 18 | #elif defined(__PIC32MX__) 19 | 20 | #define IO_REG_TYPE uint32_t 21 | #define PIN_TO_BASEREG(pin) (portModeRegister(digitalPinToPort(pin))) 22 | #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 23 | #define DIRECT_PIN_READ(base, mask) (((*(base+4)) & (mask)) ? 1 : 0) 24 | 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Encoder/utility/interrupt_config.h: -------------------------------------------------------------------------------- 1 | #if defined(__AVR__) 2 | 3 | #include 4 | #include 5 | 6 | #define attachInterrupt(num, func, mode) enableInterrupt(num) 7 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 8 | #define SCRAMBLE_INT_ORDER(num) ((num < 4) ? num + 2 : ((num < 6) ? num - 4 : num)) 9 | #define DESCRAMBLE_INT_ORDER(num) ((num < 2) ? num + 4 : ((num < 6) ? num - 2 : num)) 10 | #else 11 | #define SCRAMBLE_INT_ORDER(num) (num) 12 | #define DESCRAMBLE_INT_ORDER(num) (num) 13 | #endif 14 | 15 | static void enableInterrupt(uint8_t num) 16 | { 17 | switch (DESCRAMBLE_INT_ORDER(num)) { 18 | #if defined(EICRA) && defined(EIMSK) 19 | case 0: 20 | EICRA = (EICRA & 0xFC) | 0x01; 21 | EIMSK |= 0x01; 22 | return; 23 | case 1: 24 | EICRA = (EICRA & 0xF3) | 0x04; 25 | EIMSK |= 0x02; 26 | return; 27 | case 2: 28 | EICRA = (EICRA & 0xCF) | 0x10; 29 | EIMSK |= 0x04; 30 | return; 31 | case 3: 32 | EICRA = (EICRA & 0x3F) | 0x40; 33 | EIMSK |= 0x08; 34 | return; 35 | #elif defined(MCUCR) && defined(GICR) 36 | case 0: 37 | MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 38 | GICR |= (1 << INT0); 39 | return; 40 | case 1: 41 | MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 42 | GICR |= (1 << INT1); 43 | return; 44 | #elif defined(MCUCR) && defined(GIMSK) 45 | case 0: 46 | MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 47 | GIMSK |= (1 << INT0); 48 | return; 49 | case 1: 50 | MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 51 | GIMSK |= (1 << INT1); 52 | return; 53 | #endif 54 | #if defined(EICRB) && defined(EIMSK) 55 | case 4: 56 | EICRB = (EICRB & 0xFC) | 0x01; 57 | EIMSK |= 0x10; 58 | return; 59 | case 5: 60 | EICRB = (EICRB & 0xF3) | 0x04; 61 | EIMSK |= 0x20; 62 | return; 63 | case 6: 64 | EICRB = (EICRB & 0xCF) | 0x10; 65 | EIMSK |= 0x40; 66 | return; 67 | case 7: 68 | EICRB = (EICRB & 0x3F) | 0x40; 69 | EIMSK |= 0x80; 70 | return; 71 | #endif 72 | } 73 | } 74 | 75 | #elif defined(__PIC32MX__) 76 | 77 | #ifdef ENCODER_OPTIMIZE_INTERRUPTS 78 | #undef ENCODER_OPTIMIZE_INTERRUPTS 79 | #endif 80 | 81 | #else 82 | 83 | #ifdef ENCODER_OPTIMIZE_INTERRUPTS 84 | #undef ENCODER_OPTIMIZE_INTERRUPTS 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/Encoder/utility/interrupt_pins.h: -------------------------------------------------------------------------------- 1 | // interrupt pins for known boards 2 | 3 | // Teensy (and maybe others) define these automatically 4 | #if !defined(CORE_NUM_INTERRUPT) 5 | 6 | // Wiring boards 7 | #if defined(WIRING) 8 | #define CORE_NUM_INTERRUPT NUM_EXTERNAL_INTERRUPTS 9 | #if NUM_EXTERNAL_INTERRUPTS > 0 10 | #define CORE_INT0_PIN EI0 11 | #endif 12 | #if NUM_EXTERNAL_INTERRUPTS > 1 13 | #define CORE_INT1_PIN EI1 14 | #endif 15 | #if NUM_EXTERNAL_INTERRUPTS > 2 16 | #define CORE_INT2_PIN EI2 17 | #endif 18 | #if NUM_EXTERNAL_INTERRUPTS > 3 19 | #define CORE_INT3_PIN EI3 20 | #endif 21 | #if NUM_EXTERNAL_INTERRUPTS > 4 22 | #define CORE_INT4_PIN EI4 23 | #endif 24 | #if NUM_EXTERNAL_INTERRUPTS > 5 25 | #define CORE_INT5_PIN EI5 26 | #endif 27 | #if NUM_EXTERNAL_INTERRUPTS > 6 28 | #define CORE_INT6_PIN EI6 29 | #endif 30 | #if NUM_EXTERNAL_INTERRUPTS > 7 31 | #define CORE_INT7_PIN EI7 32 | #endif 33 | 34 | // Arduino Uno, Duemilanove, Diecimila, LilyPad, Mini, Fio, etc... 35 | #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) 36 | #define CORE_NUM_INTERRUPT 2 37 | #define CORE_INT0_PIN 2 38 | #define CORE_INT1_PIN 3 39 | 40 | // Arduino Mega 41 | #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 42 | #define CORE_NUM_INTERRUPT 6 43 | #define CORE_INT0_PIN 2 44 | #define CORE_INT1_PIN 3 45 | #define CORE_INT2_PIN 21 46 | #define CORE_INT3_PIN 20 47 | #define CORE_INT4_PIN 19 48 | #define CORE_INT5_PIN 18 49 | 50 | // Arduino Leonardo (untested) 51 | #elif defined(__AVR_ATmega32U4__) && !defined(CORE_TEENSY) 52 | #define CORE_NUM_INTERRUPT 4 53 | #define CORE_INT0_PIN 3 54 | #define CORE_INT1_PIN 2 55 | #define CORE_INT2_PIN 0 56 | #define CORE_INT3_PIN 1 57 | 58 | // Sanguino (untested) 59 | #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) 60 | #define CORE_NUM_INTERRUPT 3 61 | #define CORE_INT0_PIN 10 62 | #define CORE_INT1_PIN 11 63 | #define CORE_INT2_PIN 2 64 | 65 | // Chipkit Uno32 - attachInterrupt may not support CHANGE option 66 | #elif defined(__PIC32MX__) && defined(_BOARD_UNO_) 67 | #define CORE_NUM_INTERRUPT 5 68 | #define CORE_INT0_PIN 38 69 | #define CORE_INT1_PIN 2 70 | #define CORE_INT2_PIN 7 71 | #define CORE_INT3_PIN 8 72 | #define CORE_INT4_PIN 35 73 | 74 | // Chipkit Uno32 - attachInterrupt may not support CHANGE option 75 | #elif defined(__PIC32MX__) && defined(_BOARD_MEGA_) 76 | #define CORE_NUM_INTERRUPT 5 77 | #define CORE_INT0_PIN 3 78 | #define CORE_INT1_PIN 2 79 | #define CORE_INT2_PIN 7 80 | #define CORE_INT3_PIN 21 81 | #define CORE_INT4_PIN 20 82 | 83 | // http://hlt.media.mit.edu/?p=1229 84 | #elif defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 85 | #define CORE_NUM_INTERRUPT 1 86 | #define CORE_INT0_PIN 2 87 | 88 | // Arduino Due (untested) 89 | #elif defined(__SAM3X8E__) 90 | #define CORE_NUM_INTERRUPT 54 91 | #define CORE_INT0_PIN 0 92 | #define CORE_INT1_PIN 1 93 | #define CORE_INT2_PIN 2 94 | #define CORE_INT3_PIN 3 95 | #define CORE_INT4_PIN 4 96 | #define CORE_INT5_PIN 5 97 | #define CORE_INT6_PIN 6 98 | #define CORE_INT7_PIN 7 99 | #define CORE_INT8_PIN 8 100 | #define CORE_INT9_PIN 9 101 | #define CORE_INT10_PIN 10 102 | #define CORE_INT11_PIN 11 103 | #define CORE_INT12_PIN 12 104 | #define CORE_INT13_PIN 13 105 | #define CORE_INT14_PIN 14 106 | #define CORE_INT15_PIN 15 107 | #define CORE_INT16_PIN 16 108 | #define CORE_INT17_PIN 17 109 | #define CORE_INT18_PIN 18 110 | #define CORE_INT19_PIN 19 111 | #define CORE_INT20_PIN 20 112 | #define CORE_INT21_PIN 21 113 | #define CORE_INT22_PIN 22 114 | #define CORE_INT23_PIN 23 115 | #define CORE_INT24_PIN 24 116 | #define CORE_INT25_PIN 25 117 | #define CORE_INT26_PIN 26 118 | #define CORE_INT27_PIN 27 119 | #define CORE_INT28_PIN 28 120 | #define CORE_INT29_PIN 29 121 | #define CORE_INT30_PIN 30 122 | #define CORE_INT31_PIN 31 123 | #define CORE_INT32_PIN 32 124 | #define CORE_INT33_PIN 33 125 | #define CORE_INT34_PIN 34 126 | #define CORE_INT35_PIN 35 127 | #define CORE_INT36_PIN 36 128 | #define CORE_INT37_PIN 37 129 | #define CORE_INT38_PIN 38 130 | #define CORE_INT39_PIN 39 131 | #define CORE_INT40_PIN 40 132 | #define CORE_INT41_PIN 41 133 | #define CORE_INT42_PIN 42 134 | #define CORE_INT43_PIN 43 135 | #define CORE_INT44_PIN 44 136 | #define CORE_INT45_PIN 45 137 | #define CORE_INT46_PIN 46 138 | #define CORE_INT47_PIN 47 139 | #define CORE_INT48_PIN 48 140 | #define CORE_INT49_PIN 49 141 | #define CORE_INT50_PIN 50 142 | #define CORE_INT51_PIN 51 143 | #define CORE_INT52_PIN 52 144 | #define CORE_INT53_PIN 53 145 | 146 | #endif 147 | #endif 148 | 149 | #if !defined(CORE_NUM_INTERRUPT) 150 | #error "Interrupts are unknown for this board, please add to this code" 151 | #endif 152 | #if CORE_NUM_INTERRUPT <= 0 153 | #error "Encoder requires interrupt pins, but this board does not have any :(" 154 | #error "You could try defining ENCODER_DO_NOT_USE_INTERRUPTS as a kludge." 155 | #endif 156 | 157 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/HX711.cpp: -------------------------------------------------------------------------------- 1 | //taken and modified from https://github.com/bogde/HX711 2 | #include 3 | #include "HX711.h" 4 | 5 | HX711::HX711(byte dout, byte pd_sck, byte gain) { 6 | PD_SCK = pd_sck; 7 | DOUT = dout; 8 | 9 | pinMode(PD_SCK, OUTPUT); 10 | pinMode(DOUT, INPUT); 11 | 12 | set_gain(gain); 13 | } 14 | 15 | HX711::~HX711() { 16 | 17 | } 18 | 19 | bool HX711::is_ready() { 20 | return digitalRead(DOUT) == LOW; 21 | } 22 | 23 | void HX711::set_gain(byte gain) { 24 | switch (gain) { 25 | case 128: // channel A, gain factor 128 26 | GAIN = 1; 27 | break; 28 | case 64: // channel A, gain factor 64 29 | GAIN = 3; 30 | break; 31 | case 32: // channel B, gain factor 32 32 | GAIN = 2; 33 | break; 34 | } 35 | 36 | digitalWrite(PD_SCK, LOW); 37 | read(); 38 | } 39 | 40 | long HX711::read() { 41 | // wait for the chip to become ready 42 | while (!is_ready()); 43 | return read_fast(); 44 | } 45 | 46 | long HX711::read_fast() { 47 | unsigned long value = 0; 48 | byte data[3] = { 0 }; 49 | byte filler = 0x00; 50 | 51 | // pulse the clock pin 24 times to read the data 52 | data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST); 53 | data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST); 54 | data[0] = shiftIn(DOUT, PD_SCK, MSBFIRST); 55 | 56 | // set the channel and the gain factor for the next reading using the clock pin 57 | for (unsigned int i = 0; i < GAIN; i++) { 58 | digitalWrite(PD_SCK, HIGH); 59 | digitalWrite(PD_SCK, LOW); 60 | } 61 | 62 | // Datasheet indicates the value is returned as a two's complement value 63 | // Flip all the bits 64 | data[2] = ~data[2]; 65 | data[1] = ~data[1]; 66 | data[0] = ~data[0]; 67 | 68 | // Replicate the most significant bit to pad out a 32-bit signed integer 69 | if ( data[2] & 0x80 ) { 70 | filler = 0xFF; 71 | } else if ((0x7F == data[2]) && (0xFF == data[1]) && (0xFF == data[0])) { 72 | filler = 0xFF; 73 | } else { 74 | filler = 0x00; 75 | } 76 | 77 | // Construct a 32-bit signed integer 78 | value = ( static_cast(filler) << 24 79 | | static_cast(data[2]) << 16 80 | | static_cast(data[1]) << 8 81 | | static_cast(data[0]) ); 82 | 83 | // ... and add 1 84 | return static_cast(++value); 85 | } 86 | 87 | long HX711::read_average(byte times) { 88 | long sum = 0; 89 | for (byte i = 0; i < times; i++) { 90 | sum += read(); 91 | } 92 | return sum / times; 93 | } 94 | 95 | double HX711::get_value(byte times) { 96 | return read_average(times) - OFFSET; 97 | } 98 | 99 | float HX711::get_units(byte times) { 100 | return get_value(times) / SCALE; 101 | } 102 | 103 | float HX711::get_units_fast() { 104 | return (read_fast()-OFFSET)/SCALE; 105 | } 106 | 107 | void HX711::tare(byte times) { 108 | double sum = read_average(times); 109 | set_offset(sum); 110 | } 111 | 112 | void HX711::set_scale(float scale) { 113 | SCALE = scale; 114 | } 115 | 116 | float HX711::get_scale() { 117 | return SCALE; 118 | } 119 | 120 | void HX711::set_offset(long offset) { 121 | OFFSET = offset; 122 | } 123 | 124 | long HX711::get_offset() { 125 | return OFFSET; 126 | } 127 | 128 | void HX711::power_down() { 129 | digitalWrite(PD_SCK, LOW); 130 | digitalWrite(PD_SCK, HIGH); 131 | } 132 | 133 | void HX711::power_up() { 134 | digitalWrite(PD_SCK, LOW); 135 | } 136 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/HX711.h: -------------------------------------------------------------------------------- 1 | //taken and modified from https://github.com/bogde/HX711 2 | #ifndef HX711_h 3 | #define HX711_h 4 | 5 | #if ARDUINO >= 100 6 | #include "Arduino.h" 7 | #else 8 | #include "WProgram.h" 9 | #endif 10 | 11 | class HX711 12 | { 13 | private: 14 | byte PD_SCK; // Power Down and Serial Clock Input Pin 15 | byte DOUT; // Serial Data Output Pin 16 | byte GAIN; // amplification factor 17 | long OFFSET; // used for tare weight 18 | float SCALE; // used to return weight in grams, kg, ounces, whatever 19 | 20 | public: 21 | // define clock and data pin, channel, and gain factor 22 | // channel selection is made by passing the appropriate gain: 128 or 64 for channel A, 32 for channel B 23 | // gain: 128 or 64 for channel A; channel B works with 32 gain factor only 24 | HX711(byte dout, byte pd_sck, byte gain = 128); 25 | 26 | virtual ~HX711(); 27 | 28 | // check if HX711 is ready 29 | // from the datasheet: When output data is not ready for retrieval, digital output pin DOUT is high. Serial clock 30 | // input PD_SCK should be low. When DOUT goes to low, it indicates data is ready for retrieval. 31 | bool is_ready(); 32 | 33 | // set the gain factor; takes effect only after a call to read() 34 | // channel A can be set for a 128 or 64 gain; channel B has a fixed 32 gain 35 | // depending on the parameter, the channel is also set to either A or B 36 | void set_gain(byte gain = 128); 37 | 38 | // waits for the chip to be ready and returns a reading 39 | long read(); 40 | 41 | //returns a reading. chip must be ready before executing this command! 42 | long read_fast(); 43 | 44 | // returns an average reading; times = how many times to read 45 | long read_average(byte times = 10); 46 | 47 | // returns (read_average() - OFFSET), that is the current value without the tare weight; times = how many readings to do 48 | double get_value(byte times = 1); 49 | 50 | // returns get_value() divided by SCALE, that is the raw value divided by a value obtained via calibration 51 | // times = how many readings to do 52 | float get_units(byte times = 1); 53 | 54 | // same as get_units but without averaging and without waiting for chip to be ready 55 | float get_units_fast(); 56 | 57 | // set the OFFSET value for tare weight; times = how many times to read the tare value 58 | void tare(byte times = 10); 59 | 60 | // set the SCALE value; this value is used to convert the raw data to "human readable" data (measure units) 61 | void set_scale(float scale = 1.f); 62 | 63 | // get the current SCALE 64 | float get_scale(); 65 | 66 | // set OFFSET, the value that's subtracted from the actual reading (tare weight) 67 | void set_offset(long offset = 0); 68 | 69 | // get the current OFFSET 70 | long get_offset(); 71 | 72 | // puts the chip into power down mode 73 | void power_down(); 74 | 75 | // wakes up the chip after power down mode 76 | void power_up(); 77 | }; 78 | 79 | #endif /* HX711_h */ 80 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/HX711_readme.txt: -------------------------------------------------------------------------------- 1 | //taken from https://github.com/bogde/HX711 2 | HX711 3 | ===== 4 | 5 | An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales. 6 | 7 | This is my humble attempt at creating an Arduino library for this ADC: 8 | http://www.dfrobot.com/image/data/SEN0160/hx711_english.pdf 9 | 10 | Other libraries exist, including this very good one, which I first used and which is the starting point for my library: 11 | https://github.com/aguegu/ardulibs/tree/master/hx711 12 | 13 | Although other libraries exist, I needed a slightly different approach, so here's how my library is different than others: 14 | 15 | 1. It provides a tare() function, which "resets" the scale to 0. Many other implementations calculate the tare weight when the ADC is initialized only. I needed a way to be able to set the tare weight at any time. Use case: place an empty container on the scale, call tare() to reset the readings to 0, fill the container and get the weight of the content. 16 | 17 | 2. It provides a power_down() function, to put the ADC into a low power mode. According to the datasheet, "When PD_SCK pin changes from low to high and stays at high for longer than 60μs, HX711 enters power down mode". Use case: battery powered scales. Accordingly, there is a power_up() function to get the chip out of the low power mode. 18 | 19 | 3. It has a set_gain(byte gain) function that allows you to set the gain factor and select the channel. According to the datasheet, "Channel A can be programmed with a gain of 128 or 64, corresponding to a full-scale differential input voltage of ±20mV or ±40mV respectively, when a 5V supply is connected to AVDD analog power supply pin. Channel B has a fixed gain of 32.". The same function is used to select the channel A or channel B, by passing 128 or 64 for channel A, or 32 for channel B as the parameter. The default value is 128, which means "channel A with a gain factor of 128", so one can simply call set_gain(). Also, the function is called from the constructor. 20 | 21 | 4. The constructor has an extra parameter "gain" that allows you to set the gain factor and channel. The constructor calls the "set_gain" function mentioned above. 22 | 23 | 5. The "get_value" and "get_units" functions can receive an extra parameter "times", and they will return the average of multiple readings instead of a single reading. 24 | 25 | How to Calibrate Your Scale 26 | 27 | 1. Call set_scale() with no parameter. 28 | 2. Call tare() with no parameter. 29 | 3. Place a known weight on the scale and call get_units(10). 30 | 4. Divide the result in step 3 to your known weight. You should get about the parameter you need to pass to set_scale. 31 | 5. Adjust the parameter in step 4 until you get an accurate reading. 32 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/LiquidCrystalDogm.h: -------------------------------------------------------------------------------- 1 | #ifndef LiquidCrystal_h 2 | #define LiquidCrystal_h 3 | 4 | #include 5 | #include "Print.h" 6 | 7 | // commands 8 | #define LCD_CLEARDISPLAY 0x01 9 | #define LCD_RETURNHOME 0x02 10 | #define LCD_ENTRYMODESET 0x04 11 | #define LCD_DISPLAYCONTROL 0x08 12 | #define LCD_CURSORSHIFT 0x10 13 | #define LCD_FUNCTIONSET 0x29 14 | #define LCD_SETCGRAMADDR 0x40 15 | #define LCD_SETDDRAMADDR 0x80 16 | 17 | // flags for display entry mode 18 | #define LCD_ENTRYRIGHT 0x00 19 | #define LCD_ENTRYLEFT 0x02 20 | #define LCD_ENTRYSHIFTINCREMENT 0x01 21 | #define LCD_ENTRYSHIFTDECREMENT 0x00 22 | 23 | // flags for display on/off control 24 | #define LCD_DISPLAYON 0x04 25 | #define LCD_DISPLAYOFF 0x00 26 | #define LCD_CURSORON 0x02 27 | #define LCD_CURSOROFF 0x00 28 | #define LCD_BLINKON 0x01 29 | #define LCD_BLINKOFF 0x00 30 | 31 | // flags for display/cursor shift 32 | #define LCD_DISPLAYMOVE 0x08 33 | #define LCD_CURSORMOVE 0x00 34 | #define LCD_MOVERIGHT 0x04 35 | #define LCD_MOVELEFT 0x00 36 | 37 | // flags for function set 38 | #define LCD_8BITMODE 0x10 39 | #define LCD_4BITMODE 0x00 40 | #define LCD_2LINE 0x08 41 | #define LCD_1LINE 0x00 42 | #define LCD_5x10DOTS 0x04 43 | #define LCD_5x8DOTS 0x00 44 | 45 | class LiquidCrystal : public Print 46 | { 47 | public: 48 | LiquidCrystal(uint8_t rs, uint8_t enable, 49 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 50 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 51 | LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, 52 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 53 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 54 | LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, 55 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 56 | LiquidCrystal(uint8_t rs, uint8_t enable, 57 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 58 | 59 | void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, 60 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 61 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 62 | 63 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 64 | 65 | void clear(); 66 | void home(); 67 | 68 | void noDisplay(); 69 | void display(); 70 | void noBlink(); 71 | void blink(); 72 | void noCursor(); 73 | void cursor(); 74 | void scrollDisplayLeft(); 75 | void scrollDisplayRight(); 76 | void leftToRight(); 77 | void rightToLeft(); 78 | void autoscroll(); 79 | void noAutoscroll(); 80 | 81 | void createChar(uint8_t, const uint8_t[]); 82 | void setCursor(uint8_t, uint8_t); 83 | virtual size_t write(uint8_t); 84 | void command(uint8_t); 85 | 86 | using Print::write; 87 | private: 88 | void send(uint8_t, uint8_t); 89 | void write4bits(uint8_t); 90 | void write8bits(uint8_t); 91 | void pulseEnable(); 92 | 93 | uint8_t _rs_pin; // LOW: command. HIGH: character. 94 | uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. 95 | uint8_t _enable_pin; // activated by a HIGH pulse. 96 | uint8_t _data_pins[8]; 97 | 98 | uint8_t _displayfunction; 99 | uint8_t _displaycontrol; 100 | uint8_t _displaymode; 101 | 102 | uint8_t _initialized; 103 | 104 | uint8_t _numlines,_currline; 105 | }; 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/MenuSystem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | MenuSystem.h - Library for creating menu structures. 3 | Created by Jon Black, August 8th 2011. 4 | Released into the public domain. 5 | 6 | License: LGPL 3 7 | */ 8 | 9 | #include "MenuSystem.h" 10 | 11 | // ********************************************************* 12 | // MenuComponent 13 | // ********************************************************* 14 | 15 | MenuComponent::MenuComponent(const char* name) 16 | : _name(name) 17 | { 18 | } 19 | 20 | const char* MenuComponent::get_name() const 21 | { 22 | return _name; 23 | } 24 | 25 | void MenuComponent::set_name(const char* name) 26 | { 27 | _name = name; 28 | } 29 | 30 | 31 | // ********************************************************* 32 | // Menu 33 | // ********************************************************* 34 | 35 | Menu::Menu(const char* name) 36 | : MenuComponent(name), 37 | _p_sel_menu_component(NULL), 38 | _p_parent(NULL), 39 | _num_menu_components(0), 40 | _cur_menu_component_num(0) 41 | { 42 | } 43 | 44 | boolean Menu::next(boolean loop) 45 | { 46 | if (_cur_menu_component_num != _num_menu_components - 1) 47 | { 48 | _cur_menu_component_num++; 49 | _p_sel_menu_component = _menu_components[_cur_menu_component_num]; 50 | 51 | return true; 52 | } else if (loop) 53 | { 54 | _cur_menu_component_num = 0; 55 | _p_sel_menu_component = _menu_components[_cur_menu_component_num]; 56 | 57 | return true; 58 | } 59 | 60 | return false; 61 | } 62 | 63 | boolean Menu::prev(boolean loop) 64 | { 65 | if (_cur_menu_component_num != 0) 66 | { 67 | _cur_menu_component_num--; 68 | _p_sel_menu_component = _menu_components[_cur_menu_component_num]; 69 | 70 | return true; 71 | } else if (loop) 72 | { 73 | _cur_menu_component_num = _num_menu_components - 1; 74 | _p_sel_menu_component = _menu_components[_cur_menu_component_num]; 75 | 76 | return true; 77 | } 78 | 79 | return false; 80 | } 81 | 82 | MenuComponent* Menu::activate() 83 | { 84 | MenuComponent* pComponent = _menu_components[_cur_menu_component_num]; 85 | 86 | if (pComponent == NULL) 87 | return NULL; 88 | 89 | return pComponent->select(); 90 | } 91 | 92 | MenuComponent* Menu::select() 93 | { 94 | return this; 95 | } 96 | 97 | void Menu::add_item(MenuItem* pItem, void (*on_select)(MenuItem*)) 98 | { 99 | // Prevent memory overrun 100 | if (_num_menu_components == MAX_MENU_ITEMS) 101 | return; 102 | 103 | _menu_components[_num_menu_components] = pItem; 104 | 105 | pItem->set_select_function(on_select); 106 | 107 | if (_num_menu_components == 0) 108 | _p_sel_menu_component = pItem; 109 | 110 | _num_menu_components++; 111 | } 112 | 113 | Menu const* Menu::get_parent() const 114 | { 115 | return _p_parent; 116 | } 117 | 118 | void Menu::set_parent(Menu* pParent) 119 | { 120 | _p_parent = pParent; 121 | } 122 | 123 | Menu const* Menu::add_menu(Menu* pMenu) 124 | { 125 | pMenu->set_parent(this); 126 | 127 | _menu_components[_num_menu_components] = pMenu; 128 | 129 | if (_num_menu_components == 0) 130 | _p_sel_menu_component = pMenu; 131 | 132 | _num_menu_components++; 133 | 134 | return pMenu; 135 | } 136 | 137 | MenuComponent const* Menu::get_menu_component(byte index) const 138 | { 139 | return _menu_components[index]; 140 | } 141 | 142 | MenuComponent const* Menu::get_selected() const 143 | { 144 | return _p_sel_menu_component; 145 | } 146 | 147 | byte Menu::get_num_menu_components() const 148 | { 149 | return _num_menu_components; 150 | } 151 | 152 | byte Menu::get_cur_menu_component_num() const 153 | { 154 | return _cur_menu_component_num; 155 | } 156 | 157 | // ********************************************************* 158 | // MenuItem 159 | // ********************************************************* 160 | 161 | MenuItem::MenuItem(const char* name) 162 | : MenuComponent(name), 163 | _on_select(0) 164 | { 165 | } 166 | 167 | void MenuItem::set_select_function(void (*on_select)(MenuItem*)) 168 | { 169 | _on_select = on_select; 170 | } 171 | 172 | MenuComponent* MenuItem::select() 173 | { 174 | if (_on_select != NULL) 175 | _on_select(this); 176 | 177 | return 0; 178 | } 179 | 180 | // ********************************************************* 181 | // MenuSystem 182 | // ********************************************************* 183 | 184 | MenuSystem::MenuSystem() 185 | : _p_root_menu(NULL), 186 | _p_curr_menu(NULL) 187 | { 188 | } 189 | 190 | boolean MenuSystem::next(boolean loop) 191 | { 192 | return _p_curr_menu->next(loop); 193 | } 194 | 195 | boolean MenuSystem::prev(boolean loop) 196 | { 197 | return _p_curr_menu->prev(loop); 198 | } 199 | 200 | void MenuSystem::select() 201 | { 202 | MenuComponent* pComponent = _p_curr_menu->activate(); 203 | 204 | if (pComponent != NULL) 205 | { 206 | _p_curr_menu = (Menu*) pComponent; 207 | } 208 | else 209 | { 210 | // A menu item was selected, so reset the menu ready for when 211 | // it's used again. 212 | _p_curr_menu = _p_root_menu; 213 | } 214 | } 215 | 216 | boolean MenuSystem::back() 217 | { 218 | if (_p_curr_menu != _p_root_menu) 219 | { 220 | _p_curr_menu = const_cast(_p_curr_menu->get_parent()); 221 | return true; 222 | } 223 | 224 | // We are already in the root menu 225 | return false; 226 | } 227 | 228 | void MenuSystem::set_root_menu(Menu* p_root_menu) 229 | { 230 | _p_root_menu = p_root_menu; 231 | _p_curr_menu = p_root_menu; 232 | } 233 | 234 | Menu const* MenuSystem::get_current_menu() const 235 | { 236 | return _p_curr_menu; 237 | } 238 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/MenuSystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | MenuSystem.h - Library for creating menu structures. 3 | Created by Jon Black, August 8th 2011. 4 | Released into the public domain. 5 | 6 | License: LGPL 3 7 | */ 8 | 9 | #ifndef MENUSYSTEM_H 10 | #define MENUSYSTEM_H 11 | 12 | #if defined(ARDUINO) && ARDUINO >= 100 13 | #include 14 | #else 15 | #include 16 | #endif 17 | 18 | 19 | #define MAX_MENU_ITEMS 10 20 | 21 | 22 | class MenuComponent 23 | { 24 | public: 25 | MenuComponent(const char* name); 26 | 27 | void set_name(const char* name); 28 | const char* get_name() const; 29 | 30 | virtual MenuComponent* select() = 0; 31 | 32 | protected: 33 | const char* _name; 34 | }; 35 | 36 | 37 | class MenuItem : public MenuComponent 38 | { 39 | public: 40 | MenuItem(const char* name); 41 | 42 | void set_select_function(void (*on_select)(MenuItem*)); 43 | 44 | virtual MenuComponent* select(); 45 | 46 | private: 47 | void (*_on_select)(MenuItem*); 48 | }; 49 | 50 | 51 | class Menu : public MenuComponent 52 | { 53 | public: 54 | Menu(const char* name); 55 | 56 | boolean next(boolean loop=false); 57 | boolean prev(boolean loop=false); 58 | MenuComponent* activate(); 59 | virtual MenuComponent* select(); 60 | 61 | void add_item(MenuItem* pItem, void (*on_select)(MenuItem*)); 62 | Menu const* add_menu(Menu* pMenu); 63 | 64 | void set_parent(Menu* pParent); 65 | Menu const* get_parent() const; 66 | 67 | MenuComponent const* get_selected() const; 68 | MenuComponent const* get_menu_component(byte index) const; 69 | 70 | byte get_num_menu_components() const; 71 | byte get_cur_menu_component_num() const; 72 | 73 | private: 74 | MenuComponent* _p_sel_menu_component; 75 | MenuComponent* _menu_components[MAX_MENU_ITEMS]; 76 | Menu* _p_parent; 77 | byte _num_menu_components; 78 | byte _cur_menu_component_num; 79 | }; 80 | 81 | 82 | class MenuSystem 83 | { 84 | public: 85 | MenuSystem(); 86 | 87 | boolean next(boolean loop=false); 88 | boolean prev(boolean loop=false); 89 | void select(); 90 | boolean back(); 91 | 92 | void set_root_menu(Menu* p_root_menu); 93 | 94 | Menu const* get_current_menu() const; 95 | 96 | private: 97 | Menu* _p_root_menu; 98 | Menu* _p_curr_menu; 99 | }; 100 | 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/PID_v1_nano.h: -------------------------------------------------------------------------------- 1 | #ifndef PID_v1_h 2 | #define PID_v1_h 3 | #define LIBRARY_VERSION 1.0.0 4 | 5 | class PID 6 | { 7 | 8 | 9 | public: 10 | 11 | //Constants used in some of the functions below 12 | #define AUTOMATIC 1 13 | #define MANUAL 0 14 | #define DIRECT 0 15 | #define REVERSE 1 16 | 17 | //commonly used functions ************************************************************************** 18 | PID(double*, double*, double*, // * constructor. links the PID to the Input, Output, and 19 | double, double, double, int); // Setpoint. Initial tuning parameters are also set here 20 | 21 | void SetMode(int Mode); // * sets PID to either Manual (0) or Auto (non-0) 22 | 23 | bool Compute(); // * performs the PID calculation. it should be 24 | // called every time loop() cycles. ON/OFF and 25 | // calculation frequency can be set using SetMode 26 | // SetSampleTime respectively 27 | 28 | void SetOutputLimits(double, double); //clamps the output to a specific range. 0-255 by default, but 29 | //it's likely the user will want to change this depending on 30 | //the application 31 | 32 | 33 | 34 | //available but not commonly used functions ******************************************************** 35 | void SetTunings(double, double, // * While most users will set the tunings once in the 36 | double); // constructor, this function gives the user the option 37 | // of changing tunings during runtime for Adaptive control 38 | void SetControllerDirection(int); // * Sets the Direction, or "Action" of the controller. DIRECT 39 | // means the output will increase when error is positive. REVERSE 40 | // means the opposite. it's very unlikely that this will be needed 41 | // once it is set in the constructor. 42 | void SetSampleTime(int); // * sets the frequency, in Milliseconds, with which 43 | // the PID calculation is performed. default is 100 44 | 45 | void ResetIntegral(); //resets integral part 46 | void ShrinkIntegral(); //shrinks integral part, used to slowly fade out 47 | 48 | 49 | 50 | //Display functions **************************************************************** 51 | double GetKp(); // These functions query the pid for interal values. 52 | double GetKi(); // they were created mainly for the pid front-end, 53 | double GetKd(); // where it's important to know what is actually 54 | int GetMode(); // inside the PID. 55 | double GetI(); // Get current I 56 | void SetI(double); // Set current I 57 | int GetDirection(); // 58 | 59 | private: 60 | void Initialize(); 61 | 62 | double dispKp; // * we'll hold on to the tuning parameters in user-entered 63 | double dispKi; // format for display purposes 64 | double dispKd; // 65 | 66 | double kp; // * (P)roportional Tuning Parameter 67 | double ki; // * (I)ntegral Tuning Parameter 68 | double kd; // * (D)erivative Tuning Parameter 69 | 70 | int controllerDirection; 71 | 72 | double *myInput; // * Pointers to the Input, Output, and Setpoint variables 73 | double *myOutput; // This creates a hard link between the variables and the 74 | double *mySetpoint; // PID, freeing the user from having to constantly tell us 75 | // what these values are. with pointers we'll just know. 76 | 77 | unsigned long lastTime, lastTimeShrink; 78 | double ITerm, lastInput; 79 | 80 | unsigned long SampleTime; 81 | double outMin, outMax; 82 | bool inAuto; 83 | }; 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/VESC/buffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * buffer.c 20 | * 21 | * Created on: 13 maj 2013 22 | * Author: benjamin 23 | */ 24 | 25 | #include "buffer.h" 26 | 27 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index) { 28 | buffer[(*index)++] = number >> 8; 29 | buffer[(*index)++] = number; 30 | } 31 | 32 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index) { 33 | buffer[(*index)++] = number >> 8; 34 | buffer[(*index)++] = number; 35 | } 36 | 37 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index) { 38 | buffer[(*index)++] = number >> 24; 39 | buffer[(*index)++] = number >> 16; 40 | buffer[(*index)++] = number >> 8; 41 | buffer[(*index)++] = number; 42 | } 43 | 44 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index) { 45 | buffer[(*index)++] = number >> 24; 46 | buffer[(*index)++] = number >> 16; 47 | buffer[(*index)++] = number >> 8; 48 | buffer[(*index)++] = number; 49 | } 50 | 51 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index) { 52 | buffer_append_int16(buffer, (int16_t)(number * scale), index); 53 | } 54 | 55 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index) { 56 | buffer_append_int32(buffer, (int32_t)(number * scale), index); 57 | } 58 | 59 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index) { 60 | int16_t res = ((uint16_t) buffer[*index]) << 8 | 61 | ((uint16_t) buffer[*index + 1]); 62 | *index += 2; 63 | return res; 64 | } 65 | 66 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) { 67 | uint16_t res = ((uint16_t) buffer[*index]) << 8 | 68 | ((uint16_t) buffer[*index + 1]); 69 | *index += 2; 70 | return res; 71 | } 72 | 73 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) { 74 | int32_t res = ((uint32_t) buffer[*index]) << 24 | 75 | ((uint32_t) buffer[*index + 1]) << 16 | 76 | ((uint32_t) buffer[*index + 2]) << 8 | 77 | ((uint32_t) buffer[*index + 3]); 78 | *index += 4; 79 | return res; 80 | } 81 | 82 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) { 83 | uint32_t res = ((uint32_t) buffer[*index]) << 24 | 84 | ((uint32_t) buffer[*index + 1]) << 16 | 85 | ((uint32_t) buffer[*index + 2]) << 8 | 86 | ((uint32_t) buffer[*index + 3]); 87 | *index += 4; 88 | return res; 89 | } 90 | 91 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index) { 92 | return (float)buffer_get_int16(buffer, index) / scale; 93 | } 94 | 95 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index) { 96 | return (float)buffer_get_int32(buffer, index) / scale; 97 | } 98 | 99 | bool buffer_get_bool(const uint8_t *buffer, int32_t *index) { 100 | 101 | if (buffer[*index] == 1) 102 | { 103 | index++; 104 | return true; 105 | } 106 | else 107 | { 108 | index++; 109 | return false; 110 | } 111 | 112 | } 113 | 114 | void buffer_append_bool(uint8_t *buffer,bool value, int32_t *index) { 115 | 116 | if (value == true) 117 | { 118 | buffer[*index] = 1; 119 | (*index)++; 120 | } 121 | else 122 | { 123 | buffer[*index] = 0; 124 | (*index)++; 125 | } 126 | 127 | } -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/VESC/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * buffer.h 20 | * 21 | * Created on: 13 maj 2013 22 | * Author: benjamin 23 | */ 24 | 25 | #ifndef BUFFER_H_ 26 | #define BUFFER_H_ 27 | 28 | #include 29 | 30 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index); 31 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index); 32 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index); 33 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index); 34 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index); 35 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index); 36 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index); 37 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index); 38 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index); 39 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index); 40 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index); 41 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index); 42 | bool buffer_get_bool(const uint8_t *buffer, int32_t *index); 43 | void buffer_append_bool(uint8_t *buffer,bool value, int32_t *index); 44 | #endif /* BUFFER_H_ */ 45 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/VESC/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 - 2017 Andreas Chaitidis Andreas.Chaitidis@gmail.com 3 | This program is free software : you can redistribute it and / or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 10 | GNU General Public License for more details. 11 | You should have received a copy of the GNU General Public License 12 | along with this program.If not, see . 13 | */ 14 | 15 | //The Config.h is a file, that I use in other programs usualy. So I define also the serial ports there. If you don't want to 16 | //use it, just comment the include statement in the VescUart.h out. 17 | 18 | #ifndef _CONFIG_h 19 | #define _CONFIG_h 20 | 21 | #define SERIALIO Serial1 22 | #define DEBUGSERIAL Serial 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/VESC/crc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * crc.c 20 | * 21 | * Created on: 26 feb 2012 22 | * Author: benjamin 23 | */ 24 | #include "crc.h" 25 | 26 | // CRC Table 27 | const unsigned short crc16_tab[] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 28 | 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 29 | 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 30 | 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 31 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 32 | 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 33 | 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 34 | 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 35 | 0x0840, 0x1861, 0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 36 | 0x9969, 0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 37 | 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 38 | 0xab1a, 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 39 | 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 40 | 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 41 | 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 42 | 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 43 | 0x5004, 0x4025, 0x7046, 0x6067, 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 44 | 0xd31c, 0xe37f, 0xf35e, 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 45 | 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 46 | 0xc50d, 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 47 | 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 48 | 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 0xd94c, 0xc96d, 49 | 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 50 | 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 51 | 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 52 | 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 53 | 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 54 | 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 55 | 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 }; 56 | 57 | unsigned short crc16(unsigned char *buf, unsigned int len) { 58 | unsigned int i; 59 | unsigned short cksum = 0; 60 | for (i = 0; i < len; i++) { 61 | cksum = crc16_tab[(((cksum >> 8) ^ *buf++) & 0xFF)] ^ (cksum << 8); 62 | } 63 | return cksum; 64 | } 65 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/VESC/crc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * crc.h 20 | * 21 | * Created on: 26 feb 2012 22 | * Author: benjamin 23 | */ 24 | 25 | #ifndef CRC_H_ 26 | #define CRC_H_ 27 | 28 | /* 29 | * Functions 30 | */ 31 | unsigned short crc16(unsigned char *buf, unsigned int len); 32 | 33 | #endif /* CRC_H_ */ 34 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/VESC/vesc_uart.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Daniel Claes on 01/05/2016. 3 | // 4 | 5 | #ifndef PEDELEC_CONTROLLER_VESC_UART_H 6 | #define PEDELEC_CONTROLLER_VESC_UART_H 7 | 8 | /* 9 | Copyright 2015 - 2017 Andreas Chaitidis Andreas.Chaitidis@gmail.com 10 | 11 | This program is free software : you can redistribute it and / or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program.If not, see . 23 | 24 | */ 25 | 26 | /*TThis library was created on an Adruinio 2560 with different serial ports to have a better possibility 27 | to debug. The serial ports are define with #define: 28 | #define SERIALIO Serial1 for the UART port to VESC 29 | #define DEBUGSERIAL Serial for debuging over USB 30 | So you need here to define the right serial port for your arduino. 31 | If you want to use debug, uncomment DEBUGSERIAL and define a port.*/ 32 | 33 | #if defined(ARDUINO) && ARDUINO >= 100 34 | #include "Arduino.h" 35 | #else 36 | #include "WProgram.h" 37 | #endif 38 | 39 | #include "datatypes.h" 40 | 41 | bool unpack_payload(uint8_t *message, int lenMes, uint8_t *payload, int lenPa); 42 | bool process_read_package(uint8_t *message, mc_values &values, int len); 43 | 44 | ///PackSendPayload Packs the payload and sends it over Serial. 45 | ///Define in a Config.h a SERIAL with the Serial in Arduino Style you want to you 46 | ///@param: payload as the payload [unit8_t Array] with length of int lenPayload 47 | ///@return the number of bytes send 48 | int send_payload(uint8_t* payload, uint8_t lenPay); 49 | 50 | ///ReceiveUartMessage receives the a message over Serial 51 | ///Define in a Config.h a SERIAL with the Serial in Arduino Style you want to you 52 | ///@parm the payload as the payload [unit8_t Array] 53 | ///@return the number of bytes receeived within the payload 54 | 55 | int process_received_msg(uint8_t* payloadReceived); 56 | 57 | ///Help Function to print struct bldcMeasure over Serial for Debug 58 | ///Define in a Config.h the DEBUGSERIAL you want to use 59 | 60 | void serial_print(const mc_values& values); 61 | 62 | ///Help Function to print uint8_t array over Serial for Debug 63 | ///Define in a Config.h the DEBUGSERIAL you want to use 64 | 65 | void serial_print(uint8_t* data, int len); 66 | 67 | ///Sends a command to VESC and stores the returned data 68 | ///@param bldcMeasure struct with received data 69 | //@return true if sucess 70 | bool vesc_get_values(mc_values &values); 71 | 72 | ///Sends a command to VESC to control the motor current 73 | ///@param current as float with the current for the motor 74 | 75 | void set_motor_current(float current); 76 | 77 | ///Sends a command to VESC to control the motor brake 78 | ///@param breakCurrent as float with the current for the brake 79 | 80 | void set_brake_current(float brakeCurrent); 81 | 82 | 83 | #endif //PEDELEC_CONTROLLER_VESC_UART_H 84 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/display.h: -------------------------------------------------------------------------------- 1 | /* 2 | Generic display init and update functions 3 | Written by Thomas Jarosch 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #ifndef DISPLAY_H 20 | #define DISPLAY_H 21 | 22 | #include "Arduino.h" 23 | 24 | void display_init(); 25 | void display_update(); 26 | void display_debug(HardwareSerial* localSerial); 27 | 28 | void display_show_important_info(const char *str, int duration_secs); 29 | void display_show_important_info(const __FlashStringHelper *str, int duration_secs); 30 | 31 | void display_show_welcome_msg(); 32 | void display_show_welcome_msg_temp(); 33 | 34 | void display_prev_view(); 35 | void display_next_view(); 36 | 37 | #if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_SERIAL) 38 | void display_16x_serial_enable_backlight(); 39 | void display_16x_serial_disable_backlight(); 40 | #endif 41 | 42 | //definitions for different screen mode 43 | typedef enum {DISPLAY_MODE_TEXT, 44 | DISPLAY_MODE_GRAPHIC, // Note: Same as _TEXT on 16x2 displays 45 | DISPLAY_MODE_MENU, 46 | DISPLAY_MODE_IMPORTANT_INFO 47 | } display_mode_type; 48 | 49 | typedef enum {DISPLAY_VIEW_MAIN=0, 50 | #if (DISPLAY_TYPE & DISPLAY_TYPE_NOKIA)&&(defined(DV_GRAPHIC)) 51 | DISPLAY_VIEW_GRAPHIC, 52 | #endif 53 | #if (DISPLAY_TYPE & DISPLAY_TYPE_16X2) 54 | #if defined(DV_TIME) 55 | DISPLAY_VIEW_TIME, 56 | #endif 57 | #if defined(DV_BATTERY) 58 | DISPLAY_VIEW_BATTERY, 59 | #endif 60 | #endif 61 | #if (defined(SUPPORT_BMP085) || defined(SUPPORT_DSPC01) || defined(SUPPORT_TEMP_SENSOR))&&defined(DV_ENVIRONMENT) 62 | DISPLAY_VIEW_ENVIRONMENT, 63 | #endif 64 | #if defined(DV_HUMAN) 65 | DISPLAY_VIEW_HUMAN, 66 | #endif 67 | #if defined(DV_ODOMETER) 68 | DISPLAY_VIEW_ODOMETER, 69 | #endif 70 | _DISPLAY_VIEW_END 71 | } display_view_type; 72 | 73 | extern display_view_type display_view; 74 | 75 | extern display_mode_type display_mode; //currently display mode 76 | extern boolean display_force_text; //only valid for Nokia displays 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/display_backlight.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Generic LCD display backlight functions 3 | (c) 2012 Thomas Jarosch 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #include "display_backlight.h" 20 | #include "display.h" 21 | #include "config.h" 22 | 23 | #ifdef SUPPORT_DISPLAY_BACKLIGHT 24 | const unsigned int backlight_default_show_ms = 5 * 1000; // Time backlight stays on by default 25 | const unsigned int backlight_blink_pause = 500; // Blink mode: Number of milliseconds between blink switch 26 | const unsigned int backlight_blink_goal = 4; // Number of blinks to do 27 | 28 | bool force_backlight_on = false; 29 | 30 | enum backlight_states 31 | { 32 | BacklightOff, // backlight is off 33 | BacklightTriggerOff, // backlight should be disabled 34 | BacklightOn, // backlight is on 35 | BacklightTriggerOn, // backlight should be enabled 36 | BacklightBlink, // backlight in blick mode 37 | BacklightTriggerBlink // backlight should start to blink 38 | }; 39 | 40 | backlight_states backlight_state = BacklightOff; 41 | unsigned long backlight_next_event_ms = 0; // When should we process next backlight state 42 | 43 | unsigned int backlight_show_ms = 0; // Custom show time if wanted 44 | bool backlight_blink_currently_enabled = false; // Blink mode: True if backlight is currently on 45 | bool backlight_blink_done_stay_on = false; // If true we stay on after blinking 46 | unsigned int backlight_blink_count = 0; // Number of blinks done 47 | 48 | static void turn_backlight_on() 49 | { 50 | #if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_SERIAL) 51 | display_16x_serial_enable_backlight(); 52 | #elif HARDWARE_REV >= 20 53 | // TODO: Make configurable 54 | bitSet(PORTH, 2); 55 | #else 56 | digitalWrite(display_backlight_pin, HIGH); 57 | #endif 58 | } 59 | 60 | static void turn_backlight_off() 61 | { 62 | // User wants the backlight to be temporarily "always on" 63 | if (force_backlight_on) 64 | { 65 | turn_backlight_on(); 66 | return; 67 | } 68 | 69 | #if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_SERIAL) 70 | display_16x_serial_disable_backlight(); 71 | #elif HARDWARE_REV >= 20 72 | // TODO: Make configurable 73 | bitClear(PORTH, 2); 74 | #else 75 | digitalWrite(display_backlight_pin, LOW); 76 | #endif 77 | } 78 | 79 | static void enter_backlight_state(const backlight_states new_state) 80 | { 81 | // We reached the next backlight event. Process it 82 | switch (new_state) 83 | { 84 | case BacklightTriggerOn: 85 | backlight_state = BacklightOn; 86 | backlight_next_event_ms = millis() + backlight_show_ms; 87 | turn_backlight_on(); 88 | break; 89 | case BacklightTriggerBlink: 90 | backlight_blink_count = 0; 91 | backlight_blink_currently_enabled = false; 92 | backlight_state = BacklightBlink; 93 | case BacklightBlink: 94 | ++backlight_blink_count; 95 | backlight_next_event_ms = millis() + backlight_blink_pause; 96 | 97 | // Trigger state change if we are done blinking 98 | if (backlight_blink_count > backlight_blink_goal) 99 | { 100 | if (backlight_blink_done_stay_on) 101 | { 102 | backlight_show_ms = backlight_default_show_ms; 103 | backlight_state = BacklightTriggerOn; 104 | } 105 | else 106 | backlight_state = BacklightTriggerOff; 107 | } 108 | 109 | backlight_blink_currently_enabled = !backlight_blink_currently_enabled; 110 | if (backlight_blink_currently_enabled) 111 | turn_backlight_on(); 112 | else 113 | turn_backlight_off(); 114 | break; 115 | case BacklightTriggerOff: 116 | case BacklightOn: 117 | case BacklightOff: 118 | default: 119 | backlight_state = BacklightOff; 120 | backlight_next_event_ms = 0; 121 | backlight_show_ms = backlight_default_show_ms; 122 | backlight_blink_count = 0; 123 | backlight_blink_currently_enabled = false; 124 | backlight_blink_done_stay_on = false; 125 | turn_backlight_off(); 126 | break; 127 | } 128 | } 129 | 130 | void enable_backlight() 131 | { 132 | backlight_show_ms = backlight_default_show_ms; 133 | enter_backlight_state(BacklightTriggerOn); 134 | } 135 | 136 | void enable_custom_backlight(unsigned int duration_ms) 137 | { 138 | backlight_show_ms = duration_ms; 139 | enter_backlight_state(BacklightTriggerOn); 140 | } 141 | 142 | void blink_backlight() 143 | { 144 | backlight_blink_done_stay_on = false; 145 | enter_backlight_state(BacklightTriggerBlink); 146 | } 147 | 148 | void blink_backlight_stay_on() 149 | { 150 | backlight_blink_done_stay_on = true; 151 | enter_backlight_state(BacklightTriggerBlink); 152 | } 153 | 154 | void handle_backlight() 155 | { 156 | if (backlight_state == BacklightOff) 157 | return; 158 | 159 | if (millis() < backlight_next_event_ms) 160 | return; 161 | 162 | // Enter next backlight state 163 | enter_backlight_state(backlight_state); 164 | } 165 | 166 | bool toggle_force_backlight_on() 167 | { 168 | force_backlight_on = !force_backlight_on; 169 | return force_backlight_on; 170 | } 171 | 172 | #endif 173 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/display_backlight.h: -------------------------------------------------------------------------------- 1 | /* 2 | Generic LCD display backlight functions 3 | (c) 2012 Thomas Jarosch 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #ifndef DISPLAY_BACKLIGHT_H 20 | #define DISPLAY_BACKLIGHT_H 21 | 22 | #include "config.h" 23 | 24 | #ifdef SUPPORT_DISPLAY_BACKLIGHT 25 | void enable_backlight(); 26 | void enable_custom_backlight(unsigned int duration_ms); 27 | void blink_backlight(); 28 | void blink_backlight_stay_on(); 29 | void handle_backlight(); 30 | 31 | bool toggle_force_backlight_on(); 32 | 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/display_bafang.h: -------------------------------------------------------------------------------- 1 | /* 2 | Library for Bafang BBS01/BBS02 Displays (C965) 3 | 4 | Copyright © 2016 Jens Kießling (jenskiessling@gmail.com) 5 | inspired by Kingmeter Library (Michael Fabry) 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | */ 21 | 22 | 23 | #ifndef BAFANG_H 24 | #define BAFANG_H 25 | 26 | 27 | // Includes 28 | #include "config.h" 29 | 30 | #if (DISPLAY_TYPE & DISPLAY_TYPE_BAFANG) 31 | 32 | #if HARDWARE_REV < 20 33 | #include 34 | #endif 35 | 36 | 37 | // Definitions 38 | #define BF_CMD_STARTREQUEST 17 39 | #define BF_CMD_STARTINFO 22 40 | #define BF_CMD_LEVEL 11 41 | #define BF_CMD_LIGHT 26 42 | #define BF_CMD_WHEELDIAM 31 43 | #define BF_CMD_GETSPEED 32 44 | #define BF_CMD_GETERROR 8 45 | #define BF_CMD_GETBAT 17 46 | #define BF_CMD_GETPOWER 10 47 | #define BF_CMD_GET2 49 48 | 49 | #define BF_LIGHTON 241 50 | 51 | #define BF_MAX_RXBUFF 6 52 | #define BF_MAX_TXBUFF 3 53 | 54 | #define BF_LEVEL0 0 55 | #define BF_LEVEL1 1 56 | #define BF_LEVEL2 11 57 | #define BF_LEVEL3 12 58 | #define BF_LEVEL4 13 59 | #define BF_LEVEL5 2 60 | #define BF_LEVEL6 21 61 | #define BF_LEVEL7 22 62 | #define BF_LEVEL8 23 63 | #define BF_LEVEL9 3 64 | #define BF_PUSHASSIST 6 65 | 66 | #define BF_DISPLAYTIMEOUT 10 67 | 68 | typedef struct 69 | { 70 | // Parameters received from display in operation mode: 71 | uint8_t AssistLevel; // 0..9 Power Assist Level 72 | uint8_t Headlight; // BF_HEADLIGHT_OFF / BF_HEADLIGHT_ON 73 | uint8_t PushAssist; // BF_PUSHASSIST_OFF / BF_PUSHASSIST_ON 74 | uint16_t Wheeldiameter; // Wheel Diameter 75 | }RX_PARAM_t; 76 | 77 | 78 | typedef struct 79 | { 80 | #if HARDWARE_REV < 20 81 | SoftwareSerial* SerialPort; 82 | #else 83 | HardwareSerial* SerialPort; 84 | #endif 85 | 86 | uint8_t RxState; 87 | uint32_t LastRx; 88 | 89 | uint8_t RxBuff[BF_MAX_RXBUFF]; 90 | uint8_t RxCnt; 91 | uint8_t InfoLength; 92 | 93 | RX_PARAM_t Rx; 94 | 95 | }BAFANG_t; 96 | 97 | 98 | 99 | 100 | // Public function prototypes 101 | #if HARDWARE_REV < 20 102 | void Bafang_Init (BAFANG_t* BF_ctx, SoftwareSerial* DisplaySerial); 103 | #else 104 | void Bafang_Init (BAFANG_t* BF_ctx, HardwareSerial* DisplaySerial); 105 | #endif 106 | 107 | void Bafang_Service(BAFANG_t* BF_ctx); 108 | 109 | void BF_sendmessage(BAFANG_t* BF_ctx,uint8_t count); 110 | 111 | 112 | #endif // BAFANG 113 | #endif // (DISPLAY_TYPE & DISPLAY_TYPE_BAFANG) 114 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/display_kingmeter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Library for King-Meter displays 3 | 4 | Copyright © 2015 Michael Fabry (Michael@Fabry.de) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | 22 | #ifndef KINGMETER_H 23 | #define KINGMETER_H 24 | 25 | 26 | // Includes 27 | #include "config.h" 28 | 29 | #if (DISPLAY_TYPE & DISPLAY_TYPE_KINGMETER) 30 | 31 | #if HARDWARE_REV < 20 32 | #include 33 | #endif 34 | 35 | 36 | // Definitions 37 | #define KM_MAX_WHEELTIME 0x0DAC // Maximum Wheeltime reported to the display (e.g. when wheel is stopped) 38 | 39 | #if (DISPLAY_TYPE == DISPLAY_TYPE_KINGMETER_618U) 40 | #define KM_MAX_RXBUFF 6 41 | #define KM_MAX_TXBUFF 8 42 | #endif 43 | 44 | #if (DISPLAY_TYPE == DISPLAY_TYPE_KINGMETER_901U) 45 | #define KM_MAX_RXBUFF 20 46 | #define KM_MAX_TXBUFF 11 47 | #endif 48 | 49 | 50 | #define KM_PASDIR_FORWARD 0x00 51 | #define KM_PASDIR_BACKWARD 0x01 52 | 53 | #define KM_HND_HL_NO 0x00 54 | #define KM_HND_HL_YES 0x01 55 | 56 | #define KM_HND_HF_NO 0x00 57 | #define KM_HND_HF_YES 0x01 58 | 59 | 60 | #define KM_WHEELSIZE_8 638 61 | #define KM_WHEELSIZE_10 798 62 | #define KM_WHEELSIZE_12 958 63 | #define KM_WHEELSIZE_14 1117 64 | 65 | #define KM_WHEELSIZE_16 1277 66 | #define KM_WHEELSIZE_18 1436 67 | #define KM_WHEELSIZE_20 1596 68 | #define KM_WHEELSIZE_22 1756 69 | #define KM_WHEELSIZE_24 1915 70 | #define KM_WHEELSIZE_26 2075 71 | #define KM_WHEELSIZE_700 2154 72 | #define KM_WHEELSIZE_28 2234 73 | 74 | #define KM_WHEELSIZE_29 2294 75 | 76 | 77 | #if (DISPLAY_TYPE == DISPLAY_TYPE_KINGMETER_618U) 78 | const uint16_t KM_WHEELSIZE[8] = { KM_WHEELSIZE_16, KM_WHEELSIZE_18, KM_WHEELSIZE_20, KM_WHEELSIZE_22, 79 | KM_WHEELSIZE_24, KM_WHEELSIZE_26, KM_WHEELSIZE_700, KM_WHEELSIZE_28 }; 80 | #endif 81 | 82 | 83 | typedef struct 84 | { 85 | // Parameters received from display in setting mode: 86 | uint16_t WheelSize_mm; // Unit: 1mm 87 | uint8_t PAS_RUN_Direction; // KM_PASDIR_FORWARD / KM_PASDIR_BACKWARD 88 | uint8_t PAS_SCN_Tolerance; // Number of PAS signals to start the motor 89 | uint8_t PAS_N_Ratio; // 0..255 PAS ratio 90 | uint8_t HND_HL_ThrParam; // KM_HND_HL_NO / KM_HND_HL_YES 91 | uint8_t HND_HF_ThrParam; // KM_HND_HF_NO / KM_HND_HF_YES 92 | uint8_t SYS_SSP_SlowStart; // 1..4 Level of soft ramping at start 93 | uint8_t SPS_SpdMagnets; // Number of magnets of speedsensor 94 | uint16_t VOL_1_UnderVolt_x10; // Unit: 0.1V 95 | 96 | }RX_SETTINGS_t; 97 | 98 | 99 | 100 | #define KM_HEADLIGHT_OFF 0x00 101 | #define KM_HEADLIGHT_ON 0x01 102 | #define KM_HEADLIGHT_LOW 0x02 103 | #define KM_HEADLIGHT_HIGH 0x03 104 | 105 | #define KM_BATTERY_NORMAL 0x00 106 | #define KM_BATTERY_LOW 0x01 107 | 108 | #define KM_PUSHASSIST_OFF 0x00 109 | #define KM_PUSHASSIST_ON 0x01 110 | 111 | #define KM_POWERASSIST_OFF 0x00 112 | #define KM_POWERASSIST_ON 0x01 113 | 114 | #define KM_THROTTLE_OFF 0x00 115 | #define KM_THROTTLE_ON 0x01 116 | 117 | #define KM_CRUISE_OFF 0x00 118 | #define KM_CRUISE_ON 0x01 119 | 120 | #define KM_OVERSPEED_NO 0x00 // Speed below limit 121 | #define KM_OVERSPEED_YES 0x01 // Overspeed detected 122 | 123 | 124 | typedef struct 125 | { 126 | // Parameters received from display in operation mode: 127 | uint8_t AssistLevel; // 0..255 Power Assist Level 128 | uint8_t Headlight; // KM_HEADLIGHT_OFF / KM_HEADLIGHT_ON / KM_HEADLIGHT_LOW / KM_HEADLIGHT_HIGH 129 | uint8_t Battery; // KM_BATTERY_NORMAL / KM_BATTERY_LOW 130 | uint8_t PushAssist; // KM_PUSHASSIST_OFF / KM_PUSHASSIST_ON 131 | uint8_t PowerAssist; // KM_POWERASSIST_OFF / KM_POWERASSIST_ON 132 | uint8_t Throttle; // KM_THROTTLE_OFF / KM_THROTTLE_ON 133 | uint8_t CruiseControl; // KM_CRUISE_OFF / KM_CRUISE_ON 134 | uint8_t OverSpeed; // KM_OVERSPEED_OFF / KM_OVERSPEED_ON 135 | uint16_t SPEEDMAX_Limit_x10; // Unit: 0.1km/h 136 | uint16_t CUR_Limit_x10; // Unit: 0.1A 137 | 138 | }RX_PARAM_t; 139 | 140 | 141 | 142 | #define KM_ERROR_NONE 0x00 143 | #define KM_ERROR_COMM 0x30 144 | 145 | typedef struct 146 | { 147 | // Parameters to be send to display in operation mode: 148 | uint8_t Battery; // KM_BATTERY_NORMAL / KM_BATTERY_LOW 149 | uint16_t Wheeltime_ms; // Unit:1ms 150 | uint8_t Error; // KM_ERROR_NONE, .. 151 | uint16_t Current_x10; // Unit: 0.1A 152 | 153 | }TX_PARAM_t; 154 | 155 | 156 | 157 | typedef struct 158 | { 159 | #if HARDWARE_REV < 20 160 | SoftwareSerial* SerialPort; 161 | #else 162 | HardwareSerial* SerialPort; 163 | #endif 164 | 165 | uint8_t RxState; 166 | uint32_t LastRx; 167 | 168 | uint8_t RxBuff[KM_MAX_RXBUFF]; 169 | uint8_t RxCnt; 170 | 171 | RX_SETTINGS_t Settings; 172 | RX_PARAM_t Rx; 173 | TX_PARAM_t Tx; 174 | 175 | }KINGMETER_t; 176 | 177 | 178 | 179 | 180 | // Public function prototypes 181 | #if HARDWARE_REV < 20 182 | void KingMeter_Init (KINGMETER_t* KM_ctx, SoftwareSerial* DisplaySerial); 183 | #else 184 | void KingMeter_Init (KINGMETER_t* KM_ctx, HardwareSerial* DisplaySerial); 185 | #endif 186 | 187 | void KingMeter_Service(KINGMETER_t* KM_ctx); 188 | 189 | 190 | #endif // KINGMETER_H 191 | #endif // (DISPLAY_TYPE & DISPLAY_TYPE_KINGMETER) 192 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/ds1307.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Code by JeeLabs http://news.jeelabs.org/code/ 3 | Released to the public domain! Enjoy! 4 | modified by Jens Kießling / jenkie 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software Foundation, 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include "ds1307.h" 23 | #include 24 | #define WIRE Wire 25 | #define DS1307_ADDRESS 0x68 26 | 27 | #if (ARDUINO >= 100) 28 | #include // capital A so it is error prone on case-sensitive filesystems 29 | #else 30 | #include 31 | #endif 32 | 33 | static uint8_t bcd2bin (uint8_t val) { return val - 6 * (val >> 4); } 34 | static uint8_t bin2bcd (uint8_t val) { return val + 6 * (val / 10); } 35 | 36 | void RTC_DS1307::adjust_time(uint8_t hh, uint8_t mm, uint8_t ss) 37 | { 38 | WIRE.beginTransmission(DS1307_ADDRESS); 39 | WIRE.write((uint8_t)0); 40 | WIRE.write(bin2bcd(ss)); 41 | WIRE.write(bin2bcd(mm)); 42 | WIRE.write(bin2bcd(hh)); 43 | WIRE.endTransmission(); 44 | } 45 | 46 | Time RTC_DS1307::get_time() 47 | { 48 | WIRE.beginTransmission(DS1307_ADDRESS); 49 | WIRE.write((uint8_t)0); 50 | WIRE.endTransmission(); 51 | WIRE.requestFrom(DS1307_ADDRESS, 7); 52 | uint8_t ss = bcd2bin(WIRE.read() & 0x7F); 53 | uint8_t mm = bcd2bin(WIRE.read()); 54 | uint8_t hh = bcd2bin(WIRE.read()); 55 | return (Time) {hh,mm,ss}; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/ds1307.h: -------------------------------------------------------------------------------- 1 | /* 2 | Code by JeeLabs http://news.jeelabs.org/code/ 3 | Released to the public domain! Enjoy! 4 | modified by Jens Kießling / jenkie 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software Foundation, 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef _ds1307_H_ 22 | #define _ds1307_H_ 23 | 24 | struct Time 25 | { 26 | uint8_t hh; //hours 27 | uint8_t mm; //minutes 28 | uint8_t ss; //seconds 29 | }; 30 | 31 | class RTC_DS1307 32 | { 33 | public: 34 | static void adjust_time(uint8_t hh, uint8_t mm, uint8_t ss); 35 | Time get_time(void); 36 | }; 37 | 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/globals.h: -------------------------------------------------------------------------------- 1 | /* 2 | Global variables from the main program code end up here. 3 | (c) 2013 Thomas Jarosch / pedelecforum.de 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef GLOBALS_H 21 | #define GLOBALS_H 22 | 23 | #include "ds1307.h" 24 | 25 | // Global defines from the main program code 26 | extern float mah; 27 | extern boolean display_force_text; 28 | extern float voltage_display; 29 | extern float current_display; 30 | extern byte battery_percent_fromvoltage; 31 | extern byte battery_percent_fromcapacity; 32 | extern double power; 33 | extern double power_set; 34 | extern float wh; 35 | extern double wh_human; 36 | extern unsigned int charge_count; 37 | extern volatile float spd; 38 | extern volatile int cad; 39 | extern volatile float km; 40 | extern float range; 41 | extern unsigned long odo; 42 | extern float temperature; 43 | extern float altitude; 44 | extern float altitude_start; 45 | extern float slope; 46 | extern int poti_stat; 47 | extern int throttle_stat; 48 | extern boolean brake_stat; 49 | extern volatile unsigned long wheel_time; 50 | extern byte pulse_human; 51 | extern double power_human; 52 | extern boolean variables_saved; 53 | 54 | extern const int bluetooth_pin; 55 | extern const int fet_out; 56 | extern const int lights_pin; 57 | 58 | extern int curr_startingaid_speed; 59 | extern int curr_spd_max1; 60 | extern int curr_spd_max2; 61 | extern int curr_power_max; 62 | extern int curr_power_poti_max; 63 | extern double curr_capacity; 64 | extern boolean current_profile; 65 | extern boolean lights_enabled; 66 | 67 | extern boolean first_aid_ignore_break; 68 | extern boolean first_aid_ignore_pas; 69 | extern boolean first_aid_ignore_speed; 70 | extern boolean first_aid_ignore_poti; 71 | extern boolean first_aid_ignore_throttle; 72 | 73 | extern void save_eeprom(); 74 | extern void save_shutdown(); 75 | extern void activate_new_profile(); 76 | 77 | #ifdef TEENSY_VERSION 78 | extern float motor_current; 79 | extern float motor_rpm; 80 | extern float temperature_vesc; 81 | extern volatile boolean pedaling; 82 | extern int throttle_write; 83 | #endif 84 | 85 | extern RTC_DS1307 rtc; 86 | extern Time now; 87 | 88 | #ifdef SUPPORT_TEMP_SENSOR 89 | #include "DallasTemp.h" 90 | extern DallasTemperature sensors; 91 | #endif 92 | 93 | // Define own version of F() macro since compile will 94 | // fail on newer gcc versions with a "const" warning. 95 | // This is the version as in Arduino 1.5 and newer. 96 | #define MY_F(string_literal) (reinterpret_cast(PSTR(string_literal))) 97 | 98 | #define FROM_FLASH(str) (reinterpret_cast(str)) 99 | 100 | 101 | #if HARDWARE_REV <= 5 && !defined(TEENSY_VERSION) 102 | #define FET_ON LOW 103 | #define FET_OFF HIGH 104 | #else 105 | #define FET_ON HIGH 106 | #define FET_OFF LOW 107 | #endif 108 | 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/hrmi_funcs.cpp: -------------------------------------------------------------------------------- 1 | // HRMI-Breakout: http://www.sparkfun.com/products/8661 2 | // Code mainly taken from: http://bildr.org/2011/08/heartrate-arduino/ 3 | 4 | #include 5 | #include "hrmi_funcs.h" 6 | 7 | #define HRMI_I2C_ADDR 127 8 | 9 | // Forward declarations 10 | static void writeRegister(int deviceAddress, byte address, byte val); 11 | static boolean hrmiGetData(byte addr, byte numBytes, byte* dataArray); 12 | 13 | void hrmi_open() 14 | { 15 | Wire.begin(); 16 | writeRegister(HRMI_I2C_ADDR, 0x53, 1); // Configure the HRMI with the requested algorithm mode 17 | } 18 | 19 | int getHeartRate() 20 | { 21 | //get and return heart rate 22 | //returns 0 if we could not determine the heart rate 23 | byte i2cRspArray[3]; // I2C response array 24 | i2cRspArray[2] = 0; 25 | 26 | writeRegister(HRMI_I2C_ADDR, 0x47, 0x1); // Request a set of heart rate values 27 | 28 | if (hrmiGetData(127, 3, i2cRspArray)) 29 | { 30 | return i2cRspArray[2]; 31 | } 32 | else 33 | { 34 | return 0; 35 | } 36 | } 37 | 38 | static void writeRegister(int deviceAddress, byte address, byte val) 39 | { 40 | //I2C command to send data to a specific address on the device 41 | Wire.beginTransmission(deviceAddress); // start transmission to device 42 | Wire.write(address); // send register address 43 | Wire.write(val); // send value to write 44 | Wire.endTransmission(); // end transmission 45 | } 46 | 47 | static boolean hrmiGetData(byte addr, byte numBytes, byte* dataArray) 48 | { 49 | //Get data from heart rate monitor and fill dataArray byte with responce 50 | //Returns true if it was able to get it, false if not 51 | Wire.requestFrom(addr, numBytes); 52 | if (Wire.available()) 53 | { 54 | 55 | for (int i=0; i 9 | #else 10 | #include 11 | #endif 12 | 13 | void hrmi_open(); 14 | int getHeartRate(); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | On the go menu system 3 | (c) 2013 Thomas Jarosch / pedelecforum.de 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef MENU_H 21 | #define MENU_H 22 | 23 | #include "Arduino.h" 24 | #include "MenuSystem.h" 25 | 26 | void init_menu(); 27 | 28 | extern unsigned long menu_activity_expire; // Timestamp when we kick the user ouf of the menu 29 | extern boolean menu_active; //Flag to indicate menu is shown or not 30 | extern boolean menu_changed; //Flag to indicate menu display needs update 31 | 32 | extern MenuSystem menu_system; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/serial_command.h: -------------------------------------------------------------------------------- 1 | /* 2 | Serial (bluetooth) communication functions 3 | Written by Jens Kießling / jenkie 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #ifndef SERIAL_COMMAND_H 20 | #define SERIAL_COMMAND_H 21 | 22 | #include "Arduino.h" 23 | 24 | void parse_serial(const char &read_c, const byte port); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/serial_lcd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Serial LCD function. Currently for New Haven display only. 3 | Written by Thomas Jarosch in 2014 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #if ARDUINO < 100 21 | #include 22 | #else 23 | #include 24 | #endif 25 | 26 | #include "serial_lcd.h" 27 | 28 | #if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_SERIAL) 29 | 30 | /** 31 | * @brief Constructor. No data is written to the display yet 32 | * 33 | * @param display_pin The pin the display is connected to 34 | */ 35 | SerialLCD::SerialLCD(const byte &display_pin, const byte &unused_pin) 36 | : SoftwareSerial(unused_pin, display_pin) 37 | , DisplayPin(display_pin) 38 | { 39 | } 40 | 41 | /** 42 | * @brief Initialize display. Clear screen, enable backlight etc. 43 | * 44 | */ 45 | void SerialLCD::init() 46 | { 47 | pinMode(DisplayPin, OUTPUT); 48 | begin(9600); 49 | 50 | // Controller on the display needs 100ms init time 51 | delay(100); 52 | 53 | // Clear screen 54 | clear(); 55 | 56 | // Set contrast 57 | setContrast(50); 58 | 59 | // Enable display 60 | display(true); 61 | } 62 | 63 | /** 64 | * @brief Clear screen and move cursor home 65 | * 66 | */ 67 | void SerialLCD::clear() 68 | { 69 | write(0xFE); 70 | write(0x51); 71 | 72 | // As clear() also clears the receive buffer 73 | // and takes 1.5ms to execute, we wait for 2 millis 74 | delay(2); 75 | } 76 | 77 | /** 78 | * @brief Move cursor home to (0,0) 79 | * 80 | */ 81 | void SerialLCD::home() 82 | { 83 | write(0xFE); 84 | write(0x46); 85 | } 86 | 87 | /** 88 | * @brief Set display contrast 89 | * 90 | * @param contrast Value between 1 and 50 91 | */ 92 | void SerialLCD::setContrast(const byte &contrast) 93 | { 94 | write(0xFE); 95 | write(0x52); 96 | write(contrast); 97 | } 98 | 99 | /** 100 | * @brief Set backlight brightness 101 | * 102 | * @param brightness Backlight brightness. Value between 1 and 8. '1' is off. 103 | */ 104 | void SerialLCD::setBacklight(const byte& brightness) 105 | { 106 | write(0xFE); 107 | write(0x53); 108 | write(brightness); 109 | } 110 | 111 | /** 112 | * @brief Set cursor x/y position. Use an out-of-screen position to hide the cursor 113 | * 114 | * @param x Horizontal position, starting at 0 115 | * @param y Line, starting at 0 116 | */ 117 | void SerialLCD::setCursor(const byte& x, const byte& y) 118 | { 119 | write(0xFE); 120 | write(0x45); 121 | write(y * 0x40 + x); 122 | } 123 | 124 | void SerialLCD::noDisplay(const bool &disable_backlight) 125 | { 126 | write(0xFE); 127 | write(0x42); 128 | 129 | if (disable_backlight) 130 | setBacklight(1); 131 | } 132 | 133 | void SerialLCD::display(const bool &enable_backlight) 134 | { 135 | write(0xFE); 136 | write(0x41); 137 | 138 | if (enable_backlight) 139 | setBacklight(8); 140 | } 141 | 142 | /** 143 | * @brief Load custom character 144 | * Custom characters can be printed via ASCII code 0 to 8 145 | * 146 | * @param address Character value to store this. Valid values are 0 to 8 147 | * @param data Character bitmap data. A character is 5x8 pixels. 148 | */ 149 | void SerialLCD::createChar(byte address, const byte data[]) 150 | { 151 | address = address & 0x7; 152 | 153 | write(0xFE); 154 | write(0x54); 155 | write(address); 156 | 157 | for (byte i = 0; i < 8; ++i) 158 | write(data[i]); 159 | } 160 | 161 | #endif 162 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/serial_lcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | Serial LCD function. Currently for New Haven display only. 3 | Written by Thomas Jarosch in 2014 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #ifndef SERIAL_LCD_H 20 | #define SERIAL_LCD_H 21 | 22 | #if ARDUINO < 100 23 | #include 24 | #else 25 | #include 26 | #endif 27 | 28 | #include "config.h" 29 | 30 | #if (DISPLAY_TYPE & DISPLAY_TYPE_16X2_SERIAL) 31 | 32 | #include 33 | 34 | class SerialLCD : public SoftwareSerial 35 | { 36 | public: 37 | SerialLCD(const byte &display_pin=10, const byte &unused_pin=11); 38 | 39 | void init(); 40 | void clear(); 41 | 42 | void home(); 43 | void setCursor(const byte &x, const byte &y); 44 | 45 | void setContrast(const byte &contrast); 46 | void setBacklight(const byte &brightness); 47 | 48 | void display(const bool &enable_backlight=true); 49 | void noDisplay(const bool &disable_backlight=true); 50 | 51 | void createChar(byte address, const byte data[]); 52 | 53 | private: 54 | byte DisplayPin; 55 | }; 56 | 57 | #endif //eo DISPLAY_TYPE_16X2_SERIAL 58 | #endif 59 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/switches.h: -------------------------------------------------------------------------------- 1 | /* 2 | Switch handling functions: short and long press detection 3 | (c) 2012-2013 jenkie and Thomas Jarosch / pedelecforum.de 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #ifndef SWITCHES_H 20 | #define SWITCHES_H 21 | 22 | #include "Arduino.h" 23 | #include "config.h" 24 | 25 | enum switch_result { PRESSED_NONE=0, PRESSED_SHORT=1, PRESSED_LONG=2 }; 26 | 27 | switch_name get_switch(int value); 28 | 29 | void init_switches(); 30 | void handle_switch(const switch_name sw_name, boolean sw_state, const switch_result &force_press=PRESSED_NONE); 31 | 32 | void action_increase_poti(); 33 | void action_decrease_poti(); 34 | void action_set_soft_poti(int new_throttle_stat); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Arduino_Pedelec_Controller/switches_action.h: -------------------------------------------------------------------------------- 1 | /* 2 | Switch actions for use in config.h 3 | (c) Thomas Jarosch / pedelecforum.de 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #ifndef SWITCHES_ACTION_H 20 | #define SWITCHES_ACTION_H 21 | 22 | // Switch names 23 | enum switch_name { //SWITCH_THROTTLE=0, 24 | //SWITCH_DISPLAY1=1, 25 | //SWITCH_DISPLAY2=2, 26 | //SWITCH_POTI=3, 27 | SWITCH_THROTTLE=0, 28 | SWITCH_UP=1, 29 | SWITCH_DOWN=2, 30 | SWITCH_LEFT=3, 31 | SWITCH_RIGHT=4, 32 | SWITCH_CENTER=5, 33 | _SWITCHES_COUNT=6 34 | }; 35 | 36 | // Switch actions: Customizable actions for short and long press. See config.h 37 | enum sw_action { ACTION_NONE=0, // do nothing 38 | ACTION_SET_SOFT_POTI, // set soft poti 39 | ACTION_SHUTDOWN_SYSTEM, // power down system 40 | ACTION_ENABLE_BACKLIGHT_LONG, // enable backlight for 60s 41 | ACTION_TOGGLE_BLUETOOTH, // switch bluetooth on/off 42 | ACTION_ENTER_MENU, // enter on-the-go settings menu 43 | ACTION_PROFILE_1, // switch to profile 1 44 | ACTION_PROFILE_2, // switch to profile 2 45 | ACTION_PROFILE, // switch profiles 1 <-> 2 46 | ACTION_TOGGLE_LIGHTS, // toggle lights on/off. Needs hardware revision 1.4 or newer 47 | ACTION_INCREASE_POTI, // increase poti value. Only working when SUPPORT_POTI is disabled 48 | ACTION_DECREASE_POTI, // decrease poti value. Only working when SUPPORT_POTI is disabled 49 | ACTION_SET_FIXED_POTI_VALUE, // (re-)set soft poti to a fixed value in watts 50 | ACTION_FIXED_THROTTLE_VALUE, // set a fixed throttle value while switch is hold down (=emulate starting aid) 51 | ACTION_DISPLAY_PREV_VIEW, // go to prev view in display. Rools over if at the beginning 52 | ACTION_DISPLAY_NEXT_VIEW, // go the new view in display. Rolls over if at the end 53 | ACTION_GEAR_SHIFT_LOW, // gear shift: shift to low gear 54 | ACTION_GEAR_SHIFT_HIGH, // gear shift: shift to high gear 55 | ACTION_GEAR_SHIFT_AUTO, // gear shift: shift motor controller to "auto" mode 56 | ACTION_GEAR_SHIFT_TOGGLE_LOW_HIGH, // gear shift: toggle between low and high 57 | ACTION_GEAR_SHIFT_TOGGLE_LOW_HIGH_AUTO // gear shift: toggle between low, high and auto 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /Bluetooth_Setup/Bluetooth_Setup.ino: -------------------------------------------------------------------------------- 1 | /* 2 | This program configures the bluetooth module with custom name and pin for 3 | use with the Arduino Pedelec Controller 4 | 5 | 1st step: Connect Bluetooth module to Arduino Pedelec Controller 6 | 2nd step: Wait 1 minute after uploading the program (bluetooth module should 7 | shut down and repower during this time), then you are ready. 8 | 9 | Written by Jens Kießling (jenkie) 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software Foundation, 23 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | 27 | #define HARDWARE_REV 21 //place your hardware revision here: 1-5 means hardware-revision 1.x, 2x means 2.x 28 | int SerialSpeed=9600; //set the current speed of your bluetooth module here, usually 9600 29 | 30 | #if HARDWARE_REV<20 31 | HardwareSerial btSerial=Serial; 32 | int btPin=7; 33 | #else 34 | HardwareSerial btSerial=Serial1; 35 | int btPin=13; 36 | #endif 37 | 38 | void setup() 39 | { 40 | #if HARDWARE_REV>=20 41 | pinMode(38,OUTPUT); 42 | digitalWrite(38, 1); // turn on whole system on 43 | delay(5000); 44 | #endif 45 | btSerial.begin(SerialSpeed); 46 | delay(1000); 47 | pinMode(btPin, OUTPUT); 48 | digitalWrite(btPin,HIGH); 49 | delay(5000); 50 | btSerial.print("AT"); 51 | delay(1000); 52 | btSerial.print("AT+VERSION?"); 53 | delay(1000); 54 | btSerial.print("AT+ORGL"); 55 | delay(1000); 56 | btSerial.print("AT+RMAAD"); 57 | delay(1000); 58 | btSerial.print("AT+ROLE=0"); 59 | delay(1000); 60 | btSerial.print("AT+PSWD=1234"); // Set pin to 1234 or anything of your choice 61 | delay(5000); 62 | btSerial.print("AT+NAMEArduinoPedelec"); //use your own name if you want 63 | delay(5000); 64 | btSerial.print("AT+BAUD8"); // Set baudrate to 115200, do not change 65 | delay(5000); 66 | digitalWrite(btPin,LOW); 67 | delay(10000); 68 | digitalWrite(btPin,HIGH); 69 | #if HARDWARE_REV>=20 70 | digitalWrite(38, 0); // turn on whole system off 71 | #endif 72 | 73 | } 74 | 75 | void loop() 76 | { 77 | 78 | } 79 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #=============================================================================# 2 | # Author: Thomas Jarosch # 3 | # Date: 24.04.2012 # 4 | # # 5 | # Description: Pedelec controller cmake project # 6 | # # 7 | #=============================================================================# 8 | #set(CMAKE_TOOLCHAIN_FILE cmake/ArduinoToolchain.cmake) # Arduino Toolchain 9 | 10 | 11 | cmake_minimum_required(VERSION 2.8) 12 | 13 | set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/cmake/teensy-arm.toolchain.cmake") 14 | 15 | project(Pedelec_Controller C CXX) 16 | 17 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") 18 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib") 19 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib") 20 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 21 | 22 | include(Teensy) 23 | 24 | # "grep" for FC 2.0 hardware in config.h 25 | #file(STRINGS Arduino_Pedelec_Controller/config.h config_h_lines REGEX "^#define HARDWARE_REV 2[0-9]") 26 | #if (config_h_lines) 27 | # message("Building firmware for FC 2.0 or higher") 28 | # set(FC_PROCESSOR mega2560) 29 | #else(config_h_lines) 30 | # set(FC_PROCESSOR uno) 31 | #endif(config_h_lines) 32 | 33 | # Documentation 34 | option(DOCUMENTATION "Generate API documentation with Doxygen" OFF) 35 | 36 | find_package(Doxygen) 37 | if(DOCUMENTATION AND DOXYGEN_FOUND) 38 | 39 | # Set variables 40 | set(top_srcdir ${CMAKE_SOURCE_DIR}) 41 | 42 | # Find doxy config 43 | message(STATUS "Doxygen found.") 44 | set(DOXY_DIR "${CMAKE_SOURCE_DIR}/docs") 45 | set(DOXY_CONFIG "${DOXY_DIR}/Doxyfile.in") 46 | 47 | # Copy doxy.config.in 48 | configure_file("${DOXY_CONFIG}" "${CMAKE_BINARY_DIR}/doxy.config") 49 | 50 | # Create doc directory 51 | add_custom_command( 52 | OUTPUT ${CMAKE_BINARY_DIR}/doc 53 | COMMAND rm -rf ${CMAKE_BINARY_DIR}/doc/{html,man} 54 | COMMAND mkdir -p ${CMAKE_BINARY_DIR}/doc 55 | DEPENDS pcontroller 56 | ) 57 | 58 | # Run doxygen 59 | add_custom_command( 60 | OUTPUT ${CMAKE_BINARY_DIR}/doc/html/index.html 61 | COMMAND ${DOXYGEN_EXECUTABLE} "${CMAKE_BINARY_DIR}/doxy.config" 62 | DEPENDS "${CMAKE_BINARY_DIR}/doxy.config" "${CMAKE_BINARY_DIR}/doc" 63 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/doc 64 | ) 65 | 66 | add_custom_target(docs ALL DEPENDS ${CMAKE_BINARY_DIR}/doc/html/index.html) 67 | 68 | message(STATUS "Generating API documentation with Doxygen") 69 | else(DOCUMENTATION AND DOXYGEN_FOUND) 70 | message(STATUS "Not generating API documentation") 71 | endif(DOCUMENTATION AND DOXYGEN_FOUND) 72 | 73 | # add libraries to project 74 | #link_directories(${ARDUINO_SDK}/libraries) 75 | 76 | add_subdirectory(Arduino_Pedelec_Controller) 77 | add_subdirectory(Hardware_Test) 78 | 79 | -------------------------------------------------------------------------------- /Hardware_Test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #=============================================================================# 2 | # Author: Thomas Jarosch # 3 | # Date: 24.04.2012 # 4 | # # 5 | # Description: Pedelec controller cmake project # 6 | # # 7 | #=============================================================================# 8 | include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} 9 | ${CMAKE_SOURCE_DIR}/Hardware_Test) 10 | 11 | #configure_file(main.cpp testprogram.cpp COPYONLY) 12 | 13 | # Hardware test program 14 | set(TESTPROGRAM_NAME testprogram) 15 | #set(${TESTPROGRAM_NAME}_BOARD ${FC_PROCESSOR}) 16 | #set(${TESTPROGRAM_NAME}_PORT /dev/ttyUSB0) 17 | 18 | import_arduino_library(EEPROM) 19 | import_arduino_library(SPI) 20 | import_arduino_library(ILI9341_t3) 21 | 22 | 23 | set(${TESTPROGRAM_NAME}_SRCS 24 | main.cpp 25 | PCD8544_charset.cpp 26 | PCD8544_nano.cpp 27 | VESC/buffer.cpp 28 | VESC/crc.cpp 29 | VESC/vesc_uart.cpp 30 | #Adafruit_PCD8544/Adafruit_PCD8544.cpp 31 | ) 32 | 33 | add_teensy_executable(${TESTPROGRAM_NAME} "${${TESTPROGRAM_NAME}_SRCS}") 34 | 35 | #generate_arduino_firmware(${TESTPROGRAM_NAME}) 36 | 37 | # Dirty hack to solve compile error on Fedora 15 38 | #target_link_libraries(${TESTPROGRAM_NAME} m) 39 | #target_link_libraries(${TESTPROGRAM_NAME} c) 40 | #target_link_libraries(${TESTPROGRAM_NAME} m) 41 | -------------------------------------------------------------------------------- /Hardware_Test/EEPROMAnything.h: -------------------------------------------------------------------------------- 1 | //EEPROMAnything is taken from here: http://www.arduino.cc/playground/Code/EEPROMWriteAnything 2 | 3 | #include "EEPROM.h" 4 | #if ARDUINO < 100 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | template int EEPROM_writeAnything(int ee, const T& value) 11 | { 12 | const byte* p = (const byte*)(const void*)&value; 13 | int i; 14 | for (i = 0; i < sizeof(value); i++) 15 | EEPROM.write(ee++, *p++); 16 | return i; 17 | } 18 | 19 | template int EEPROM_readAnything(int ee, T& value) 20 | { 21 | byte* p = (byte*)(void*)&value; 22 | int i; 23 | for (i = 0; i < sizeof(value); i++) 24 | *p++ = EEPROM.read(ee++); 25 | return i; 26 | } 27 | -------------------------------------------------------------------------------- /Hardware_Test/LiquidCrystalDogm.h: -------------------------------------------------------------------------------- 1 | #ifndef LiquidCrystal_h 2 | #define LiquidCrystal_h 3 | 4 | #include 5 | #include "Print.h" 6 | 7 | // commands 8 | #define LCD_CLEARDISPLAY 0x01 9 | #define LCD_RETURNHOME 0x02 10 | #define LCD_ENTRYMODESET 0x04 11 | #define LCD_DISPLAYCONTROL 0x08 12 | #define LCD_CURSORSHIFT 0x10 13 | #define LCD_FUNCTIONSET 0x29 14 | #define LCD_SETCGRAMADDR 0x40 15 | #define LCD_SETDDRAMADDR 0x80 16 | 17 | // flags for display entry mode 18 | #define LCD_ENTRYRIGHT 0x00 19 | #define LCD_ENTRYLEFT 0x02 20 | #define LCD_ENTRYSHIFTINCREMENT 0x01 21 | #define LCD_ENTRYSHIFTDECREMENT 0x00 22 | 23 | // flags for display on/off control 24 | #define LCD_DISPLAYON 0x04 25 | #define LCD_DISPLAYOFF 0x00 26 | #define LCD_CURSORON 0x02 27 | #define LCD_CURSOROFF 0x00 28 | #define LCD_BLINKON 0x01 29 | #define LCD_BLINKOFF 0x00 30 | 31 | // flags for display/cursor shift 32 | #define LCD_DISPLAYMOVE 0x08 33 | #define LCD_CURSORMOVE 0x00 34 | #define LCD_MOVERIGHT 0x04 35 | #define LCD_MOVELEFT 0x00 36 | 37 | // flags for function set 38 | #define LCD_8BITMODE 0x10 39 | #define LCD_4BITMODE 0x00 40 | #define LCD_2LINE 0x08 41 | #define LCD_1LINE 0x00 42 | #define LCD_5x10DOTS 0x04 43 | #define LCD_5x8DOTS 0x00 44 | 45 | class LiquidCrystal : public Print 46 | { 47 | public: 48 | LiquidCrystal(uint8_t rs, uint8_t enable, 49 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 50 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 51 | LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, 52 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 53 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 54 | LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, 55 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 56 | LiquidCrystal(uint8_t rs, uint8_t enable, 57 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 58 | 59 | void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, 60 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, 61 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 62 | 63 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 64 | 65 | void clear(); 66 | void home(); 67 | 68 | void noDisplay(); 69 | void display(); 70 | void noBlink(); 71 | void blink(); 72 | void noCursor(); 73 | void cursor(); 74 | void scrollDisplayLeft(); 75 | void scrollDisplayRight(); 76 | void leftToRight(); 77 | void rightToLeft(); 78 | void autoscroll(); 79 | void noAutoscroll(); 80 | 81 | void createChar(uint8_t, const uint8_t[]); 82 | void setCursor(uint8_t, uint8_t); 83 | virtual size_t write(uint8_t); 84 | void command(uint8_t); 85 | 86 | using Print::write; 87 | private: 88 | void send(uint8_t, uint8_t); 89 | void write4bits(uint8_t); 90 | void write8bits(uint8_t); 91 | void pulseEnable(); 92 | 93 | uint8_t _rs_pin; // LOW: command. HIGH: character. 94 | uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. 95 | uint8_t _enable_pin; // activated by a HIGH pulse. 96 | uint8_t _data_pins[8]; 97 | 98 | uint8_t _displayfunction; 99 | uint8_t _displaycontrol; 100 | uint8_t _displaymode; 101 | 102 | uint8_t _initialized; 103 | 104 | uint8_t _numlines,_currline; 105 | }; 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /Hardware_Test/PCD8544_charset.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs. 3 | * 4 | * Copyright (c) 2010 Carlos Rodrigues 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | 26 | #include 27 | 28 | 29 | // The 7-bit ASCII character set... 30 | const PROGMEM unsigned char charset[][5] = 31 | { 32 | { 0x00, 0x00, 0x00, 0x00, 0x00 }, // 20 space 33 | { 0x00, 0x00, 0x5f, 0x00, 0x00 }, // 21 ! 34 | { 0x00, 0x07, 0x00, 0x07, 0x00 }, // 22 " 35 | { 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // 23 # 36 | { 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // 24 $ 37 | { 0x23, 0x13, 0x08, 0x64, 0x62 }, // 25 % 38 | { 0x36, 0x49, 0x55, 0x22, 0x50 }, // 26 & 39 | { 0x00, 0x05, 0x03, 0x00, 0x00 }, // 27 ' 40 | { 0x00, 0x1c, 0x22, 0x41, 0x00 }, // 28 ( 41 | { 0x00, 0x41, 0x22, 0x1c, 0x00 }, // 29 ) 42 | { 0x14, 0x08, 0x3e, 0x08, 0x14 }, // 2a * 43 | { 0x08, 0x08, 0x3e, 0x08, 0x08 }, // 2b + 44 | { 0x00, 0x50, 0x30, 0x00, 0x00 }, // 2c , 45 | { 0x08, 0x08, 0x08, 0x08, 0x08 }, // 2d - 46 | { 0x00, 0x60, 0x60, 0x00, 0x00 }, // 2e . 47 | { 0x20, 0x10, 0x08, 0x04, 0x02 }, // 2f / 48 | { 0x3e, 0x51, 0x49, 0x45, 0x3e }, // 30 0 49 | { 0x00, 0x42, 0x7f, 0x40, 0x00 }, // 31 1 50 | { 0x42, 0x61, 0x51, 0x49, 0x46 }, // 32 2 51 | { 0x21, 0x41, 0x45, 0x4b, 0x31 }, // 33 3 52 | { 0x18, 0x14, 0x12, 0x7f, 0x10 }, // 34 4 53 | { 0x27, 0x45, 0x45, 0x45, 0x39 }, // 35 5 54 | { 0x3c, 0x4a, 0x49, 0x49, 0x30 }, // 36 6 55 | { 0x01, 0x71, 0x09, 0x05, 0x03 }, // 37 7 56 | { 0x36, 0x49, 0x49, 0x49, 0x36 }, // 38 8 57 | { 0x06, 0x49, 0x49, 0x29, 0x1e }, // 39 9 58 | { 0x00, 0x36, 0x36, 0x00, 0x00 }, // 3a : 59 | { 0x00, 0x56, 0x36, 0x00, 0x00 }, // 3b ; 60 | { 0x08, 0x14, 0x22, 0x41, 0x00 }, // 3c < 61 | { 0x14, 0x14, 0x14, 0x14, 0x14 }, // 3d = 62 | { 0x00, 0x41, 0x22, 0x14, 0x08 }, // 3e > 63 | { 0x02, 0x01, 0x51, 0x09, 0x06 }, // 3f ? 64 | { 0x32, 0x49, 0x79, 0x41, 0x3e }, // 40 @ 65 | { 0x7e, 0x11, 0x11, 0x11, 0x7e }, // 41 A 66 | { 0x7f, 0x49, 0x49, 0x49, 0x36 }, // 42 B 67 | { 0x3e, 0x41, 0x41, 0x41, 0x22 }, // 43 C 68 | { 0x7f, 0x41, 0x41, 0x22, 0x1c }, // 44 D 69 | { 0x7f, 0x49, 0x49, 0x49, 0x41 }, // 45 E 70 | { 0x7f, 0x09, 0x09, 0x09, 0x01 }, // 46 F 71 | { 0x3e, 0x41, 0x49, 0x49, 0x7a }, // 47 G 72 | { 0x7f, 0x08, 0x08, 0x08, 0x7f }, // 48 H 73 | { 0x00, 0x41, 0x7f, 0x41, 0x00 }, // 49 I 74 | { 0x20, 0x40, 0x41, 0x3f, 0x01 }, // 4a J 75 | { 0x7f, 0x08, 0x14, 0x22, 0x41 }, // 4b K 76 | { 0x7f, 0x40, 0x40, 0x40, 0x40 }, // 4c L 77 | { 0x7f, 0x02, 0x0c, 0x02, 0x7f }, // 4d M 78 | { 0x7f, 0x04, 0x08, 0x10, 0x7f }, // 4e N 79 | { 0x3e, 0x41, 0x41, 0x41, 0x3e }, // 4f O 80 | { 0x7f, 0x09, 0x09, 0x09, 0x06 }, // 50 P 81 | { 0x3e, 0x41, 0x51, 0x21, 0x5e }, // 51 Q 82 | { 0x7f, 0x09, 0x19, 0x29, 0x46 }, // 52 R 83 | { 0x46, 0x49, 0x49, 0x49, 0x31 }, // 53 S 84 | { 0x01, 0x01, 0x7f, 0x01, 0x01 }, // 54 T 85 | { 0x3f, 0x40, 0x40, 0x40, 0x3f }, // 55 U 86 | { 0x1f, 0x20, 0x40, 0x20, 0x1f }, // 56 V 87 | { 0x3f, 0x40, 0x38, 0x40, 0x3f }, // 57 W 88 | { 0x63, 0x14, 0x08, 0x14, 0x63 }, // 58 X 89 | { 0x07, 0x08, 0x70, 0x08, 0x07 }, // 59 Y 90 | { 0x61, 0x51, 0x49, 0x45, 0x43 }, // 5a Z 91 | { 0x00, 0x7f, 0x41, 0x41, 0x00 }, // 5b [ 92 | { 0x02, 0x04, 0x08, 0x10, 0x20 }, // 5c backslash 93 | { 0x00, 0x41, 0x41, 0x7f, 0x00 }, // 5d ] 94 | { 0x04, 0x02, 0x01, 0x02, 0x04 }, // 5e ^ 95 | { 0x40, 0x40, 0x40, 0x40, 0x40 }, // 5f _ 96 | { 0x00, 0x01, 0x02, 0x04, 0x00 }, // 60 ` 97 | { 0x20, 0x54, 0x54, 0x54, 0x78 }, // 61 a 98 | { 0x7f, 0x48, 0x44, 0x44, 0x38 }, // 62 b 99 | { 0x38, 0x44, 0x44, 0x44, 0x20 }, // 63 c 100 | { 0x38, 0x44, 0x44, 0x48, 0x7f }, // 64 d 101 | { 0x38, 0x54, 0x54, 0x54, 0x18 }, // 65 e 102 | { 0x08, 0x7e, 0x09, 0x01, 0x02 }, // 66 f 103 | { 0x0c, 0x52, 0x52, 0x52, 0x3e }, // 67 g 104 | { 0x7f, 0x08, 0x04, 0x04, 0x78 }, // 68 h 105 | { 0x00, 0x44, 0x7d, 0x40, 0x00 }, // 69 i 106 | { 0x20, 0x40, 0x44, 0x3d, 0x00 }, // 6a j 107 | { 0x7f, 0x10, 0x28, 0x44, 0x00 }, // 6b k 108 | { 0x00, 0x41, 0x7f, 0x40, 0x00 }, // 6c l 109 | { 0x7c, 0x04, 0x18, 0x04, 0x78 }, // 6d m 110 | { 0x7c, 0x08, 0x04, 0x04, 0x78 }, // 6e n 111 | { 0x38, 0x44, 0x44, 0x44, 0x38 }, // 6f o 112 | { 0x7c, 0x14, 0x14, 0x14, 0x08 }, // 70 p 113 | { 0x08, 0x14, 0x14, 0x18, 0x7c }, // 71 q 114 | { 0x7c, 0x08, 0x04, 0x04, 0x08 }, // 72 r 115 | { 0x48, 0x54, 0x54, 0x54, 0x20 }, // 73 s 116 | { 0x04, 0x3f, 0x44, 0x40, 0x20 }, // 74 t 117 | { 0x3c, 0x40, 0x40, 0x20, 0x7c }, // 75 u 118 | { 0x1c, 0x20, 0x40, 0x20, 0x1c }, // 76 v 119 | { 0x3c, 0x40, 0x30, 0x40, 0x3c }, // 77 w 120 | { 0x44, 0x28, 0x10, 0x28, 0x44 }, // 78 x 121 | { 0x0c, 0x50, 0x50, 0x50, 0x3c }, // 79 y 122 | { 0x44, 0x64, 0x54, 0x4c, 0x44 }, // 7a z 123 | { 0x00, 0x08, 0x36, 0x41, 0x00 }, // 7b { 124 | { 0x00, 0x00, 0x7f, 0x00, 0x00 }, // 7c | 125 | { 0x00, 0x41, 0x36, 0x08, 0x00 }, // 7d } 126 | { 0x10, 0x08, 0x08, 0x10, 0x08 }, // 7e ~ 127 | { 0x00, 0x00, 0x00, 0x00, 0x00 } // 7f 128 | }; 129 | 130 | 131 | /* vim: set expandtab ts=4 sw=4: */ 132 | -------------------------------------------------------------------------------- /Hardware_Test/PCD8544_nano.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs. 3 | * 4 | * Copyright (c) 2010 Carlos Rodrigues 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | 26 | #ifndef PCD8544_H 27 | #define PCD8544_H 28 | 29 | 30 | #if ARDUINO < 100 31 | #include 32 | #else 33 | #include 34 | #endif 35 | 36 | 37 | // Chip variants supported... 38 | #define CHIP_PCD8544 0 39 | #define CHIP_ST7576 1 40 | 41 | 42 | class PCD8544: public Print 43 | { 44 | public: 45 | // All the pins can be changed from the default values... 46 | PCD8544(unsigned char sclk = 13, /* clock (display pin 2) */ 47 | unsigned char sdin = 11, /* data-in (display pin 3) */ 48 | unsigned char dc = 9, /* data select (display pin 4) */ 49 | unsigned char reset = 10, /* reset (display pin 8) */ 50 | unsigned char sce = 8); /* enable (display pin 5) */ 51 | 52 | // Display initialization (dimensions in pixels)... 53 | void begin(unsigned char width=84, unsigned char height=48, unsigned char model=CHIP_PCD8544); 54 | void stop(); 55 | 56 | // Erase everything on the display... 57 | void clear(); 58 | void clearLine(); // ...or just the current line 59 | 60 | // Control the display's power state... 61 | void setPower(bool on); 62 | 63 | // For compatibility with the LiquidCrystal library... 64 | void display(); 65 | void noDisplay(); 66 | 67 | // Activate white-on-black mode (whole display)... 68 | void setInverse(bool inverse); 69 | 70 | // Place the cursor at the start of the current line... 71 | void home(); 72 | 73 | // Place the cursor at position (column, line)... 74 | void setCursor(unsigned char column, unsigned char line); 75 | 76 | // Assign a user-defined glyph (5x8) to an ASCII character (0-31)... 77 | void createChar(unsigned char chr, const unsigned char *glyph); 78 | 79 | // Write an ASCII character at the current cursor position (7-bit)... 80 | #if ARDUINO < 100 81 | virtual void write(uint8_t chr); 82 | #else 83 | virtual size_t write(uint8_t chr); 84 | #endif 85 | 86 | // Draw a bitmap at the current cursor position... 87 | void drawBitmap(const unsigned char *data, unsigned char columns, unsigned char lines); 88 | 89 | // Draw a chart element at the current cursor position... 90 | void drawColumn(unsigned char lines, unsigned char value); 91 | 92 | private: 93 | unsigned char pin_sclk; 94 | unsigned char pin_sdin; 95 | unsigned char pin_dc; 96 | unsigned char pin_reset; 97 | unsigned char pin_sce; 98 | 99 | // The size of the display, in pixels... 100 | unsigned char width; 101 | unsigned char height; 102 | 103 | // Current cursor position... 104 | unsigned char column; 105 | unsigned char line; 106 | 107 | // User-defined glyphs (below the ASCII space character)... 108 | const unsigned char *custom[' ']; 109 | 110 | // Send a command or data to the display... 111 | void send(unsigned char type, unsigned char data); 112 | }; 113 | 114 | 115 | #endif /* PCD8544_H */ 116 | 117 | 118 | /* vim: set expandtab ts=4 sw=4: */ 119 | -------------------------------------------------------------------------------- /Hardware_Test/VESC/buffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * buffer.c 20 | * 21 | * Created on: 13 maj 2013 22 | * Author: benjamin 23 | */ 24 | 25 | #include "buffer.h" 26 | 27 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index) { 28 | buffer[(*index)++] = number >> 8; 29 | buffer[(*index)++] = number; 30 | } 31 | 32 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index) { 33 | buffer[(*index)++] = number >> 8; 34 | buffer[(*index)++] = number; 35 | } 36 | 37 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index) { 38 | buffer[(*index)++] = number >> 24; 39 | buffer[(*index)++] = number >> 16; 40 | buffer[(*index)++] = number >> 8; 41 | buffer[(*index)++] = number; 42 | } 43 | 44 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index) { 45 | buffer[(*index)++] = number >> 24; 46 | buffer[(*index)++] = number >> 16; 47 | buffer[(*index)++] = number >> 8; 48 | buffer[(*index)++] = number; 49 | } 50 | 51 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index) { 52 | buffer_append_int16(buffer, (int16_t)(number * scale), index); 53 | } 54 | 55 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index) { 56 | buffer_append_int32(buffer, (int32_t)(number * scale), index); 57 | } 58 | 59 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index) { 60 | int16_t res = ((uint16_t) buffer[*index]) << 8 | 61 | ((uint16_t) buffer[*index + 1]); 62 | *index += 2; 63 | return res; 64 | } 65 | 66 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) { 67 | uint16_t res = ((uint16_t) buffer[*index]) << 8 | 68 | ((uint16_t) buffer[*index + 1]); 69 | *index += 2; 70 | return res; 71 | } 72 | 73 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) { 74 | int32_t res = ((uint32_t) buffer[*index]) << 24 | 75 | ((uint32_t) buffer[*index + 1]) << 16 | 76 | ((uint32_t) buffer[*index + 2]) << 8 | 77 | ((uint32_t) buffer[*index + 3]); 78 | *index += 4; 79 | return res; 80 | } 81 | 82 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) { 83 | uint32_t res = ((uint32_t) buffer[*index]) << 24 | 84 | ((uint32_t) buffer[*index + 1]) << 16 | 85 | ((uint32_t) buffer[*index + 2]) << 8 | 86 | ((uint32_t) buffer[*index + 3]); 87 | *index += 4; 88 | return res; 89 | } 90 | 91 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index) { 92 | return (float)buffer_get_int16(buffer, index) / scale; 93 | } 94 | 95 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index) { 96 | return (float)buffer_get_int32(buffer, index) / scale; 97 | } 98 | 99 | bool buffer_get_bool(const uint8_t *buffer, int32_t *index) { 100 | 101 | if (buffer[*index] == 1) 102 | { 103 | index++; 104 | return true; 105 | } 106 | else 107 | { 108 | index++; 109 | return false; 110 | } 111 | 112 | } 113 | 114 | void buffer_append_bool(uint8_t *buffer,bool value, int32_t *index) { 115 | 116 | if (value == true) 117 | { 118 | buffer[*index] = 1; 119 | (*index)++; 120 | } 121 | else 122 | { 123 | buffer[*index] = 0; 124 | (*index)++; 125 | } 126 | 127 | } -------------------------------------------------------------------------------- /Hardware_Test/VESC/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * buffer.h 20 | * 21 | * Created on: 13 maj 2013 22 | * Author: benjamin 23 | */ 24 | 25 | #ifndef BUFFER_H_ 26 | #define BUFFER_H_ 27 | 28 | #include 29 | 30 | void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index); 31 | void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index); 32 | void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index); 33 | void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index); 34 | void buffer_append_float16(uint8_t* buffer, float number, float scale, int32_t *index); 35 | void buffer_append_float32(uint8_t* buffer, float number, float scale, int32_t *index); 36 | int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index); 37 | uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index); 38 | int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index); 39 | uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index); 40 | float buffer_get_float16(const uint8_t *buffer, float scale, int32_t *index); 41 | float buffer_get_float32(const uint8_t *buffer, float scale, int32_t *index); 42 | bool buffer_get_bool(const uint8_t *buffer, int32_t *index); 43 | void buffer_append_bool(uint8_t *buffer,bool value, int32_t *index); 44 | #endif /* BUFFER_H_ */ 45 | -------------------------------------------------------------------------------- /Hardware_Test/VESC/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 - 2017 Andreas Chaitidis Andreas.Chaitidis@gmail.com 3 | This program is free software : you can redistribute it and / or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 10 | GNU General Public License for more details. 11 | You should have received a copy of the GNU General Public License 12 | along with this program.If not, see . 13 | */ 14 | 15 | //The Config.h is a file, that I use in other programs usualy. So I define also the serial ports there. If you don't want to 16 | //use it, just comment the include statement in the VescUart.h out. 17 | 18 | #ifndef _CONFIG_h 19 | #define _CONFIG_h 20 | 21 | #define SERIALIO Serial1 22 | #define DEBUGSERIAL Serial 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Hardware_Test/VESC/crc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * crc.c 20 | * 21 | * Created on: 26 feb 2012 22 | * Author: benjamin 23 | */ 24 | #include "crc.h" 25 | 26 | // CRC Table 27 | const unsigned short crc16_tab[] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 28 | 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 29 | 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 30 | 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 31 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 32 | 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 33 | 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 34 | 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 35 | 0x0840, 0x1861, 0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 36 | 0x9969, 0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 37 | 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 38 | 0xab1a, 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 39 | 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 40 | 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 41 | 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 42 | 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 43 | 0x5004, 0x4025, 0x7046, 0x6067, 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 44 | 0xd31c, 0xe37f, 0xf35e, 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 45 | 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 46 | 0xc50d, 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 47 | 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 48 | 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 0xd94c, 0xc96d, 49 | 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 50 | 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 51 | 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 52 | 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 53 | 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 54 | 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 55 | 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 }; 56 | 57 | unsigned short crc16(unsigned char *buf, unsigned int len) { 58 | unsigned int i; 59 | unsigned short cksum = 0; 60 | for (i = 0; i < len; i++) { 61 | cksum = crc16_tab[(((cksum >> 8) ^ *buf++) & 0xFF)] ^ (cksum << 8); 62 | } 63 | return cksum; 64 | } 65 | -------------------------------------------------------------------------------- /Hardware_Test/VESC/crc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /* 19 | * crc.h 20 | * 21 | * Created on: 26 feb 2012 22 | * Author: benjamin 23 | */ 24 | 25 | #ifndef CRC_H_ 26 | #define CRC_H_ 27 | 28 | /* 29 | * Functions 30 | */ 31 | unsigned short crc16(unsigned char *buf, unsigned int len); 32 | 33 | #endif /* CRC_H_ */ 34 | -------------------------------------------------------------------------------- /Hardware_Test/VESC/vesc_uart.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Daniel Claes on 01/05/2016. 3 | // 4 | 5 | #ifndef PEDELEC_CONTROLLER_VESC_UART_H 6 | #define PEDELEC_CONTROLLER_VESC_UART_H 7 | 8 | /* 9 | Copyright 2015 - 2017 Andreas Chaitidis Andreas.Chaitidis@gmail.com 10 | 11 | This program is free software : you can redistribute it and / or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program.If not, see . 23 | 24 | */ 25 | 26 | /*TThis library was created on an Adruinio 2560 with different serial ports to have a better possibility 27 | to debug. The serial ports are define with #define: 28 | #define SERIALIO Serial1 for the UART port to VESC 29 | #define DEBUGSERIAL Serial for debuging over USB 30 | So you need here to define the right serial port for your arduino. 31 | If you want to use debug, uncomment DEBUGSERIAL and define a port.*/ 32 | 33 | #if defined(ARDUINO) && ARDUINO >= 100 34 | #include "Arduino.h" 35 | #else 36 | #include "WProgram.h" 37 | #endif 38 | 39 | #include "datatypes.h" 40 | #include "config.h" 41 | 42 | bool unpack_payload(uint8_t *message, int lenMes, uint8_t *payload, int lenPa); 43 | bool process_read_package(uint8_t *message, mc_values &values, int len); 44 | 45 | ///PackSendPayload Packs the payload and sends it over Serial. 46 | ///Define in a Config.h a SERIAL with the Serial in Arduino Style you want to you 47 | ///@param: payload as the payload [unit8_t Array] with length of int lenPayload 48 | ///@return the number of bytes send 49 | int send_payload(uint8_t* payload, int lenPay); 50 | 51 | ///ReceiveUartMessage receives the a message over Serial 52 | ///Define in a Config.h a SERIAL with the Serial in Arduino Style you want to you 53 | ///@parm the payload as the payload [unit8_t Array] 54 | ///@return the number of bytes receeived within the payload 55 | 56 | int process_received_msg(uint8_t* payloadReceived); 57 | 58 | ///Help Function to print struct bldcMeasure over Serial for Debug 59 | ///Define in a Config.h the DEBUGSERIAL you want to use 60 | 61 | void serial_print(const mc_values& values); 62 | 63 | ///Help Function to print uint8_t array over Serial for Debug 64 | ///Define in a Config.h the DEBUGSERIAL you want to use 65 | 66 | void serial_print(uint8_t* data, int len); 67 | 68 | ///Sends a command to VESC and stores the returned data 69 | ///@param bldcMeasure struct with received data 70 | //@return true if sucess 71 | bool vesc_get_values(mc_values &values); 72 | 73 | ///Sends a command to VESC to control the motor current 74 | ///@param current as float with the current for the motor 75 | 76 | void set_motor_current(float current); 77 | 78 | ///Sends a command to VESC to control the motor brake 79 | ///@param breakCurrent as float with the current for the brake 80 | 81 | void set_brake_current(float brakeCurrent); 82 | 83 | 84 | #endif //PEDELEC_CONTROLLER_VESC_UART_H 85 | -------------------------------------------------------------------------------- /Hardware_Test/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | int serial_putc( char c, FILE * ) 20 | { 21 | Serial.write( c ); 22 | 23 | return c; 24 | } 25 | 26 | void printf_begin(void) 27 | { 28 | fdevopen( &serial_putc, 0 ); 29 | } 30 | 31 | #endif // __PRINTF_H__ 32 | -------------------------------------------------------------------------------- /cmake/Arduino.inc.in: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | void setup(); 3 | void loop(); 4 | 5 | #include "@SOURCE_PATH@" 6 | -------------------------------------------------------------------------------- /cmake/teensy-arm.toolchain.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015, Pierre-Andre Saulais 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 2. Redistributions in binary form must reproduce the above copyright notice, 10 | # this list of conditions and the following disclaimer in the documentation 11 | # and/or other materials provided with the distribution. 12 | # 13 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 17 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | set(TRIPLE "arm-none-eabi") 25 | 26 | ## MAC 27 | if(UNIX) 28 | if (APPLE) 29 | set(ARDUINO_ROOT "/Applications/Arduino.app/Contents/Java" CACHE PATH "Path to the Arduino application") 30 | set(TY_EXECUTABLE "/Applications/TyQt.app/Contents/MacOS/tyc" CACHE FILEPATH "Path to the 'ty' executable that can upload programs to the Teensy") 31 | else() 32 | ## Linux 33 | set(ARDUINO_ROOT "/home/daniel/arduino-1.6.10" CACHE PATH "Path to the Arduino application") 34 | set(TY_EXECUTABLE "/usr/local/bin/tyc" CACHE FILEPATH "Path to the 'ty' executable that can upload programs to the Teensy") 35 | endif() 36 | endif() 37 | 38 | set(TEENSY_CORES_ROOT "${ARDUINO_ROOT}/hardware/teensy/avr/cores" CACHE PATH "Path to the Teensy 'cores' repository") 39 | set(TEENSY_ROOT "${TEENSY_CORES_ROOT}/teensy3") 40 | set(ARDUINO_LIB_ROOT "${ARDUINO_ROOT}/hardware/teensy/avr/libraries" CACHE PATH "Path to the Arduino library directory") 41 | 42 | set(TEENSY_ROOT "${TEENSY_CORES_ROOT}/teensy3") 43 | set(TOOLCHAIN_ROOT ${ARDUINO_ROOT}/hardware/tools/arm) 44 | 45 | set(ARDUINO_VERSION "106" CACHE STRING "Version of the Arduino SDK") 46 | set(TEENSYDUINO_VERSION "130" CACHE STRING "Version of the Teensyduino SDK") 47 | 48 | 49 | #set(TEENSY_MODEL "MK20DX256" CACHE STRING "Model of the Teensy MCU") 50 | set(TEENSY_MODEL "MK20DX256") # XXX Add Teensy 3.0 support. 51 | 52 | set(TEENSY_FREQUENCY "96" CACHE STRING "Frequency of the Teensy MCU (Mhz)") 53 | set_property(CACHE TEENSY_FREQUENCY PROPERTY STRINGS 96 72 48 24 16 8 4 2) 54 | 55 | set(TEENSY_USB_MODE "SERIAL" CACHE STRING "What kind of USB device the Teensy should emulate") 56 | set_property(CACHE TEENSY_USB_MODE PROPERTY STRINGS SERIAL HID SERIAL_HID MIDI RAWHID FLIGHTSIM) 57 | 58 | if(WIN32) 59 | set(TOOL_OS_SUFFIX .exe) 60 | else(WIN32) 61 | set(TOOL_OS_SUFFIX ) 62 | endif(WIN32) 63 | 64 | set(CMAKE_SYSTEM_NAME Generic) 65 | set(CMAKE_SYSTEM_PROCESSOR arm) 66 | set(CMAKE_CROSSCOMPILING 1) 67 | 68 | set(CMAKE_C_COMPILER "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" FORCE) 69 | set(CMAKE_CXX_COMPILER "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" FORCE) 70 | set(CMAKE_AR "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" FORCE) 71 | set(CMAKE_LINKER "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" FORCE) 72 | set(CMAKE_NM "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" FORCE) 73 | set(CMAKE_OBJCOPY "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" FORCE) 74 | set(CMAKE_OBJDUMP "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" FORCE) 75 | set(CMAKE_STRIP "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" FORCE) 76 | set(CMAKE_RANLIB "${TOOLCHAIN_ROOT}/bin/${TRIPLE}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" FORCE) 77 | 78 | include_directories("${TEENSY_ROOT}") 79 | 80 | set(TARGET_FLAGS "-mcpu=cortex-m4 -mthumb") 81 | set(BASE_FLAGS "-Os -Wall -nostdlib -ffunction-sections -fdata-sections ${TARGET_FLAGS}") 82 | 83 | set(CMAKE_C_FLAGS "${BASE_FLAGS} -DTIME_T=1421620748" CACHE STRING "c flags") # XXX Generate TIME_T dynamically. 84 | set(CMAKE_CXX_FLAGS "${BASE_FLAGS} -fno-exceptions -fno-rtti -felide-constructors -std=gnu++0x" CACHE STRING "c++ flags") 85 | 86 | set(LINKER_FLAGS "-Os -Wl,--gc-sections ${TARGET_FLAGS} -T${TEENSY_ROOT}/mk20dx256.ld" ) 87 | set(LINKER_LIBS "-larm_cortexM4l_math -lm" ) 88 | set(CMAKE_SHARED_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" FORCE) 89 | set(CMAKE_MODULE_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" FORCE) 90 | set(CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS}" CACHE STRING "linker flags" FORCE) 91 | 92 | # Do not pass flags like '-ffunction-sections -fdata-sections' to the linker. 93 | # This causes undefined symbol errors when linking. 94 | set(CMAKE_CXX_LINK_EXECUTABLE " -o ${LINKER_LIBS}" CACHE STRING "Linker command line" FORCE) 95 | 96 | add_definitions("-DARDUINO=${ARDUINO_VERSION}") 97 | add_definitions("-DTEENSYDUINO=${TEENSYDUINO_VERSION}") 98 | add_definitions("-D__${TEENSY_MODEL}__") 99 | add_definitions(-DLAYOUT_US_ENGLISH) 100 | add_definitions(-DUSB_VID=null) 101 | add_definitions(-DUSB_PID=null) 102 | add_definitions(-MMD) 103 | -------------------------------------------------------------------------------- /cmake_arduino/ArduinoToolchain.cmake: -------------------------------------------------------------------------------- 1 | #=============================================================================# 2 | # Author: Tomasz Bogdal (QueezyTheGreat) 3 | # Home: https://github.com/queezythegreat/arduino-cmake 4 | # 5 | # This Source Code Form is subject to the terms of the Mozilla Public 6 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | # You can obtain one at http://mozilla.org/MPL/2.0/. 8 | #=============================================================================# 9 | set(CMAKE_SYSTEM_NAME Arduino) 10 | 11 | set(CMAKE_C_COMPILER avr-gcc) 12 | set(CMAKE_CXX_COMPILER avr-g++) 13 | 14 | # Add current directory to CMake Module path automatically 15 | if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/Platform/Arduino.cmake) 16 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}) 17 | endif() 18 | 19 | #=============================================================================# 20 | # System Paths # 21 | #=============================================================================# 22 | if(UNIX) 23 | include(Platform/UnixPaths) 24 | if(APPLE) 25 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ~/Applications 26 | /Applications 27 | /Developer/Applications 28 | /sw # Fink 29 | /opt/local) # MacPorts 30 | endif() 31 | elseif(WIN32) 32 | include(Platform/WindowsPaths) 33 | endif() 34 | 35 | 36 | #=============================================================================# 37 | # Detect Arduino SDK # 38 | #=============================================================================# 39 | if(NOT ARDUINO_SDK_PATH) 40 | set(ARDUINO_PATHS) 41 | 42 | foreach(DETECT_VERSION_MAJOR 1) 43 | foreach(DETECT_VERSION_MINOR RANGE 5 0) 44 | list(APPEND ARDUINO_PATHS arduino-${DETECT_VERSION_MAJOR}.${DETECT_VERSION_MINOR}) 45 | foreach(DETECT_VERSION_PATCH RANGE 3 0) 46 | list(APPEND ARDUINO_PATHS arduino-${DETECT_VERSION_MAJOR}.${DETECT_VERSION_MINOR}.${DETECT_VERSION_PATCH}) 47 | endforeach() 48 | endforeach() 49 | endforeach() 50 | 51 | foreach(VERSION RANGE 23 19) 52 | list(APPEND ARDUINO_PATHS arduino-00${VERSION}) 53 | endforeach() 54 | 55 | if(UNIX) 56 | file(GLOB SDK_PATH_HINTS /usr/share/arduino* 57 | /opt/local/arduino* 58 | /opt/arduino* 59 | /usr/local/share/arduino*) 60 | elseif(WIN32) 61 | set(SDK_PATH_HINTS "C:\\Program Files\\Arduino" 62 | "C:\\Program Files (x86)\\Arduino" 63 | ) 64 | endif() 65 | list(SORT SDK_PATH_HINTS) 66 | list(REVERSE SDK_PATH_HINTS) 67 | endif() 68 | 69 | find_path(ARDUINO_SDK_PATH 70 | NAMES lib/version.txt 71 | PATH_SUFFIXES share/arduino 72 | Arduino.app/Contents/Resources/Java/ 73 | Arduino.app/Contents/Java/ 74 | ${ARDUINO_PATHS} 75 | HINTS ${SDK_PATH_HINTS} 76 | DOC "Arduino SDK path.") 77 | 78 | if(ARDUINO_SDK_PATH) 79 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr) 80 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr/utils) 81 | else() 82 | message(FATAL_ERROR "Could not find Arduino SDK (set ARDUINO_SDK_PATH)!") 83 | endif() 84 | 85 | set(ARDUINO_CPUMENU) 86 | if(ARDUINO_CPU) 87 | set(ARDUINO_CPUMENU ".menu.cpu.${ARDUINO_CPU}") 88 | endif(ARDUINO_CPU) -------------------------------------------------------------------------------- /docs/README_breadboard.md: -------------------------------------------------------------------------------- 1 | # Default configuration with Nokia 5510 Display (PCD8544) 2 | 3 | ## Arduino Pinout 4 | in config.h check ```HARDWARE_REV 21``` 5 | All options are left to default values, else you have to change the connections 6 | 7 | ### A14: Voltage read-Pin 8 | Leave it open, it will read some random values... 9 | 10 | ### 38: FET: Pull high to switch off 11 | Add an LED with Resistor (~470Ω) to GND 12 | 13 | ### A15: Current read-Pin 14 | Leave it open, it will read some random values... 15 | 16 | ### 11: Buzzer 17 | Connect buzzer with resistor (~200Ω) to GND 18 | 19 | ### 37: Switch 20 | Connect a push switch to GND 21 | 22 | ### 12: Switch 2 23 | Connect a push switch to GND 24 | 25 | ## Nokia 5510 Display (PCD8544) 26 | Connect Display pin -> To arduino Pin 27 | The Display only supports 3.3V, use a level shifter for I/O Pins! 28 | ``` 29 | LED+ -> 3.3V 30 | VCC -> 3.3V 31 | GND -> GND 32 | 33 | sclk -> 7 [PH4] (clock) 34 | sdin -> 17 [PH0] (data-in) 35 | dc -> 16 [PH1] (data select) 36 | reset -> 6 [PH3] 37 | sce -> 8 [PH5] (enable)** 38 | ``` 39 | 40 | SCE is connected to PH2, but PH2 is not connected on the Arduino, so change the line 41 | ```cpp 42 | unsigned char sce = 2); /* enable (display pin 5) */ 43 | ``` 44 | to 45 | ```cpp 46 | unsigned char sce = 5); /* enable (display pin 5) */ 47 | ``` 48 | 49 | ### Serial Port 50 | You get all information on the Serial port to Debug 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /docs/README_cmake.txt: -------------------------------------------------------------------------------- 1 | If you like more control over the build process 2 | than the Java based Arduino UI provides, 3 | the CMAKE based build system is for you. 4 | 5 | It invokes avr-gcc and avrdude directly. 6 | 7 | Note: Linux only for now. Windows support is untested. 8 | 9 | 1. Setup: Create a build directory 10 | 11 | mkdir build 12 | cd build 13 | cmake ../ 14 | 15 | 2. Compile 16 | 17 | cd build 18 | make 19 | 20 | 3. Upload 21 | 22 | cd build 23 | make pcontroller-upload 24 | -------------------------------------------------------------------------------- /docs/README_hacking.txt: -------------------------------------------------------------------------------- 1 | *** Determine code size (linux only) *** 2 | nm --demangle --print-size --size-sort --reverse-sort -t d pcontroller.elf |less 3 | 4 | *** Interactive serial interface on linux *** 5 | socat - /dev/ttyUSB0,b115200,echo=0 6 | -------------------------------------------------------------------------------- /docs/README_menu.txt: -------------------------------------------------------------------------------- 1 | If you press display button 2 for a long time, 2 | you'll enter the on-the-go menu. 3 | 4 | Use display button 1 to go up, button 2 to go down. 5 | A long press of button 1 or button 2 will activate the current item. 6 | 7 | The menu closes automatically after selecting an item. 8 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Arduino-Pedelec-Controller 2 | Software for the Pedelec/E-Bike controller based on Arduino hardware, see www.pedelecforum.de "ForumsController" 3 | 4 | ## Board Pinout / Connections 5 | http://www.pedelecforum.de/wiki/doku.php?id=elektrotechnik:forumscontroller 6 | 7 | ## Documents 8 | * [Breadboard configuration](docs/README_breadboard.md) 9 | * [CMake](docs/README_cmake.txt) 10 | * [Hacking](docs/README_hacking.txt) 11 | * [Menu](docs/README_menu.txt) 12 | 13 | ## Code build status 14 | [![Build Status](https://travis-ci.org/jenkie/Arduino-Pedelec-Controller.svg?branch=master)](https://travis-ci.org/jenkie/Arduino-Pedelec-Controller) 15 | -------------------------------------------------------------------------------- /tools/code_reformat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # "astyle" tool used to reformat the 3 | # source code to a common base 4 | # TODO: Windows version 5 | /usr/bin/astyle --indent=spaces=4 --indent-switches --brackets=break \ 6 | --convert-tabs --keep-one-line-statements --keep-one-line-blocks \ 7 | $* 8 | --------------------------------------------------------------------------------