RPLIDAR A1M8 LCD

Dependencies:   TS_DISCO_F746NG mbed BufferedSerial LCD_DISCO_F746NG mbed-rtos Trigo BSP_DISCO_F746NG

Committer:
KheirddineZ
Date:
Tue Jun 22 13:22:01 2021 +0000
Revision:
8:7788cc96e8ad
Parent:
6:b6efac82e5f9
RPLIDAR A1M8

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"
KheirddineZ 8:7788cc96e8ad 11 #include "Capture.h"
Carminio 3:43ab856b5efa 12
Carminio 6:b6efac82e5f9 13 DigitalIn myStopButton(USER_BUTTON);
Carminio 0:88706d6abbf7 14 Motor lid_Motor(PWM_OUT);
Carminio 0:88706d6abbf7 15 Communication SendCommands;
Carminio 1:1ff3fe3679c1 16 LCD_DISCO_F746NG lcd;
Carminio 1:1ff3fe3679c1 17 TS_DISCO_F746NG ts;
Carminio 5:734551a9f4e7 18 LCD_DISCO_F746NG lcd_Thread;
Carminio 1:1ff3fe3679c1 19
KheirddineZ 8:7788cc96e8ad 20
Carminio 5:734551a9f4e7 21 TS_StateTypeDef TS_State;
Carminio 5:734551a9f4e7 22
Carminio 6:b6efac82e5f9 23 uint16_t x,y;
Carminio 1:1ff3fe3679c1 24 uint8_t idx;
Carminio 2:8f71c97fe9d7 25 uint8_t start=1;
Carminio 0:88706d6abbf7 26
KheirddineZ 8:7788cc96e8ad 27
KheirddineZ 8:7788cc96e8ad 28 void Fond(int offsetX, int offsetY)
KheirddineZ 8:7788cc96e8ad 29 {
KheirddineZ 8:7788cc96e8ad 30 int x = 0;
KheirddineZ 8:7788cc96e8ad 31 int y = 0;
KheirddineZ 8:7788cc96e8ad 32 uint32_t* dataPtr = (uint32_t*)Capture.data;
KheirddineZ 8:7788cc96e8ad 33 while(y < Capture.height) {
KheirddineZ 8:7788cc96e8ad 34 while(x < Capture.width) {
KheirddineZ 8:7788cc96e8ad 35 BSP_LCD_DrawPixel(x + offsetX, y + offsetY, *dataPtr);
KheirddineZ 8:7788cc96e8ad 36 dataPtr++;
KheirddineZ 8:7788cc96e8ad 37 x++;
KheirddineZ 8:7788cc96e8ad 38 }
KheirddineZ 8:7788cc96e8ad 39 x = 0;
KheirddineZ 8:7788cc96e8ad 40 y++;
KheirddineZ 8:7788cc96e8ad 41 }
KheirddineZ 8:7788cc96e8ad 42 }
KheirddineZ 8:7788cc96e8ad 43
KheirddineZ 8:7788cc96e8ad 44 void StopLidar_thread(void const *args) {
Carminio 5:734551a9f4e7 45 wait(1);
Carminio 4:0df95765b1b0 46 while(true) {
Carminio 6:b6efac82e5f9 47 if (myStopButton==1) {
Carminio 4:0df95765b1b0 48 SendCommands.Stop();
Carminio 4:0df95765b1b0 49 wait_ms(10);
Carminio 4:0df95765b1b0 50 lid_Motor.StopMotor_Scan();
Carminio 4:0df95765b1b0 51 wait_ms(10);
Carminio 4:0df95765b1b0 52 SendCommands.Reset();
Carminio 5:734551a9f4e7 53 wait_ms(10);
Carminio 5:734551a9f4e7 54 lcd_Thread.DisplayOff();
Carminio 4:0df95765b1b0 55 }
Carminio 4:0df95765b1b0 56 }
Carminio 3:43ab856b5efa 57 }
Carminio 3:43ab856b5efa 58
Carminio 3:43ab856b5efa 59
Carminio 0:88706d6abbf7 60 int main() {
KheirddineZ 8:7788cc96e8ad 61
KheirddineZ 8:7788cc96e8ad 62 Thread StopLidar__th(StopLidar_thread); // THREAD
Carminio 4:0df95765b1b0 63
KheirddineZ 8:7788cc96e8ad 64 /* PREMIERE INTERFACE
KheirddineZ 8:7788cc96e8ad 65
Carminio 0:88706d6abbf7 66 lcd.Clear(LCD_COLOR_BLACK);
Carminio 0:88706d6abbf7 67 lcd.SetBackColor(LCD_COLOR_BLACK);
Carminio 0:88706d6abbf7 68 lcd.SetTextColor(LCD_COLOR_GREEN);
Carminio 0:88706d6abbf7 69 wait(0.3);
Carminio 0:88706d6abbf7 70 lcd.SetFont(&Font24);
KheirddineZ 8:7788cc96e8ad 71 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"LIDAR ", CENTER_MODE);
Carminio 2:8f71c97fe9d7 72 lcd.SetFont(&Font8);
KheirddineZ 8:7788cc96e8ad 73 lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"K.ZAILLEL", RIGHT_MODE);
KheirddineZ 8:7788cc96e8ad 74
Carminio 2:8f71c97fe9d7 75
Carminio 1:1ff3fe3679c1 76 lcd.SetTextColor(LCD_COLOR_GREEN);
KheirddineZ 8:7788cc96e8ad 77 lcd.FillRect(136, 200, 200, 50);
Carminio 2:8f71c97fe9d7 78
Carminio 2:8f71c97fe9d7 79 lcd.SetFont(&Font24);
Carminio 1:1ff3fe3679c1 80 lcd.SetBackColor(LCD_COLOR_GREEN);
Carminio 1:1ff3fe3679c1 81 lcd.SetTextColor(LCD_COLOR_BLACK);
KheirddineZ 8:7788cc96e8ad 82 lcd.DisplayStringAt(202, LINE(9), (uint8_t *)"SCAN", LEFT_MODE);*/
KheirddineZ 8:7788cc96e8ad 83
Carminio 2:8f71c97fe9d7 84 while(start) {
KheirddineZ 8:7788cc96e8ad 85 Fond(0,0);
KheirddineZ 8:7788cc96e8ad 86 ts.GetState(&TS_State);
KheirddineZ 8:7788cc96e8ad 87 if (TS_State.touchDetected) {
Carminio 1:1ff3fe3679c1 88 for (idx = 0; idx < TS_State.touchDetected; idx++) {
Carminio 1:1ff3fe3679c1 89 x = TS_State.touchX[idx];
Carminio 1:1ff3fe3679c1 90 y = TS_State.touchY[idx];
Carminio 1:1ff3fe3679c1 91 }
Carminio 2:8f71c97fe9d7 92
KheirddineZ 8:7788cc96e8ad 93 if((x>=136) && (x<=336) && (y>=200) && (y<=250)) { // Bouton SCAN
KheirddineZ 8:7788cc96e8ad 94 lcd.Clear(LCD_COLOR_BLACK);
KheirddineZ 8:7788cc96e8ad 95 lcd.SetBackColor(LCD_COLOR_BLACK);
KheirddineZ 8:7788cc96e8ad 96 lcd.SetTextColor(LCD_COLOR_GREEN);
KheirddineZ 8:7788cc96e8ad 97 wait(0.3);
KheirddineZ 8:7788cc96e8ad 98 lcd.SetFont(&Font16);
KheirddineZ 8:7788cc96e8ad 99 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)"Scanning ... ", CENTER_MODE);
KheirddineZ 8:7788cc96e8ad 100
KheirddineZ 8:7788cc96e8ad 101
KheirddineZ 8:7788cc96e8ad 102
KheirddineZ 8:7788cc96e8ad 103 // Init UART
Carminio 0:88706d6abbf7 104 SendCommands.confUART();
Carminio 0:88706d6abbf7 105
KheirddineZ 8:7788cc96e8ad 106 // RESET
Carminio 0:88706d6abbf7 107 // SendCommands.Reset();
Carminio 0:88706d6abbf7 108
KheirddineZ 8:7788cc96e8ad 109 // Get_Health command
Carminio 0:88706d6abbf7 110 // SendCommands.Get_Health();
Carminio 0:88706d6abbf7 111
KheirddineZ 8:7788cc96e8ad 112 // Get_Info command
Carminio 0:88706d6abbf7 113 // SendCommands.Get_Info();
Carminio 0:88706d6abbf7 114
KheirddineZ 8:7788cc96e8ad 115 // Start motor
Carminio 0:88706d6abbf7 116 lid_Motor.StartMotor_Scan();
Carminio 3:43ab856b5efa 117
KheirddineZ 8:7788cc96e8ad 118 // Scan
Carminio 0:88706d6abbf7 119 SendCommands.Scan();
Carminio 2:8f71c97fe9d7 120 start=0;
Carminio 2:8f71c97fe9d7 121 }
Carminio 1:1ff3fe3679c1 122 }
Carminio 0:88706d6abbf7 123 }
Carminio 4:0df95765b1b0 124
Carminio 0:88706d6abbf7 125 }
Carminio 3:43ab856b5efa 126
Carminio 3:43ab856b5efa 127