A simple digital lock with attempted audio guidance

Dependencies:   FATFileSystem TextLCD mbed

Fork of Digital_Lock_with_audio by NITH ece

Committer:
4180_1
Date:
Wed Mar 16 01:49:13 2011 +0000
Revision:
0:e09703934ff4

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:e09703934ff4 1 /*
4180_1 0:e09703934ff4 2 Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au)
4180_1 0:e09703934ff4 3
4180_1 0:e09703934ff4 4
4180_1 0:e09703934ff4 5 Permission is hereby granted, free of charge, to any person obtaining a copy
4180_1 0:e09703934ff4 6 of this software and associated documentation files (the "Software"), to deal
4180_1 0:e09703934ff4 7 in the Software without restriction, including without limitation the rights
4180_1 0:e09703934ff4 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4180_1 0:e09703934ff4 9 copies of the Software, and to permit persons to whom the Software is
4180_1 0:e09703934ff4 10 furnished to do so, subject to the following conditions:
4180_1 0:e09703934ff4 11
4180_1 0:e09703934ff4 12 The above copyright notice and this permission notice shall be included in
4180_1 0:e09703934ff4 13 all copies or substantial portions of the Software.
4180_1 0:e09703934ff4 14
4180_1 0:e09703934ff4 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4180_1 0:e09703934ff4 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4180_1 0:e09703934ff4 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4180_1 0:e09703934ff4 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4180_1 0:e09703934ff4 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4180_1 0:e09703934ff4 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4180_1 0:e09703934ff4 21 THE SOFTWARE.
4180_1 0:e09703934ff4 22
4180_1 0:e09703934ff4 23 Parts written by Jim Lindblom of Sparkfun
4180_1 0:e09703934ff4 24 Ported to mbed by A.Buckton, Feb 2011
4180_1 0:e09703934ff4 25 */
4180_1 0:e09703934ff4 26
4180_1 0:e09703934ff4 27 #ifndef MPR121_H
4180_1 0:e09703934ff4 28 #define MPR121_H
4180_1 0:e09703934ff4 29
4180_1 0:e09703934ff4 30 //using namespace std;
4180_1 0:e09703934ff4 31
4180_1 0:e09703934ff4 32 class Mpr121
4180_1 0:e09703934ff4 33 {
4180_1 0:e09703934ff4 34
4180_1 0:e09703934ff4 35 public:
4180_1 0:e09703934ff4 36 // i2c Addresses, bit-shifted
4180_1 0:e09703934ff4 37 enum Address { ADD_VSS = 0xb4,// ADD->VSS = 0x5a <-wiring on Sparkfun board
4180_1 0:e09703934ff4 38 ADD_VDD = 0xb6,// ADD->VDD = 0x5b
4180_1 0:e09703934ff4 39 ADD_SCL = 0xb8,// ADD->SDA = 0x5c
4180_1 0:e09703934ff4 40 ADD_SDA = 0xba // ADD->SCL = 0x5d
4180_1 0:e09703934ff4 41 };
4180_1 0:e09703934ff4 42
4180_1 0:e09703934ff4 43 // Real initialiser, takes the i2c address of the device.
4180_1 0:e09703934ff4 44 Mpr121(I2C *i2c, Address i2cAddress);
4180_1 0:e09703934ff4 45
4180_1 0:e09703934ff4 46 bool getProximityMode();
4180_1 0:e09703934ff4 47
4180_1 0:e09703934ff4 48 void setProximityMode(bool mode);
4180_1 0:e09703934ff4 49
4180_1 0:e09703934ff4 50 int readTouchData();
4180_1 0:e09703934ff4 51
4180_1 0:e09703934ff4 52 unsigned char read(int key);
4180_1 0:e09703934ff4 53
4180_1 0:e09703934ff4 54 int write(int address, unsigned char value);
4180_1 0:e09703934ff4 55 int writeMany(int start, unsigned char* dataSet, int length);
4180_1 0:e09703934ff4 56
4180_1 0:e09703934ff4 57 void setElectrodeThreshold(int electrodeId, unsigned char touchThreshold, unsigned char releaseThreshold);
4180_1 0:e09703934ff4 58
4180_1 0:e09703934ff4 59 protected:
4180_1 0:e09703934ff4 60 // Configures the MPR with standard settings. This is permitted to be overwritten by sub-classes.
4180_1 0:e09703934ff4 61 void configureSettings();
4180_1 0:e09703934ff4 62
4180_1 0:e09703934ff4 63 private:
4180_1 0:e09703934ff4 64 // The I2C bus instance.
4180_1 0:e09703934ff4 65 I2C *i2c;
4180_1 0:e09703934ff4 66
4180_1 0:e09703934ff4 67 // i2c address of this mpr121
4180_1 0:e09703934ff4 68 Address address;
4180_1 0:e09703934ff4 69 };
4180_1 0:e09703934ff4 70
4180_1 0:e09703934ff4 71
4180_1 0:e09703934ff4 72 // MPR121 Register Defines
4180_1 0:e09703934ff4 73 #define MHD_R 0x2B
4180_1 0:e09703934ff4 74 #define NHD_R 0x2C
4180_1 0:e09703934ff4 75 #define NCL_R 0x2D
4180_1 0:e09703934ff4 76 #define FDL_R 0x2E
4180_1 0:e09703934ff4 77 #define MHD_F 0x2F
4180_1 0:e09703934ff4 78 #define NHD_F 0x30
4180_1 0:e09703934ff4 79 #define NCL_F 0x31
4180_1 0:e09703934ff4 80 #define FDL_F 0x32
4180_1 0:e09703934ff4 81 #define NHDT 0x33
4180_1 0:e09703934ff4 82 #define NCLT 0x34
4180_1 0:e09703934ff4 83 #define FDLT 0x35
4180_1 0:e09703934ff4 84 // Proximity sensing controls
4180_1 0:e09703934ff4 85 #define MHDPROXR 0x36
4180_1 0:e09703934ff4 86 #define NHDPROXR 0x37
4180_1 0:e09703934ff4 87 #define NCLPROXR 0x38
4180_1 0:e09703934ff4 88 #define FDLPROXR 0x39
4180_1 0:e09703934ff4 89 #define MHDPROXF 0x3A
4180_1 0:e09703934ff4 90 #define NHDPROXF 0x3B
4180_1 0:e09703934ff4 91 #define NCLPROXF 0x3C
4180_1 0:e09703934ff4 92 #define FDLPROXF 0x3D
4180_1 0:e09703934ff4 93 #define NHDPROXT 0x3E
4180_1 0:e09703934ff4 94 #define NCLPROXT 0x3F
4180_1 0:e09703934ff4 95 #define FDLPROXT 0x40
4180_1 0:e09703934ff4 96 // Electrode Touch/Release thresholds
4180_1 0:e09703934ff4 97 #define ELE0_T 0x41
4180_1 0:e09703934ff4 98 #define ELE0_R 0x42
4180_1 0:e09703934ff4 99 #define ELE1_T 0x43
4180_1 0:e09703934ff4 100 #define ELE1_R 0x44
4180_1 0:e09703934ff4 101 #define ELE2_T 0x45
4180_1 0:e09703934ff4 102 #define ELE2_R 0x46
4180_1 0:e09703934ff4 103 #define ELE3_T 0x47
4180_1 0:e09703934ff4 104 #define ELE3_R 0x48
4180_1 0:e09703934ff4 105 #define ELE4_T 0x49
4180_1 0:e09703934ff4 106 #define ELE4_R 0x4A
4180_1 0:e09703934ff4 107 #define ELE5_T 0x4B
4180_1 0:e09703934ff4 108 #define ELE5_R 0x4C
4180_1 0:e09703934ff4 109 #define ELE6_T 0x4D
4180_1 0:e09703934ff4 110 #define ELE6_R 0x4E
4180_1 0:e09703934ff4 111 #define ELE7_T 0x4F
4180_1 0:e09703934ff4 112 #define ELE7_R 0x50
4180_1 0:e09703934ff4 113 #define ELE8_T 0x51
4180_1 0:e09703934ff4 114 #define ELE8_R 0x52
4180_1 0:e09703934ff4 115 #define ELE9_T 0x53
4180_1 0:e09703934ff4 116 #define ELE9_R 0x54
4180_1 0:e09703934ff4 117 #define ELE10_T 0x55
4180_1 0:e09703934ff4 118 #define ELE10_R 0x56
4180_1 0:e09703934ff4 119 #define ELE11_T 0x57
4180_1 0:e09703934ff4 120 #define ELE11_R 0x58
4180_1 0:e09703934ff4 121 // Proximity Touch/Release thresholds
4180_1 0:e09703934ff4 122 #define EPROXTTH 0x59
4180_1 0:e09703934ff4 123 #define EPROXRTH 0x5A
4180_1 0:e09703934ff4 124 // Debounce configuration
4180_1 0:e09703934ff4 125 #define DEB_CFG 0x5B
4180_1 0:e09703934ff4 126 // AFE- Analogue Front End configuration
4180_1 0:e09703934ff4 127 #define AFE_CFG 0x5C
4180_1 0:e09703934ff4 128 // Filter configuration
4180_1 0:e09703934ff4 129 #define FIL_CFG 0x5D
4180_1 0:e09703934ff4 130 // Electrode configuration - transistions to "active mode"
4180_1 0:e09703934ff4 131 #define ELE_CFG 0x5E
4180_1 0:e09703934ff4 132
4180_1 0:e09703934ff4 133 #define GPIO_CTRL0 0x73
4180_1 0:e09703934ff4 134 #define GPIO_CTRL1 0x74
4180_1 0:e09703934ff4 135 #define GPIO_DATA 0x75
4180_1 0:e09703934ff4 136 #define GPIO_DIR 0x76
4180_1 0:e09703934ff4 137 #define GPIO_EN 0x77
4180_1 0:e09703934ff4 138 #define GPIO_SET 0x78
4180_1 0:e09703934ff4 139 #define GPIO_CLEAR 0x79
4180_1 0:e09703934ff4 140 #define GPIO_TOGGLE 0x7A
4180_1 0:e09703934ff4 141 // Auto configration registers
4180_1 0:e09703934ff4 142 #define AUTO_CFG_0 0x7B
4180_1 0:e09703934ff4 143 #define AUTO_CFG_U 0x7D
4180_1 0:e09703934ff4 144 #define AUTO_CFG_L 0x7E
4180_1 0:e09703934ff4 145 #define AUTO_CFG_T 0x7F
4180_1 0:e09703934ff4 146
4180_1 0:e09703934ff4 147 // Threshold defaults
4180_1 0:e09703934ff4 148 // Electrode touch threshold
4180_1 0:e09703934ff4 149 #define E_THR_T 0x0F
4180_1 0:e09703934ff4 150 // Electrode release threshold
4180_1 0:e09703934ff4 151 #define E_THR_R 0x0A
4180_1 0:e09703934ff4 152 // Prox touch threshold
4180_1 0:e09703934ff4 153 #define PROX_THR_T 0x02
4180_1 0:e09703934ff4 154 // Prox release threshold
4180_1 0:e09703934ff4 155 #define PROX_THR_R 0x02
4180_1 0:e09703934ff4 156
4180_1 0:e09703934ff4 157 #endif