
mbed2_5
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
Revision 0:edf190717f4f, committed 2020-05-24
- Comitter:
- wolve265
- Date:
- Sun May 24 18:45:14 2020 +0000
- Commit message:
- final
Changed in this revision
diff -r 000000000000 -r edf190717f4f BSP_DISCO_F429ZI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BSP_DISCO_F429ZI.lib Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/BSP_DISCO_F429ZI/#53d9067a4feb
diff -r 000000000000 -r edf190717f4f Command.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Command.cpp Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,39 @@ +#include "Command.h" +#include "mbed.h" +#include <cstring> + +void Command::Decode(){ + char *pcActualToken = strtok(cReceived, " "); + + if(0 == strcmp(pcActualToken, "id")){ + eName = ID; + strcpy(cReply, "id DISCO-F429ZI"); + } + else if(0 == strcmp(pcActualToken, "callib")){ + eName = CALLIB; + strcpy(cReply, "ok"); + } + else if(0 == strcmp(pcActualToken, "goto")){ + eName = GOTO; + strcpy(cReply, "ok"); + pcActualToken = strtok(NULL, " "); + HexStringToUInt(pcActualToken); + } + else if(0 == strcmp(pcActualToken, "step")){ + eName = STEP; + strcpy(cReply, "ok"); + pcActualToken = strtok(NULL, " "); + HexStringToUInt(pcActualToken); + } + else{ + eName = IDLE; + strcpy(cReply, "unknowncommand"); + } +} + +void Command::HexStringToUInt(char *pcHexString){ + unsigned long ulReceivedNumber; + ulReceivedNumber = strtoul(pcHexString, NULL, 0); + uiReceivedNumber = (unsigned int)ulReceivedNumber; +} +
diff -r 000000000000 -r edf190717f4f Command.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Command.h Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,23 @@ +#ifndef COMMAND_H +#define COMMAND_H + +enum CommandName{ + CALLIB, + ID, + GOTO, + STEP, + IDLE +}; + +class Command{ + private: + void HexStringToUInt(char *); + public: + char cReceived[255]; + char cReply[255]; + unsigned int uiReceivedNumber; + void Decode(); + enum CommandName eName; +}; + +#endif
diff -r 000000000000 -r edf190717f4f LCD_DISCO_F429ZI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD_DISCO_F429ZI.lib Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/ST/code/LCD_DISCO_F429ZI/#dc55a068bc1a
diff -r 000000000000 -r edf190717f4f Led.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Led.cpp Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,81 @@ +#include "Led.h" + +Led::Led(){ + lcd.Clear(LCD_COLOR_WHITE); + + ucLineXpos = 220; + ucLineYpos = 120; + DrawServo(); + + ucCurrentIndex = 0; + for(unsigned char ucLedCounter = 0; ucLedCounter < 4; ucLedCounter++){ + lcd.SetTextColor(LCD_COLOR_BLACK); + lcd.FillCircle(30+(60*ucLedCounter), 280, 23); + On(0); + } +} + +void Led::DrawServo(){ + lcd.SetTextColor(LCD_COLOR_BLACK); + lcd.FillCircle(120, 120, 100); + lcd.SetTextColor(LCD_COLOR_WHITE); + lcd.FillCircle(120, 120, 20); + lcd.DrawLine(120, 120, ucLineXpos, ucLineYpos); +} + +void Led::StepRight(){ + ucCurrentIndex = (ucCurrentIndex+1)%4; + On(ucCurrentIndex); + if(20 == ucLineXpos && ucLineYpos > 20){ + ucLineYpos-=10; + } + else if(220 == ucLineXpos && ucLineYpos < 220){ + ucLineYpos+=10; + } + else if(20 == ucLineYpos && ucLineXpos < 220){ + ucLineXpos+=10; + } + else if(220 == ucLineYpos && ucLineXpos > 20){ + ucLineXpos-=10; + } + else{} + DrawServo(); + wait(0.05); +} + +void Led::StepLeft(){ + if(0 == ucCurrentIndex){ + ucCurrentIndex = 3; + } + else{ + ucCurrentIndex = (ucCurrentIndex-1)%4; + } + On(ucCurrentIndex); + if(20 == ucLineXpos && ucLineYpos < 220){ + ucLineYpos+=10; + } + else if(220 == ucLineXpos && ucLineYpos > 20){ + ucLineYpos-=10; + } + else if(20 == ucLineYpos && ucLineXpos > 20){ + ucLineXpos-=10; + } + else if(220 == ucLineYpos && ucLineXpos < 220){ + ucLineXpos+=10; + } + else{} + DrawServo(); + wait(0.05); +} + +void Led::On(unsigned char ucIndex){ + for(unsigned char ucLedCounter = 0; ucLedCounter < 4; ucLedCounter++){ + if(ucIndex == ucLedCounter){ + lcd.SetTextColor(LCD_COLOR_CYAN); + } + else{ + lcd.SetTextColor(LCD_COLOR_WHITE); + } + lcd.FillCircle(30+(60*ucLedCounter), 280, 20); + } +} \ No newline at end of file
diff -r 000000000000 -r edf190717f4f Led.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Led.h Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,20 @@ +#ifndef LED_H +#define LED_H + +#include "LCD_DISCO_F429ZI.h" + +class Led{ + private: + LCD_DISCO_F429ZI lcd; + void On(unsigned char); + void DrawServo(); + unsigned char ucLineXpos; + unsigned char ucLineYpos; + unsigned char ucCurrentIndex; + public: + Led(); + void StepRight(); + void StepLeft(); +}; + +#endif \ No newline at end of file
diff -r 000000000000 -r edf190717f4f Servo.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.cpp Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,52 @@ +#include "Servo.h" +#include "mbed.h" + +InterruptIn user_button(USER_BUTTON); + +Servo::Servo(){ + uiCurrentPosition = 0; +} + +void Servo::Callib(){ + while(!user_button){ + MyLed.StepRight(); + } + uiCurrentPosition = 0; +} + +void Servo::GoTo(unsigned int uiDesiredPosition){ + while(uiDesiredPosition != uiCurrentPosition){ + if(uiDesiredPosition > uiCurrentPosition){ + MyLed.StepRight(); + uiCurrentPosition++; + } + else if(uiDesiredPosition < uiCurrentPosition){ + MyLed.StepLeft(); + uiCurrentPosition--; + } + else{} + } +} + +void Servo::Step(unsigned int uiSteps){ + for(unsigned int uiStepCounter; uiStepCounter < uiSteps; uiStepCounter++){ + MyLed.StepRight(); + uiCurrentPosition++; + } +} + +void Servo::Do(){ + switch(MyCommand.eName){ + case CALLIB: + Callib(); + break; + case GOTO: + GoTo(MyCommand.uiReceivedNumber); + break; + case STEP: + Step(MyCommand.uiReceivedNumber); + break; + default: + break; + } +} \ No newline at end of file
diff -r 000000000000 -r edf190717f4f Servo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.h Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,19 @@ +#ifndef SERVO_H +#define SERVO_H + +#include "Command.h" +#include "Led.h" + +class Servo{ + private: + Led MyLed; + void Callib(); + void GoTo(unsigned int); + void Step(unsigned int); + unsigned int uiCurrentPosition; + public: + Servo(); + Command MyCommand; + void Do(); +}; +#endif \ No newline at end of file
diff -r 000000000000 -r edf190717f4f Uart.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Uart.cpp Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,42 @@ +#include "Uart.h" +#include "mbed.h" +Serial uart(USBTX, USBRX); // tx, rx + +void Uart::print(char *pcString){ + uart.printf(pcString); +} + +bool Uart::puts(char *pTransmitWord, unsigned char ucWordSize){ + if(NULL != pTransmitWord[ucWordSize]){ + return 1; + } + else{ + unsigned char ucCharacterCounter; + for(ucCharacterCounter = 0; ucCharacterCounter < ucWordSize; ucCharacterCounter++){ + uart.putc(pTransmitWord[ucCharacterCounter]); + } + uart.putc(13); + return 0; + } +} + +bool Uart::gets(char *pReceivedWord, unsigned char ucWordSize){ + unsigned char ucCharacterCounter; + + for(ucCharacterCounter = 0; ucCharacterCounter <= ucWordSize; ucCharacterCounter++){ + unsigned char ucCurrentChar = uart.getc(); + if(ucCharacterCounter > ucWordSize){ + return 1; + } + else{ + if(13 == ucCurrentChar){ + pReceivedWord[ucCharacterCounter] = NULL; + return 0; + } + else{ + pReceivedWord[ucCharacterCounter] = ucCurrentChar; + } + } + } + return 0; +} \ No newline at end of file
diff -r 000000000000 -r edf190717f4f Uart.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Uart.h Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,13 @@ +#ifndef UART_H +#define UART_H + +class Uart{ + private: + + public: + bool puts(char *, unsigned char); + bool gets(char *, unsigned char); + void print(char *); +}; + +#endif \ No newline at end of file
diff -r 000000000000 -r edf190717f4f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,20 @@ +#include "Uart.h" +#include "Servo.h" +#include <cstring> + +int main(){ + Uart MyUart; + Servo MyServo; + + while(1){ + unsigned char ucWordSize = 255; + MyUart.gets(MyServo.MyCommand.cReceived, ucWordSize); + + MyServo.MyCommand.Decode(); + + ucWordSize = strlen(MyServo.MyCommand.cReply); + MyUart.puts(MyServo.MyCommand.cReply, ucWordSize); + + MyServo.Do(); + } +} \ No newline at end of file
diff -r 000000000000 -r edf190717f4f mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun May 24 18:45:14 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file