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: BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG mbed
Diff: main.cpp
- Revision:
- 2:b05f40331fc3
- Parent:
- 1:b6e184239fba
- Child:
- 3:2d2c2f2044b4
--- a/main.cpp Sat Oct 31 23:35:40 2015 +0000
+++ b/main.cpp Sun Nov 01 00:36:00 2015 +0000
@@ -28,6 +28,20 @@
char ESP8266sendingCharsStr[] = "Sending chars... ";
char ESP8266sendingRequestStr[] = "Sending request... ";
+TS_StateTypeDef TS_State;
+uint8_t status;
+
+
+void checkDisplayLines() {
+ if(lineDisplay>7) {
+ for(int idx = 2; idx<8; idx++) {
+ lcd.ClearStringLine(idx);
+ };
+
+ lineDisplay = 2;
+ };
+};
+
bool ESP8266readResponse(char* delimiter, char* response) {
int i = 0, j = 0;
char c;
@@ -54,37 +68,49 @@
void ESP8266init(char* ssid, char* password) {
led1 = 0;
+ lineDisplay = 0;
pc.baud(115200);
serial6.baud(115200);
+ lcd.SetTextColor(LCD_COLOR_RED);
pc.printf("%s\r\n", ESP8266initStr);
lcd.DisplayStringAt(0, LINE(lineDisplay++), (uint8_t *)ESP8266initStr, CENTER_MODE);
lineDisplay++;
+ lcd.SetTextColor(LCD_COLOR_BLACK);
pc.printf("%s", ESP8266resetStr);
lcd.DisplayStringAt(0, LINE(lineDisplay), (uint8_t *)ESP8266resetStr, LEFT_MODE);
serial6.printf("AT+RST\r\n");
ESP8266readResponse(ESP8266responseOkStr, NULL);
ESP8266readResponse(ESP8266responseReadyStr, NULL);
+ lcd.SetTextColor(LCD_COLOR_GREEN);
pc.printf("%s\r\n", ESP8266doneStr);
lcd.DisplayStringAt(0, LINE(lineDisplay++), (uint8_t *)ESP8266doneStr, RIGHT_MODE);
+ lcd.SetTextColor(LCD_COLOR_BLACK);
pc.printf("%s", ESP8266clientModeStr);
lcd.DisplayStringAt(0, LINE(lineDisplay), (uint8_t *)ESP8266clientModeStr, LEFT_MODE);
serial6.printf("AT+CWMODE=1\r\n");
ESP8266readResponse(ESP8266responseOkStr, NULL);
+ lcd.SetTextColor(LCD_COLOR_GREEN);
pc.printf("%s\r\n", ESP8266doneStr);
lcd.DisplayStringAt(0, LINE(lineDisplay++), (uint8_t *)ESP8266doneStr, RIGHT_MODE);
+ lcd.SetTextColor(LCD_COLOR_BLACK);
pc.printf("%s", ESP8266wifiConnectionStr);
lcd.DisplayStringAt(0, LINE(lineDisplay), (uint8_t *)ESP8266wifiConnectionStr, LEFT_MODE);
serial6.printf("AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, password);
ESP8266readResponse(ESP8266responseOkStr, NULL);
+ lcd.SetTextColor(LCD_COLOR_GREEN);
pc.printf("%s\r\n", ESP8266doneStr);
lcd.DisplayStringAt(0, LINE(lineDisplay++), (uint8_t *)ESP8266doneStr, RIGHT_MODE);
+ lcd.SetTextColor(LCD_COLOR_BLACK);
led1 = 1;
+ lcd.SetTextColor(LCD_COLOR_BLUE); //request button
+ lcd.FillCircle(425, 230, 25);
+ lcd.SetTextColor(LCD_COLOR_BLACK); //reset button
};
void ESP8266get(char* domain, char* url, char* response) {
@@ -94,43 +120,78 @@
n2 = strlen(url);
pc.printf("%s", ESP8266serverConnectionStr);
+ checkDisplayLines();
lcd.DisplayStringAt(0, LINE(lineDisplay), (uint8_t *)ESP8266serverConnectionStr, LEFT_MODE);
serial6.printf("AT+CIPSTART=\"TCP\",\"%s\",80\r\n", domain);
ESP8266readResponse(ESP8266responseOkStr, NULL);
+ lcd.SetTextColor(LCD_COLOR_GREEN);
pc.printf("%s\r\n", ESP8266doneStr);
lcd.DisplayStringAt(0, LINE(lineDisplay++), (uint8_t *)ESP8266doneStr, RIGHT_MODE);
+ lcd.SetTextColor(LCD_COLOR_BLACK);
pc.printf("%s", ESP8266sendingCharsStr);
+ checkDisplayLines();
lcd.DisplayStringAt(0, LINE(lineDisplay), (uint8_t *)ESP8266sendingCharsStr, LEFT_MODE);
serial6.printf("AT+CIPSEND=%d\r\n", 11+n1+1+n2+13);
ESP8266readResponse(ESP8266responseGetStr, NULL);
+ lcd.SetTextColor(LCD_COLOR_GREEN);
pc.printf("%s\r\n", ESP8266doneStr);
lcd.DisplayStringAt(0, LINE(lineDisplay++), (uint8_t *)ESP8266doneStr, RIGHT_MODE);
+ lcd.SetTextColor(LCD_COLOR_BLACK);
pc.printf("%s", ESP8266sendingRequestStr);
+ checkDisplayLines();
lcd.DisplayStringAt(0, LINE(lineDisplay), (uint8_t *)ESP8266sendingRequestStr, LEFT_MODE);
serial6.printf("GET http://%s/%s HTTP/1.0\r\n\r\n", domain, url);
ESP8266readResponse(ESP8266responseSendStr, NULL);
ESP8266readResponse(ESP8266responseClosedStr, response);
+ lcd.SetTextColor(LCD_COLOR_GREEN);
pc.printf("%s\r\n", ESP8266doneStr);
lcd.DisplayStringAt(0, LINE(lineDisplay++), (uint8_t *)ESP8266doneStr, RIGHT_MODE);
+ lcd.SetTextColor(LCD_COLOR_BLACK);
};
-int main() {
+void LCDinit() {
lcd.Clear(LCD_COLOR_WHITE);
lcd.SetBackColor(LCD_COLOR_WHITE);
- lcd.SetTextColor(LCD_COLOR_BLACK);
- char response[ESP8266limitResponse];
- char domain[] = "gabrieledisimone.it";
- char url[] = "";
-
- ESP8266init("Telecom-47520601", "famigliaquino2000router10");
+ status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
- ESP8266get(domain, url, response);
-
- pc.printf("response:\r\n%s", response);
+ lcd.SetTextColor(LCD_COLOR_BLACK); //reset button
+ lcd.FillCircle(50, 230, 25);
+};
+
+void init() {
+ LCDinit();
+ ESP8266init("Telecom-47520601", "famigliaquino2000router10");
+};
+
+void TSdetect() {
while(1) {
- pc.putc(serial6.getc());
+ int idx, x, y;
+ ts.GetState(&TS_State); //TOUCH STATE
+
+ if (TS_State.touchDetected) { //TOUCH DETECTED
+ for (idx = 0; idx < TS_State.touchDetected; idx++) {
+ x = TS_State.touchX[idx];
+ y = TS_State.touchY[idx];
+
+ if ((x>400)&&(x<450)&&(y>205)&&(y<255)) {
+ char response[ESP8266limitResponse];
+ char domain[] = "gabrieledisimone.it";
+ char url[] = "";
+
+ ESP8266get(domain, url, response);
+ pc.printf("response:\r\n%s", response);
+ } else if ((x>25)&&(x<75)&&(y>205)&&(y<255)) {
+ init();
+ };
+ };
+ };
};
+};
+
+int main() {
+ init();
+ TSdetect();
};
\ No newline at end of file