Code to run the controller for the wifi robot

Dependencies:   ESP8266Interface HTTPClient-SSL WebSocketClient mbed-rtos mbed

Committer:
anewton8
Date:
Tue Oct 20 17:35:45 2015 +0000
Revision:
0:e68e51f935d1
Finished controller code. Tuesday October 20th, 2015

Who changed what in which revision?

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