10.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef EEPROMAnything_H
  2. #define EEPROMAnything_H
  3. #include <EEPROM.h>
  4. #include <Arduino.h> // for type definitions
  5. // Source: http://arduino.cc/playground/Code/EEPROMWriteAnything
  6. // [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
  7. // []
  8. // [] V-Strom Mk1B - An extra display for a Suzuki DL-650 ("V-Strom") that adds the following functionality:
  9. // [] 1. Battery Level display in Volts - e.g. 14.5V
  10. // [] 2. Gear Position Indicator on LCD - e.g. 1, 2, 3, 4, 5, 6, N
  11. // [] 3. Ambient Temperature in Farenheight or Celsius - e.g. 62.5F
  12. // [] 4. [Future] LED display of gear position (one led for each gear 1-6, in different colors, N will be blinking on 1)
  13. // [] 5. [Future] Accurate display of the fuel level (in percentage)
  14. // [] 6. [Future] Show Fuel consumption - MPG or KM/L, TBD: need to tap into motorcycle's speed sensor (PWM)
  15. // [] 7. [Future] Fix the OEM V-Strom Fuel Gauge to become linear
  16. // [] License: GPL V3
  17. /*
  18. Stromputer - Enhanced display for Suzuki V-Strom Motorcycles (DL-650, DL-1000, years 2004-2011)
  19. Copyright (C) 2011 Yuval Naveh
  20. This program is free software: you can redistribute it and/or modify
  21. it under the terms of the GNU General Public License as published by
  22. the Free Software Foundation, either version 3 of the License, or
  23. (at your option) any later version.
  24. This program is distributed in the hope that it will be useful,
  25. but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. GNU General Public License for more details.
  28. You should have received a copy of the GNU General Public License
  29. along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. */
  31. /*
  32. .::::::.:::::::::::::::::::.. ... . :::::::::::. ... :::::::::::::::.,:::::: :::::::..
  33. ;;;` `;;;;;;;;'''';;;;``;;;; .;;;;;;;. ;;,. ;;;`;;;```.;;;;; ;;;;;;;;;;;'''';;;;'''' ;;;;``;;;;
  34. '[==/[[[[, [[ [[[,/[[[' ,[[ \[[,[[[[, ,[[[[,`]]nnn]]'[[' [[[ [[ [[cccc [[[,/[[['
  35. ''' $ $$ $$$$$$c $$$, $$$$$$$$$$$"$$$ $$$"" $$ $$$ $$ $$"""" $$$$$$c
  36. 88b dP 88, 888b "88bo,"888,_ _,88P888 Y88" 888o888o 88 .d888 88, 888oo,__ 888b "88bo,
  37. "YMmMY" MMM MMMM "W" "YMMMMMP" MMM M' "MMMYMMMb "YmmMMMM"" MMM """"YUMMMMMMM "W"
  38. */
  39. // Write a template value into EEPROM address [ee]
  40. template <class T> int EEPROM_writeAnything(int ee, const T& value)
  41. {
  42. const byte* p = (const byte*)(const void*)&value;
  43. unsigned int i;
  44. for (i = 0; i < sizeof(value); i++)
  45. EEPROM.write(ee++, *p++);
  46. return i;
  47. }
  48. // Read a template value from EEPROM address [ee]
  49. template <class T> int EEPROM_readAnything(int ee, T& value)
  50. {
  51. byte* p = (byte*)(void*)&value;
  52. unsigned int i;
  53. for (i = 0; i < sizeof(value); i++)
  54. *p++ = EEPROM.read(ee++);
  55. return i;
  56. }
  57. #endif