Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SeeedGrayOLED mbed
Fork of MBED_CPP_DII4A by
Diff: temp.cpp
- Revision:
- 2:fa5b67d8d989
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/temp.cpp Mon Mar 13 18:25:52 2017 +0000
@@ -0,0 +1,132 @@
+/*
+ * SeeedGrayOLED.cpp
+ * SSD1327 Gray OLED Driver Library for SSD1327
+ *
+ * Copyright (c) 2011 seeed technology inc.
+ * Author : Visweswara R
+ * Create Time : Dec 2011
+ * Change Log :
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "mbed.h"
+#include "TouchClamp.h"
+#include "I2C.h"
+#include <stdio.h>
+#include <string.h>
+
+// 8x8 Font ASCII 32 - 127 Implemented
+// Users can modify this to support more characters(glyphs)
+// BasicFont is placed in code memory.
+
+// This font can be freely used without any restriction(It is placed in public domain)
+// const unsigned char BasicFont[][8] PROGMEM=
+
+TouchClamp::TouchClamp(PinName sda, PinName scl,int addr):
+ _device(sda, scl)
+{
+ _addr = addr;
+}
+
+void TouchClamp::init(void)
+{
+ unsigned char mpr[3]={_addr,0x5E,0x00};
+ int ack = 0;
+ int i = 0;
+ // Put the MPR into setup mode
+ ack = write(mpr,3);
+
+ // Electrode filters for when data is > baseline
+ unsigned char elec_flt[6]={_addr,0x2B,0x01,0x01,0x00,0x00};
+ ack = write(elec_flt,6);
+
+ // Electrode filters for when data is < baseline
+ unsigned char elec_flt2[6]={_addr,0x2F,0x01,0x01,0x00,0x00};
+ ack = write(elec_flt2,6);
+
+ // Electrode touch and release thresholds
+ for(i=0; i<12; i++){
+ _device.start();
+ ack = _device.write(_addr);
+ ack = _device.write(0x41+(i*2));
+ ack = _device.write(0x0F);
+ ack = _device.write(0x0A);
+ _device.stop();
+ }
+
+ // Proximity Settings
+ unsigned char proximy[13]={_addr,0x36,0xff,0xff,0x00,0x00,0x01,0x01,0xff,0xff,0x00,0x00,0x00};
+ ack = write(proximy,13);
+
+ unsigned char proximy2[4]={_addr,0x59,0x5D,0x02};
+ ack = write(proximy2,4);
+
+ unsigned char proximy3[3]={_addr,0x5D,0x04};
+ ack = write(proximy3,3);
+
+ unsigned char proximy4[3]={_addr,0x5E,0x0C};
+ ack = write(proximy4,3);
+}
+
+int TouchClamp::write(unsigned char * data, int size)
+{
+ int i = 0;
+ int ack = 0;
+ /////////////////////
+ ///WRITE PROTOCOLE///
+ /////////////////////
+ _device.start();
+ ack = _device.write(_addr);
+ for(i=0;i<size;i++)
+ {
+ ack = _device.write(data[i]);
+ if(ack == 0)
+ return 0;
+ }
+ _device.stop();
+ return 1;
+}
+
+unsigned char TouchClamp::readTouch(unsigned char command)
+{
+ unsigned char result = 0;
+ int ack = 0; ////////////////////
+ ///READ PROTOCOLE///
+ ////////////////////
+ //Start the command
+ _device.start();
+ // Address the target (Write mode)
+ ack = _device.write(_addr);
+ if(ack == 0)
+ return 0;
+ // Re-send the target address in read mode
+ ack = _device.write(command);
+ if(ack == 0)
+ return 0;
+ // Re-start for read of data
+ _device.start();
+ // Re-send the target address in read mode
+ ack = _device.write(_addr+1);
+ if(ack == 0)
+ return 0;
+ // Read in the result
+ result = _device.read(0);
+ // Reset the bus
+ _device.stop();
+
+ return result;
+}
+
