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: czosnekengine_17_06 Servo_fullrange mbed
Fork of CZOSN_ostateczny_29_06 by
Diff: main.cpp
- Revision:
- 2:325a730cd438
- Parent:
- 1:da4c204737bf
- Child:
- 3:d78e7f6477d8
--- a/main.cpp Tue Jun 14 13:32:33 2016 +0000
+++ b/main.cpp Wed Jun 15 12:33:51 2016 +0000
@@ -35,7 +35,7 @@
//*******************KONIEC OPISU******************************************************************//
bool isCorrectPacket(char *buffor){
- if ((bufor[0]!='@') && (bufor[0]!='&'))
+ if (bufor[0]!='@')
{
// stm.printf("ZLY ZNAK POCZATKU\n");
stm.printf("blad\n");
@@ -53,7 +53,7 @@
stm.printf("blad\n");
return false;
}
- if(bufor[9]!='$')
+ if((bufor[9]!='$')&&(bufor[9]!='&'))
{
// stm.printf("ZLY ZNAK KONCA\n");
stm.printf("blad\n");
@@ -107,8 +107,6 @@
//**********ODPALANIE SILNIKOW******//
eng_left.move(l);
eng_right.move(p);
-
- stm.printf(bufor);
}
void move_camera()
{
@@ -140,29 +138,7 @@
cam_poziom.position(po);
cam_pion.position(pi);
}
-void fill_buffer(int i)
-{
- bufor[i] = stm.getc();
- if(i==0){
- if((bufor[i]=='@') || (bufor[i]=='&')) //zaczynamy zapelniac bufor jak dostaniemy @
- ++i;
- }
- else if(bufor[i]=='@'){ // i != 0 //interpretujemy jakby potencjalny poczatek ramki
- cleanBuffer(bufor);
- //stm.printf("blad\n");
- bufor[0]='@';
- i=1; //bo zerowy znak '@' juz zczytal
- }
- else if (bufor[i]=='&'){ // i != 0 //interpretujemy jakby potencjalny poczatek ramki
- cleanBuffer(bufor);
- //stm.printf("blad\n");
- bufor[0]='&';
- i=1; //bo zerowy znak '@' juz zczytal
- }
- else
- i++;
-}
-
+
int main(){
int i = 0;
cleanBuffer(bufor);
@@ -172,19 +148,29 @@
eng_left.move(0);
eng_right.move(0);
}
- //if((bufor[9] == NULL)&&(stm.readable()))
- while (bufor[9] == NULL){
- fill_buffer(i);
- }
+ if(bufor[9] == NULL){
+ bufor[i] = stm.getc();
+ if(i==0){
+ if(bufor[i]=='@') //zaczynamy zapelniac bufor jak dostaniemy @
+ ++i;
+ }
+ else if(bufor[i]=='@'){ // i != 0 //interpretujemy jakby potencjalny poczatek ramki
+ cleanBuffer(bufor);
+ bufor[0]='@';
+ i=1; //bo zerowy znak '@' juz zczytal
+ }
+ else i++;
+ continue;
+ }
if(isCorrectPacket(bufor)){
t.stop();
t.reset();
t.start();
}
- if(bufor[0]=='@'){
+ if(bufor[9]=='$'){
move_wheels();
}
- else if(bufor[0]=='&'){
+ else if(bufor[9]=='&'){
move_camera();
}
i=0;
