RPLIDAR A1M8 LCD

Dependencies:   TS_DISCO_F746NG mbed BufferedSerial LCD_DISCO_F746NG mbed-rtos Trigo BSP_DISCO_F746NG

Committer:
Carminio
Date:
Thu Nov 24 11:50:42 2016 +0000
Revision:
4:0df95765b1b0
Parent:
3:43ab856b5efa
Child:
5:734551a9f4e7
Ver. con thread che gestisce lo stop del lidar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Carminio 0:88706d6abbf7 1 #include "mbed.h"
Carminio 4:0df95765b1b0 2 #include "rtos.h"
Carminio 0:88706d6abbf7 3 #include "Serial.h"
Carminio 0:88706d6abbf7 4 #include "BufferedSerial.h"
Carminio 0:88706d6abbf7 5 #include "Communication.h"
Carminio 0:88706d6abbf7 6 #include "Motor.h"
Carminio 0:88706d6abbf7 7 #include <stdlib.h>
Carminio 0:88706d6abbf7 8 #include <stdio.h>
Carminio 0:88706d6abbf7 9 #include "LCD_DISCO_F746NG.h"
Carminio 1:1ff3fe3679c1 10 #include "TS_DISCO_F746NG.h"
Carminio 0:88706d6abbf7 11
Carminio 3:43ab856b5efa 12
Carminio 0:88706d6abbf7 13 //Dichiarazione oggetti
Carminio 4:0df95765b1b0 14 DigitalIn myStopButton(USER_BUTTON);
Carminio 0:88706d6abbf7 15 Motor lid_Motor(PWM_OUT);
Carminio 0:88706d6abbf7 16 Communication SendCommands;
Carminio 1:1ff3fe3679c1 17 LCD_DISCO_F746NG lcd;
Carminio 1:1ff3fe3679c1 18 TS_DISCO_F746NG ts;
Carminio 1:1ff3fe3679c1 19
Carminio 1:1ff3fe3679c1 20 //Dichiarazione variabili
Carminio 1:1ff3fe3679c1 21 uint16_t x, y;
Carminio 1:1ff3fe3679c1 22 uint8_t idx;
Carminio 2:8f71c97fe9d7 23 uint8_t start=1;
Carminio 0:88706d6abbf7 24
Carminio 4:0df95765b1b0 25 void button_thread(void const *args) {
Carminio 4:0df95765b1b0 26 while(true) {
Carminio 4:0df95765b1b0 27 if (myStopButton == 1) {
Carminio 4:0df95765b1b0 28 SendCommands.Stop();
Carminio 4:0df95765b1b0 29 wait_ms(10);
Carminio 4:0df95765b1b0 30 lid_Motor.StopMotor_Scan();
Carminio 4:0df95765b1b0 31 wait_ms(10);
Carminio 4:0df95765b1b0 32 SendCommands.Reset();
Carminio 4:0df95765b1b0 33 }
Carminio 4:0df95765b1b0 34 }
Carminio 3:43ab856b5efa 35 }
Carminio 3:43ab856b5efa 36
Carminio 3:43ab856b5efa 37
Carminio 0:88706d6abbf7 38 int main() {
Carminio 4:0df95765b1b0 39 // Threads start here
Carminio 4:0df95765b1b0 40 Thread button_th(button_thread);
Carminio 4:0df95765b1b0 41
Carminio 0:88706d6abbf7 42 // Initialize Display
Carminio 0:88706d6abbf7 43 lcd.Clear(LCD_COLOR_BLACK);
Carminio 0:88706d6abbf7 44 lcd.SetBackColor(LCD_COLOR_BLACK);
Carminio 0:88706d6abbf7 45 lcd.SetTextColor(LCD_COLOR_GREEN);
Carminio 0:88706d6abbf7 46 wait(0.3);
Carminio 0:88706d6abbf7 47 lcd.SetFont(&Font24);
Carminio 0:88706d6abbf7 48 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"SLAMTEC LIDAR A2", CENTER_MODE);
Carminio 2:8f71c97fe9d7 49 lcd.SetFont(&Font8);
Carminio 2:8f71c97fe9d7 50 lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"STMicroelectronics", RIGHT_MODE);
Carminio 2:8f71c97fe9d7 51 lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"D. Ruggiero 2016", RIGHT_MODE);
Carminio 2:8f71c97fe9d7 52
Carminio 1:1ff3fe3679c1 53 // Configure buttons and TFT display
Carminio 1:1ff3fe3679c1 54 TS_StateTypeDef TS_State;
Carminio 1:1ff3fe3679c1 55 lcd.SetTextColor(LCD_COLOR_GREEN);
Carminio 2:8f71c97fe9d7 56 lcd.FillRect(136, 200, 200, 50); ///Disegna bottone Verde
Carminio 2:8f71c97fe9d7 57
Carminio 2:8f71c97fe9d7 58 lcd.SetFont(&Font24);
Carminio 1:1ff3fe3679c1 59 lcd.SetBackColor(LCD_COLOR_GREEN);
Carminio 1:1ff3fe3679c1 60 lcd.SetTextColor(LCD_COLOR_BLACK);
Carminio 2:8f71c97fe9d7 61 lcd.DisplayStringAt(202, LINE(9), (uint8_t *)"SCAN", LEFT_MODE);
Carminio 2:8f71c97fe9d7 62
Carminio 2:8f71c97fe9d7 63 while(start) {
Carminio 1:1ff3fe3679c1 64
Carminio 1:1ff3fe3679c1 65 // Initialize TFT display
Carminio 1:1ff3fe3679c1 66 ts.GetState(&TS_State);
Carminio 1:1ff3fe3679c1 67 if (TS_State.touchDetected) {
Carminio 1:1ff3fe3679c1 68 for (idx = 0; idx < TS_State.touchDetected; idx++) {
Carminio 1:1ff3fe3679c1 69 x = TS_State.touchX[idx];
Carminio 1:1ff3fe3679c1 70 y = TS_State.touchY[idx];
Carminio 1:1ff3fe3679c1 71 }
Carminio 2:8f71c97fe9d7 72
Carminio 2:8f71c97fe9d7 73 if((x>=136) && (x<=336) && (y>=200) && (y<=250)) {
Carminio 2:8f71c97fe9d7 74 lcd.Clear(LCD_COLOR_BLACK);
Carminio 0:88706d6abbf7 75
Carminio 0:88706d6abbf7 76 // Initialize UART
Carminio 0:88706d6abbf7 77 SendCommands.confUART();
Carminio 0:88706d6abbf7 78
Carminio 0:88706d6abbf7 79 // Perform a device reset
Carminio 0:88706d6abbf7 80 // SendCommands.Reset();
Carminio 0:88706d6abbf7 81
Carminio 0:88706d6abbf7 82 // Send Get_Health command
Carminio 0:88706d6abbf7 83 // SendCommands.Get_Health();
Carminio 0:88706d6abbf7 84
Carminio 0:88706d6abbf7 85 // Send Get_Info command
Carminio 0:88706d6abbf7 86 // SendCommands.Get_Info();
Carminio 0:88706d6abbf7 87
Carminio 0:88706d6abbf7 88 // Start motor (PWM: Frequency 25KHz, Duty cycle 60%)
Carminio 0:88706d6abbf7 89 lid_Motor.StartMotor_Scan();
Carminio 3:43ab856b5efa 90
Carminio 0:88706d6abbf7 91 // Start scan
Carminio 0:88706d6abbf7 92 SendCommands.Scan();
Carminio 2:8f71c97fe9d7 93 start=0;
Carminio 2:8f71c97fe9d7 94 }
Carminio 1:1ff3fe3679c1 95 }
Carminio 0:88706d6abbf7 96 }
Carminio 4:0df95765b1b0 97
Carminio 0:88706d6abbf7 98 }
Carminio 3:43ab856b5efa 99
Carminio 3:43ab856b5efa 100