light off mechanics
This commit is contained in:
parent
cb9483e6ff
commit
99e4edf762
15
.cproject
15
.cproject
@ -34,6 +34,9 @@
|
|||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Touch-Screen}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Touch-Screen}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/WiFi}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/WiFi}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/WiFi/src}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/WiFi/src}""/>
|
||||||
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Adafruit_FT6206}""/>
|
||||||
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/Wire}""/>
|
||||||
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/Wire/utility}""/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="it.baeyens.arduino.compiler.cpp.sketch.input.505756577" name="CPP source files" superClass="it.baeyens.arduino.compiler.cpp.sketch.input"/>
|
<inputType id="it.baeyens.arduino.compiler.cpp.sketch.input.505756577" name="CPP source files" superClass="it.baeyens.arduino.compiler.cpp.sketch.input"/>
|
||||||
</tool>
|
</tool>
|
||||||
@ -50,6 +53,9 @@
|
|||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Touch-Screen}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Touch-Screen}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/WiFi}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/WiFi}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/WiFi/src}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/WiFi/src}""/>
|
||||||
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Adafruit_FT6206}""/>
|
||||||
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/Wire}""/>
|
||||||
|
<listOptionValue builtIn="false" value=""${workspace_loc:/MqttMonitor/Libraries/Wire/utility}""/>
|
||||||
</option>
|
</option>
|
||||||
<inputType id="it.baeyens.arduino.compiler.c.sketch.input.575652065" name="C Source Files" superClass="it.baeyens.arduino.compiler.c.sketch.input"/>
|
<inputType id="it.baeyens.arduino.compiler.c.sketch.input.575652065" name="C Source Files" superClass="it.baeyens.arduino.compiler.c.sketch.input"/>
|
||||||
</tool>
|
</tool>
|
||||||
@ -62,8 +68,9 @@
|
|||||||
</toolChain>
|
</toolChain>
|
||||||
</folderInfo>
|
</folderInfo>
|
||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
<entry excluding="Adafruit-GFX|Libraries/*/?xamples|Streaming|MQTT|TFT_ILI9341|Libraries/*/?xtras|Metro|Touch-Screen|TFTLCD" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
<entry excluding="Adafruit_FT6206|Adafruit-GFX|Libraries/*/?xamples|Streaming|MQTT|TFT_ILI9341|Libraries/*/?xtras|Metro|Touch-Screen|TFTLCD" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Adafruit-GFX"/>
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Adafruit-GFX"/>
|
||||||
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Adafruit_FT6206"/>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTT"/>
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTT"/>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Metro"/>
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Metro"/>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Streaming"/>
|
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Streaming"/>
|
||||||
@ -82,6 +89,10 @@
|
|||||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||||
<storageModule moduleId="refreshScope"/>
|
<storageModule moduleId="refreshScope" versionNumber="2">
|
||||||
|
<configuration configurationName="Release">
|
||||||
|
<resource resourceType="PROJECT" workspacePath="/MqttMonitor"/>
|
||||||
|
</configuration>
|
||||||
|
</storageModule>
|
||||||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
||||||
</cproject>
|
</cproject>
|
||||||
|
5
.project
5
.project
@ -36,6 +36,11 @@
|
|||||||
<type>2</type>
|
<type>2</type>
|
||||||
<locationURI>ArduinoLibPath/WiFi</locationURI>
|
<locationURI>ArduinoLibPath/WiFi</locationURI>
|
||||||
</link>
|
</link>
|
||||||
|
<link>
|
||||||
|
<name>Libraries/Wire</name>
|
||||||
|
<type>2</type>
|
||||||
|
<locationURI>ArduinoHardwareLibPath/Wire</locationURI>
|
||||||
|
</link>
|
||||||
<link>
|
<link>
|
||||||
<name>arduino/core</name>
|
<name>arduino/core</name>
|
||||||
<type>2</type>
|
<type>2</type>
|
||||||
|
@ -154,10 +154,10 @@ environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA
|
|||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.DTS/value=3600
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.DTS/value=3600
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/delimiter=\:
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/delimiter=\:
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/operation=replace
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/operation=replace
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/value=1468171079
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.LOCAL/value=1468270614
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/delimiter=\:
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/delimiter=\:
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/operation=replace
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/operation=replace
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/value=1468163879
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.UTC/value=1468263414
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/delimiter=\:
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/delimiter=\:
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/operation=replace
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/operation=replace
|
||||||
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/value=3600
|
environment/project/it.baeyens.arduino.core.toolChain.release.1898938335/A.EXTRA.TIME.ZONE/value=3600
|
||||||
|
225
Adafruit_FT6206/Adafruit_FT6206.cpp
Normal file
225
Adafruit_FT6206/Adafruit_FT6206.cpp
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
/***************************************************
|
||||||
|
This is a library for the Adafruit Capacitive Touch Screens
|
||||||
|
|
||||||
|
----> http://www.adafruit.com/products/1947
|
||||||
|
|
||||||
|
Check out the links above for our tutorials and wiring diagrams
|
||||||
|
This chipset uses I2C to communicate
|
||||||
|
|
||||||
|
Adafruit invests time and resources providing this open source code,
|
||||||
|
please support Adafruit and open-source hardware by purchasing
|
||||||
|
products from Adafruit!
|
||||||
|
|
||||||
|
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||||
|
MIT license, all text above must be included in any redistribution
|
||||||
|
****************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#if ARDUINO >= 100
|
||||||
|
#include "Arduino.h"
|
||||||
|
#else
|
||||||
|
#include "WProgram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#include <Adafruit_FT6206.h>
|
||||||
|
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
#define Wire Wire1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Instantiates a new FT6206 class
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
// I2C, no address adjustments or pins
|
||||||
|
Adafruit_FT6206::Adafruit_FT6206() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
|
@brief Setups the HW
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
boolean Adafruit_FT6206::begin(uint8_t threshhold) {
|
||||||
|
Wire.begin();
|
||||||
|
|
||||||
|
// change threshhold to be higher/lower
|
||||||
|
writeRegister8(FT6206_REG_THRESHHOLD, threshhold);
|
||||||
|
|
||||||
|
if ((readRegister8(FT6206_REG_VENDID) != 17) || (readRegister8(FT6206_REG_CHIPID) != 6)) return false;
|
||||||
|
/*
|
||||||
|
Serial.print("Vend ID: "); Serial.println(readRegister8(FT6206_REG_VENDID));
|
||||||
|
Serial.print("Chip ID: "); Serial.println(readRegister8(FT6206_REG_CHIPID));
|
||||||
|
Serial.print("Firm V: "); Serial.println(readRegister8(FT6206_REG_FIRMVERS));
|
||||||
|
Serial.print("Point Rate Hz: "); Serial.println(readRegister8(FT6206_REG_POINTRATE));
|
||||||
|
Serial.print("Thresh: "); Serial.println(readRegister8(FT6206_REG_THRESHHOLD));
|
||||||
|
*/
|
||||||
|
// dump all registers
|
||||||
|
/*
|
||||||
|
for (int16_t i=0; i<0x20; i++) {
|
||||||
|
Serial.print("I2C $"); Serial.print(i, HEX);
|
||||||
|
Serial.print(" = 0x"); Serial.println(readRegister8(i), HEX);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DONT DO THIS - REALLY - IT DOESNT WORK
|
||||||
|
void Adafruit_FT6206::autoCalibrate(void) {
|
||||||
|
writeRegister8(FT6206_REG_MODE, FT6206_REG_FACTORYMODE);
|
||||||
|
delay(100);
|
||||||
|
//Serial.println("Calibrating...");
|
||||||
|
writeRegister8(FT6206_REG_CALIBRATE, 4);
|
||||||
|
delay(300);
|
||||||
|
for (uint8_t i = 0; i < 100; i++) {
|
||||||
|
uint8_t temp;
|
||||||
|
temp = readRegister8(FT6206_REG_MODE);
|
||||||
|
Serial.println(temp, HEX);
|
||||||
|
//return to normal mode, calibration finish
|
||||||
|
if (0x0 == ((temp & 0x70) >> 4))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
delay(200);
|
||||||
|
//Serial.println("Calibrated");
|
||||||
|
delay(300);
|
||||||
|
writeRegister8(FT6206_REG_MODE, FT6206_REG_FACTORYMODE);
|
||||||
|
delay(100);
|
||||||
|
writeRegister8(FT6206_REG_CALIBRATE, 5);
|
||||||
|
delay(300);
|
||||||
|
writeRegister8(FT6206_REG_MODE, FT6206_REG_WORKMODE);
|
||||||
|
delay(300);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
boolean Adafruit_FT6206::touched(void) {
|
||||||
|
|
||||||
|
uint8_t n = readRegister8(FT6206_REG_NUMTOUCHES);
|
||||||
|
if ((n == 1) || (n == 2)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************/
|
||||||
|
|
||||||
|
void Adafruit_FT6206::readData(uint16_t *x, uint16_t *y) {
|
||||||
|
|
||||||
|
uint8_t i2cdat[16];
|
||||||
|
Wire.beginTransmission(FT6206_ADDR);
|
||||||
|
Wire.write((byte)0);
|
||||||
|
Wire.endTransmission();
|
||||||
|
Wire.beginTransmission(FT6206_ADDR);
|
||||||
|
Wire.requestFrom((byte)FT6206_ADDR, (byte)32);
|
||||||
|
for (uint8_t i=0; i<16; i++)
|
||||||
|
i2cdat[i] = Wire.read();
|
||||||
|
Wire.endTransmission();
|
||||||
|
|
||||||
|
/*
|
||||||
|
for (int16_t i=0; i<0x20; i++) {
|
||||||
|
Serial.print("I2C $"); Serial.print(i, HEX); Serial.print(" = 0x"); Serial.println(i2cdat[i], HEX);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
touches = i2cdat[0x02];
|
||||||
|
|
||||||
|
//Serial.println(touches);
|
||||||
|
if (touches > 2) {
|
||||||
|
touches = 0;
|
||||||
|
*x = *y = 0;
|
||||||
|
}
|
||||||
|
if (touches == 0) {
|
||||||
|
*x = *y = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (touches == 2) Serial.print('2');
|
||||||
|
for (uint8_t i=0; i<16; i++) {
|
||||||
|
// Serial.print("0x"); Serial.print(i2cdat[i], HEX); Serial.print(" ");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Serial.println();
|
||||||
|
if (i2cdat[0x01] != 0x00) {
|
||||||
|
Serial.print("Gesture #");
|
||||||
|
Serial.println(i2cdat[0x01]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Serial.print("# Touches: "); Serial.print(touches);
|
||||||
|
for (uint8_t i=0; i<2; i++) {
|
||||||
|
touchX[i] = i2cdat[0x03 + i*6] & 0x0F;
|
||||||
|
touchX[i] <<= 8;
|
||||||
|
touchX[i] |= i2cdat[0x04 + i*6];
|
||||||
|
touchY[i] = i2cdat[0x05 + i*6] & 0x0F;
|
||||||
|
touchY[i] <<= 8;
|
||||||
|
touchY[i] |= i2cdat[0x06 + i*6];
|
||||||
|
touchID[i] = i2cdat[0x05 + i*6] >> 4;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Serial.println();
|
||||||
|
for (uint8_t i=0; i<touches; i++) {
|
||||||
|
Serial.print("ID #"); Serial.print(touchID[i]); Serial.print("\t("); Serial.print(touchX[i]);
|
||||||
|
Serial.print(", "); Serial.print(touchY[i]);
|
||||||
|
Serial.print (") ");
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
*/
|
||||||
|
*x = touchX[0]; *y = touchY[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
TS_Point Adafruit_FT6206::getPoint(void) {
|
||||||
|
uint16_t x, y;
|
||||||
|
uint8_t z;
|
||||||
|
readData(&x, &y);
|
||||||
|
return TS_Point(x, y, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t Adafruit_FT6206::readRegister8(uint8_t reg) {
|
||||||
|
uint8_t x ;
|
||||||
|
// use i2c
|
||||||
|
Wire.beginTransmission(FT6206_ADDR);
|
||||||
|
Wire.write((byte)reg);
|
||||||
|
Wire.endTransmission();
|
||||||
|
Wire.beginTransmission(FT6206_ADDR);
|
||||||
|
Wire.requestFrom((byte)FT6206_ADDR, (byte)1);
|
||||||
|
x = Wire.read();
|
||||||
|
Wire.endTransmission();
|
||||||
|
|
||||||
|
// Serial.print("$"); Serial.print(reg, HEX);
|
||||||
|
// Serial.print(": 0x"); Serial.println(x, HEX);
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Adafruit_FT6206::writeRegister8(uint8_t reg, uint8_t val) {
|
||||||
|
// use i2c
|
||||||
|
Wire.beginTransmission(FT6206_ADDR);
|
||||||
|
Wire.write((byte)reg);
|
||||||
|
Wire.write((byte)val);
|
||||||
|
Wire.endTransmission();
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************/
|
||||||
|
|
||||||
|
TS_Point::TS_Point(void) {
|
||||||
|
x = y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TS_Point::TS_Point(int16_t x0, int16_t y0, int16_t z0) {
|
||||||
|
x = x0;
|
||||||
|
y = y0;
|
||||||
|
z = z0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TS_Point::operator==(TS_Point p1) {
|
||||||
|
return ((p1.x == x) && (p1.y == y) && (p1.z == z));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TS_Point::operator!=(TS_Point p1) {
|
||||||
|
return ((p1.x != x) || (p1.y != y) || (p1.z != z));
|
||||||
|
}
|
81
Adafruit_FT6206/Adafruit_FT6206.h
Normal file
81
Adafruit_FT6206/Adafruit_FT6206.h
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/***************************************************
|
||||||
|
This is a library for the Adafruit Capacitive Touch Screens
|
||||||
|
|
||||||
|
----> http://www.adafruit.com/products/1947
|
||||||
|
|
||||||
|
Check out the links above for our tutorials and wiring diagrams
|
||||||
|
This chipset uses I2C to communicate
|
||||||
|
|
||||||
|
Adafruit invests time and resources providing this open source code,
|
||||||
|
please support Adafruit and open-source hardware by purchasing
|
||||||
|
products from Adafruit!
|
||||||
|
|
||||||
|
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||||
|
MIT license, all text above must be included in any redistribution
|
||||||
|
****************************************************/
|
||||||
|
|
||||||
|
#ifndef ADAFRUIT_FT6206_LIBRARY
|
||||||
|
#define ADAFRUIT_FT6206_LIBRARY
|
||||||
|
|
||||||
|
#if ARDUINO >= 100
|
||||||
|
#include "Arduino.h"
|
||||||
|
#else
|
||||||
|
#include "WProgram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define FT6206_ADDR 0x38
|
||||||
|
#define FT6206_G_FT5201ID 0xA8
|
||||||
|
#define FT6206_REG_NUMTOUCHES 0x02
|
||||||
|
|
||||||
|
#define FT6206_NUM_X 0x33
|
||||||
|
#define FT6206_NUM_Y 0x34
|
||||||
|
|
||||||
|
#define FT6206_REG_MODE 0x00
|
||||||
|
#define FT6206_REG_CALIBRATE 0x02
|
||||||
|
#define FT6206_REG_WORKMODE 0x00
|
||||||
|
#define FT6206_REG_FACTORYMODE 0x40
|
||||||
|
#define FT6206_REG_THRESHHOLD 0x80
|
||||||
|
#define FT6206_REG_POINTRATE 0x88
|
||||||
|
#define FT6206_REG_FIRMVERS 0xA6
|
||||||
|
#define FT6206_REG_CHIPID 0xA3
|
||||||
|
#define FT6206_REG_VENDID 0xA8
|
||||||
|
|
||||||
|
// calibrated for Adafruit 2.8" ctp screen
|
||||||
|
#define FT6206_DEFAULT_THRESSHOLD 128
|
||||||
|
|
||||||
|
class TS_Point {
|
||||||
|
public:
|
||||||
|
TS_Point(void);
|
||||||
|
TS_Point(int16_t x, int16_t y, int16_t z);
|
||||||
|
|
||||||
|
bool operator==(TS_Point);
|
||||||
|
bool operator!=(TS_Point);
|
||||||
|
|
||||||
|
int16_t x, y, z;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Adafruit_FT6206 {
|
||||||
|
public:
|
||||||
|
|
||||||
|
Adafruit_FT6206(void);
|
||||||
|
boolean begin(uint8_t thresh = FT6206_DEFAULT_THRESSHOLD);
|
||||||
|
|
||||||
|
void writeRegister8(uint8_t reg, uint8_t val);
|
||||||
|
uint8_t readRegister8(uint8_t reg);
|
||||||
|
|
||||||
|
void readData(uint16_t *x, uint16_t *y);
|
||||||
|
void autoCalibrate(void);
|
||||||
|
|
||||||
|
boolean touched(void);
|
||||||
|
TS_Point getPoint(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t touches;
|
||||||
|
uint16_t touchX[2], touchY[2], touchID[2];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //ADAFRUIT_FT6206_LIBRARY
|
45
hmi.cpp
45
hmi.cpp
@ -10,9 +10,15 @@
|
|||||||
|
|
||||||
using namespace HmiNS;
|
using namespace HmiNS;
|
||||||
|
|
||||||
Hmi::Hmi() : m_tft(6, 9, 11, 13, -1, 12), // m_tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET),
|
Hmi::Hmi() : m_tft(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST, TFT_MISO), // m_tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET),
|
||||||
|
m_ctp(),
|
||||||
|
m_backLightPin(TFT_BACKLIGHT),
|
||||||
|
m_backLightEnable(true),
|
||||||
m_displayIdentifier(0),
|
m_displayIdentifier(0),
|
||||||
m_alarmMessageAvailable(false)
|
m_alarmMessageAvailable(false),
|
||||||
|
m_seconds(0),
|
||||||
|
m_lightOn(LIGHT_ON),
|
||||||
|
m_lightOff(LIGHT_OFF)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (uint8_t i = 0; i < NUM_OF_MESSAGESLOTS; i++) {
|
for (uint8_t i = 0; i < NUM_OF_MESSAGESLOTS; i++) {
|
||||||
@ -25,15 +31,25 @@ Hmi::Hmi() : m_tft(6, 9, 11, 13, -1, 12), // m_tft(LCD_CS, LCD_CD, LCD_WR, LCD_R
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Hmi::begin() {
|
void Hmi::begin() {
|
||||||
|
pinMode(5, OUTPUT);
|
||||||
|
digitalWrite(5, HIGH);
|
||||||
|
|
||||||
m_tft.begin();
|
m_tft.begin();
|
||||||
m_tft.setRotation(1);
|
m_tft.setRotation(1);
|
||||||
m_tft.setTextSize(2);
|
m_tft.setTextSize(2);
|
||||||
m_tft.fillScreen(BLACK);
|
m_tft.fillScreen(BLACK);
|
||||||
|
|
||||||
|
if (! m_ctp.begin(40)) { // pass in 'sensitivity' coefficient
|
||||||
|
Serial.println("Couldn't start FT6206 touchscreen controller");
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hmi::clear() {
|
void Hmi::clear() {
|
||||||
m_tft.fillScreen(BLACK);
|
m_tft.fillScreen(BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hmi::updateMessage(uint8_t slot, char* header, char* body) {
|
void Hmi::updateMessage(uint8_t slot, char* header, char* body) {
|
||||||
uint8_t index = slot - 1; // slots start at 1, the index starts at 0
|
uint8_t index = slot - 1; // slots start at 1, the index starts at 0
|
||||||
if (index < NUM_OF_MESSAGESLOTS) {
|
if (index < NUM_OF_MESSAGESLOTS) {
|
||||||
@ -73,6 +89,31 @@ void Hmi::drawMessages() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hmi::setSeconds(uint32_t seconds) {
|
||||||
|
m_seconds = seconds;
|
||||||
|
}
|
||||||
|
|
||||||
void Hmi::exec() {
|
void Hmi::exec() {
|
||||||
drawMessages();
|
drawMessages();
|
||||||
|
|
||||||
|
static uint32_t oldSeconds = 0;
|
||||||
|
if (m_seconds != oldSeconds) {
|
||||||
|
oldSeconds = m_seconds;
|
||||||
|
Serial << "LIGHT_OFF: " << m_lightOff << endl;
|
||||||
|
Serial << "LIGHT_ON: " << m_lightOn << endl;
|
||||||
|
Serial << "enable: " << m_backLightEnable << endl;
|
||||||
|
Serial << "Seconds: " << m_seconds << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((m_seconds > m_lightOff) || (m_seconds < m_lightOn)) && !m_ctp.touched() && m_backLightEnable) {
|
||||||
|
m_backLightEnable = false;
|
||||||
|
digitalWrite(m_backLightPin, LOW);
|
||||||
|
Serial << "lights off" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((((m_seconds < m_lightOff) && (m_seconds > m_lightOn)) || m_ctp.touched()) && !m_backLightEnable) {
|
||||||
|
m_backLightEnable = true;
|
||||||
|
digitalWrite(m_backLightPin, HIGH);
|
||||||
|
Serial << "lights on" << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
26
hmi.h
26
hmi.h
@ -12,15 +12,19 @@
|
|||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
// #include <Adafruit_TFTLCD.h>
|
// #include <Adafruit_TFTLCD.h>
|
||||||
#include "Adafruit_ILI9341.h"
|
#include "Adafruit_ILI9341.h"
|
||||||
|
#include <Adafruit_FT6206.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace HmiNS {
|
namespace HmiNS {
|
||||||
// const static uint8_t LCD_CS = A3;
|
const static int8_t TFT_CS = 6;
|
||||||
// const static uint8_t LCD_CD = A2;
|
const static int8_t TFT_DC = 9;
|
||||||
// const static uint8_t LCD_WR = A1;
|
const static int8_t TFT_MOSI = 11;
|
||||||
// const static uint8_t LCD_RD = A0;
|
const static int8_t TFT_SCLK = 13;
|
||||||
// const static uint8_t LCD_RESET = A4;
|
const static int8_t TFT_RST = -1;
|
||||||
|
const static int8_t TFT_MISO = 12;
|
||||||
|
const static int8_t TFT_BACKLIGHT = 5;
|
||||||
|
|
||||||
const static uint16_t BLACK = 0x0000;
|
const static uint16_t BLACK = 0x0000;
|
||||||
const static uint16_t BLUE = 0x001F;
|
const static uint16_t BLUE = 0x001F;
|
||||||
@ -33,6 +37,10 @@ namespace HmiNS {
|
|||||||
|
|
||||||
const static uint8_t BUFFERLEN_MESSAGESLOT = 9;
|
const static uint8_t BUFFERLEN_MESSAGESLOT = 9;
|
||||||
const static uint8_t NUM_OF_MESSAGESLOTS = 10;
|
const static uint8_t NUM_OF_MESSAGESLOTS = 10;
|
||||||
|
|
||||||
|
const static uint32_t LIGHT_OFF = 79200;
|
||||||
|
const static uint32_t LIGHT_ON = 25200;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -52,11 +60,19 @@ public:
|
|||||||
void updateMessage(uint8_t slot, char* header, char* body);
|
void updateMessage(uint8_t slot, char* header, char* body);
|
||||||
void toggleAlarmState(); // only for debug
|
void toggleAlarmState(); // only for debug
|
||||||
void clear();
|
void clear();
|
||||||
|
void setSeconds(uint32_t seconds);
|
||||||
private:
|
private:
|
||||||
void drawMessages();
|
void drawMessages();
|
||||||
Adafruit_ILI9341 m_tft;
|
Adafruit_ILI9341 m_tft;
|
||||||
|
Adafruit_FT6206 m_ctp;
|
||||||
|
|
||||||
|
int8_t m_backLightPin;
|
||||||
|
bool m_backLightEnable;
|
||||||
uint16_t m_displayIdentifier;
|
uint16_t m_displayIdentifier;
|
||||||
bool m_alarmMessageAvailable;
|
bool m_alarmMessageAvailable;
|
||||||
|
uint32_t m_seconds;
|
||||||
|
uint32_t m_lightOn;
|
||||||
|
uint32_t m_lightOff;
|
||||||
MessageSlot m_messageSlots[HmiNS::NUM_OF_MESSAGESLOTS];
|
MessageSlot m_messageSlots[HmiNS::NUM_OF_MESSAGESLOTS];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ extern Hmi hmi;
|
|||||||
|
|
||||||
static const char MESSAGE_TOPIC[] = "IoT/Monitor/Message";
|
static const char MESSAGE_TOPIC[] = "IoT/Monitor/Message";
|
||||||
static const char ALARM_TOPIC[] = "IoT/Monitor/Alarm";
|
static const char ALARM_TOPIC[] = "IoT/Monitor/Alarm";
|
||||||
|
static const char SECONDS_TOPIC[] = "IoT/SecondsSinceMidnight";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void callback(char* topic, byte* payload, unsigned int length);
|
void callback(char* topic, byte* payload, unsigned int length);
|
||||||
@ -77,6 +79,9 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
hmi.updateMessage(slot, headerStr, bodyStr);
|
hmi.updateMessage(slot, headerStr, bodyStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (!strcmp(topic, SECONDS_TOPIC)) {
|
||||||
|
uint32_t seconds = atol(buffer);
|
||||||
|
hmi.setSeconds(seconds);
|
||||||
} else {
|
} else {
|
||||||
Serial << "Strange, unknown topic received" << endl;
|
Serial << "Strange, unknown topic received" << endl;
|
||||||
}
|
}
|
||||||
@ -170,6 +175,7 @@ void MqttClientNS::exec() {
|
|||||||
if (mqttClient.connect("Monitor")) {
|
if (mqttClient.connect("Monitor")) {
|
||||||
mqttClient.subscribe(MESSAGE_TOPIC);
|
mqttClient.subscribe(MESSAGE_TOPIC);
|
||||||
mqttClient.subscribe(ALARM_TOPIC);
|
mqttClient.subscribe(ALARM_TOPIC);
|
||||||
|
mqttClient.subscribe(SECONDS_TOPIC);
|
||||||
disconnectTime = millis();
|
disconnectTime = millis();
|
||||||
mqttClient.publish("IoT/Monitor/Started", "monitor started");
|
mqttClient.publish("IoT/Monitor/Started", "monitor started");
|
||||||
disconnectState = 0;
|
disconnectState = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user