ArduinoLibs
|
00001 /* 00002 * Copyright (C) 2012 Southern Storm Software, Pty Ltd. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00019 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00020 * DEALINGS IN THE SOFTWARE. 00021 */ 00022 00023 #ifndef LCD_h 00024 #define LCD_h 00025 00026 // Extended version of the LiquidCrystal library that works specifically 00027 // with Freetronics' 16x2 LCD display, including support for the back 00028 // light and the Up/Down/Left/Right/Select buttons. More info: 00029 // 00030 // http://www.freetronics.com/pages/16x2-lcd-shield-quickstart-guide 00031 00032 // Include a copy of the standard LiquidCrystal library so we can extend it. 00033 #include "utility/LiquidCrystal.h" 00034 00035 // Button event codes. 00036 #define LCD_BUTTON_NONE 0 00037 #define LCD_BUTTON_LEFT 1 00038 #define LCD_BUTTON_RIGHT 2 00039 #define LCD_BUTTON_UP 3 00040 #define LCD_BUTTON_DOWN 4 00041 #define LCD_BUTTON_SELECT 5 00042 #define LCD_BUTTON_LEFT_RELEASED -1 00043 #define LCD_BUTTON_RIGHT_RELEASED -2 00044 #define LCD_BUTTON_UP_RELEASED -3 00045 #define LCD_BUTTON_DOWN_RELEASED -4 00046 #define LCD_BUTTON_SELECT_RELEASED -5 00047 00048 class LCD : public LiquidCrystal { 00049 public: 00050 LCD() : LiquidCrystal(8, 9, 4, 5, 6, 7) { init(); } 00051 LCD(uint8_t pin9) : LiquidCrystal(8, pin9, 4, 5, 6, 7) { init(); } 00052 00053 uint8_t backlightPin() const { return _backlightPin; } 00054 void setBacklightPin(uint8_t pin); 00055 00056 void display(); 00057 void noDisplay(); 00058 00059 enum ScreenSaverMode 00060 { 00061 DisplayOff, 00062 BacklightOff, 00063 BacklightOnSelect 00064 }; 00065 00066 ScreenSaverMode screenSaverMode() const { return mode; } 00067 void setScreenSaverMode(ScreenSaverMode mode); 00068 00069 void enableScreenSaver(int timeoutSecs = 10); 00070 void disableScreenSaver(); 00071 bool isScreenSaved() const { return screenSaved; } 00072 00073 int getButton(); 00074 00075 private: 00076 uint8_t _backlightPin; 00077 bool backlightInit; 00078 int prevButton; 00079 int debounceButton; 00080 unsigned long timeout; 00081 unsigned long lastRestore; 00082 unsigned long lastDebounce; 00083 bool screenSaved; 00084 bool eatRelease; 00085 ScreenSaverMode mode; 00086 00087 void init(); 00088 }; 00089 00090 #endif