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.
Revision 5:c1952cbf8111, committed 2018-01-04
- Comitter:
- Ciesarik3
- Date:
- Thu Jan 04 23:04:53 2018 +0000
- Parent:
- 4:f2b6a3558671
- Child:
- 6:83b531eead03
- Commit message:
- habadury;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/definicie.h Thu Jan 04 23:04:53 2018 +0000
@@ -0,0 +1,69 @@
+//#ifndef DEFINICIE_H
+//#define DEFINICIE_H
+
+
+
+
+#define DISPLAY 0x30 // DATA smer 0x01-> UP 0x02-> DOWN , text (string)
+#define TERMINAL 0xD0 // Vypise vsetko
+
+#define VYTAH_BUTTON_P 0xb0 // ┌-----------┐
+#define VYTAH_BUTTON_1 0xb1 // | DATA 0xFF |
+#define VYTAH_BUTTON_2 0xb2 // |-----------|
+#define VYTAH_BUTTON_3 0xb3 // |-----------|
+#define VYTAH_BUTTON_4 0xb4 // |-----------|
+
+#define POSCHODIE_BUTTON_P 0xc0 // |-----------|
+#define POSCHODIE_BUTTON_1 0xc1 // |-----------|
+#define POSCHODIE_BUTTON_2 0xc2 // |-----------|
+#define POSCHODIE_BUTTON_3 0xc3 // |-----------|
+#define POSCHODIE_BUTTON_4 0xc4 // └-----------┘
+
+#define VYTAH_DIODA_P 0x20 // ┌--------------------------┐
+#define VYTAH_DIODA_1 0x21 // | DATA 0x00-> OFF 0x01->ON |
+#define VYTAH_DIODA_2 0x22 // |--------------------------|
+#define VYTAH_DIODA_3 0x23 // |--------------------------|
+#define VYTAH_DIODA_4 0x24 // |--------------------------|
+
+#define POSCHODIE_DIODA_P 0x10 // |--------------------------|
+#define POSCHODIE_DIODA_1 0x11 // |--------------------------|
+#define POSCHODIE_DIODA_2 0x12 // |--------------------------|
+#define POSCHODIE_DIODA_3 0x13 // |--------------------------|
+#define POSCHODIE_DIODA_4 0x14 // └--------------------------┘
+
+#define VYTAH 0xf0 // DATA 0x00-> UNLOCK 0x01-> LOCK
+#define BRZDA 0xf // DATA 0x00-> DEACTIVATE 0x01-> ACTIVATE
+
+#define FLOOR_LIMIT_SWITCH_P 0xe0 // ┌------------------------------------------┐
+#define FLOOR_LIMIT_SWITCH_1 0xe1 // | DATA 0x00-> LOW 0x01->WIDE 0x02-> NARROW |
+#define FLOOR_LIMIT_SWITCH_2 0xe2 // |------------------------------------------|
+#define FLOOR_LIMIT_SWITCH_3 0xe3 // |------------------------------------------|
+#define FLOOR_LIMIT_SWITCH_4 0xe4 // └------------------------------------------┘
+
+#define MOTOR 0xf1 // DATA 0x1-> STOP 0x02-> UP/DOWN 32bit <-100,100> 0x3-> MOTOR ENCODER COUNT (double)
+#define WATCHDOG 0xfe // DATA 0x01-> time out ELSE regular reset ( 1500ms )
+
+
+//char crc=0x00;
+const unsigned char crc8table[256] = {
+ 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
+ 157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
+ 35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
+ 190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
+ 70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
+ 219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
+ 101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
+ 248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
+ 140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205,
+ 17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80,
+ 175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238,
+ 50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
+ 202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
+ 87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
+ 233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
+ 116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53
+};
+
+
+
+//#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/headre.cpp Thu Jan 04 23:04:53 2018 +0000
@@ -0,0 +1,101 @@
+/*#include "mbed.h"
+#include "headre.h"
+#include "definicie.h"
+
+char crc=0x00;
+//Serial pc(USBTX, USBRX, 57600);
+int i;
+
+char prijemSpravy[30];
+
+
+void prijmemSpravu()
+{
+ //pc.attach(&prijmemSpravu);
+ for (int j=0;j<4;j++)
+ {
+ while(true)
+ {
+ if(pc.readable()==1)
+ {
+ prijemSpravy[j]=pc.getc();
+ break;
+ }
+ }
+ }
+
+ int pom= prijemSpravy[3] + 1;
+
+ for (int j=0;j<pom;j++)
+ {
+ while(true)
+ {
+ if(pc.readable()==1)
+ {
+ prijemSpravy[j+4]=pc.getc();
+ break;
+ }
+ }
+ }
+ pc.attach(&prijmemSpravu);
+}
+
+
+void poslemSpravu(char adrRX, char adrTX, int velkost, char DATA[] )
+{
+ crc=0x00;
+ char odosli[5+velkost];
+ odosli[0]=0xA0;
+ odosli[1]=adrRX;
+ odosli[2]=adrTX;
+ odosli[3]=velkost;
+
+ crc=crc8table[crc^adrRX];
+ crc=crc8table[crc^adrTX];
+
+ for (i=0; i<velkost; i++) {
+ odosli[4+i]=DATA[i];
+ }
+
+ for (i=0; i<velkost; i++) {
+ crc=crc8table[crc^DATA[i]];
+ }
+
+ odosli[velkost+4]=crc;
+
+ for (i=0; i<velkost+5; i++) {
+ pc.putc(odosli[i]);
+ }
+
+}
+
+
+void zamkni()
+{
+ char DATA[]= {0x01};
+ poslemSpravu(VYTAH,0xcc,sizeof(DATA),DATA);
+}
+
+void odomkni()
+{
+ char DATA[]= {0x00};
+ poslemSpravu(VYTAH,0xcc,sizeof(DATA),DATA);
+}
+
+void stop()
+{
+ char DATA[]= {0x01};
+ poslemSpravu(MOTOR,0xcc,sizeof(DATA),DATA);
+}
+
+void hore()
+{
+ char DATA[]= {0x02,0x64,0x00,0x00,0x00};
+ poslemSpravu(MOTOR,0xcc,sizeof(DATA),DATA);
+}
+
+void dole()
+{
+ char DATA[]= {0x02,0x9c,0xff,0xff,0xff};
+ poslemSpravu(MOTOR,0xcc,sizeof(DATA),DATA);
+}*/
\ No newline at end of file
--- a/headre.h Tue Dec 12 20:55:43 2017 +0000 +++ b/headre.h Thu Jan 04 23:04:53 2018 +0000 @@ -1,7 +1,10 @@ -#ifndef HEADRE_H -#define HEADRE_H +//#ifndef HEADRE_H +//#define HEADRE_H +//#include "definicie.h" +//Serial pc(USBTX, USBRX, 57600); + void poslemSpravu(char adrRX, char adrTX, int velkost, char DATA[] ); void prijmemSpravu(); @@ -15,7 +18,10 @@ void hore(); void dole(); -void kontrola(); +//void kontrola(); + +void zarad(int co); +//void obsluz(int cislo); -#endif \ No newline at end of file +//#endif \ No newline at end of file
--- a/main.cpp Tue Dec 12 20:55:43 2017 +0000
+++ b/main.cpp Thu Jan 04 23:04:53 2018 +0000
@@ -1,6 +1,10 @@
#include "mbed.h"
#include "headre.h"
+#include "definicie.h"
+
+
+/*
#define DISPLAY 0x30 // DATA smer 0x01-> UP 0x02-> DOWN , text (string)
#define TERMINAL 0xD0 // Vypise vsetko
@@ -40,11 +44,12 @@
#define MOTOR 0xf1 // DATA 0x1-> STOP 0x02-> UP/DOWN 32bit <-100,100> 0x3-> MOTOR ENCODER COUNT (double)
#define WATCHDOG 0xfe // DATA 0x01-> time out ELSE regular reset ( 1500ms )
+*/
Serial pc(USBTX, USBRX, 57600);
int i;
unsigned int velkost;
-char crc=0x00;
+char crc=0x00;/*
char crc8table[256] = {
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
@@ -62,7 +67,7 @@
87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53
-};
+};*/
// crc [0xA0, prijem, odosielatel, vrlkost dat , data (256),crc]
//char odosli[5+sizeof(DATA)];
@@ -74,7 +79,10 @@
char diode_DATA[]={0x00,0x01};
int diode_cislo[]={0,0,0,0,0};
int stav=5;
-//int poradie[]={0,0,0,0,0};
+
+int poradie[]={0,0,0,0,0};
+int zar=0;
+int por=0;
int main()
@@ -99,11 +107,28 @@
hore();*/
}
}
-/*
-void pohyb()
+
+void zarad(int co)
{
+ if (zar<5)
+ {
+ poradie[zar]=co;
+ zar++;
+ }
+ else
+ {
+ poradie[0]=co;
+ zar=1;
+ }
+}
+void pohyb( )
+{
+ zamkni();
+ if (stav < poradie[por]) hore();
+ if (stav > poradie[por]) dole();
+ /*
switch(stav)
{
case 5: dole(); break;
@@ -116,8 +141,9 @@
case 0: break;
default: break;
}
+ */
}
-*/
+
void zamkni()
{
@@ -179,18 +205,27 @@
}
pc.attach(&prijmemSpravu);
}
+/*
+void obsluz(int cislo)
+{
+ poslemSpravu(VYTAH_DIODA_4,0xCC,0x01, &diode_DATA[1]);
+ diode_cislo[4]=1;
+ zamkni();
+
+}
+*/
void rozhodni()
{
switch(prijemSpravy[2])
{
case 0xb4: /* vytah tla4idlo 4 poschodie */
- poslemSpravu(VYTAH_DIODA_4,0xCC,0x01, &diode_DATA[1]);
- diode_cislo[4]=1;
- zamkni();
- if (stav <4) hore();
- if (stav >4) dole();
- //dole();
+ if (diode_cislo[4]==0) { zarad(4);}
+ poslemSpravu(VYTAH_DIODA_4,0xCC,0x01, &diode_DATA[1]);
+ diode_cislo[4]=1;
+
+
+
break;
@@ -271,12 +306,17 @@
case 0xe4: /* info pre odomknutie 4 poschodie */
+
+ if(poradie[zar]==4) {
+
if(prijemSpravy[4]==0x01&&diode_cislo[4]==1){stop();
poslemSpravu(VYTAH_DIODA_4,0xCC,0x01, &diode_DATA[0]);
poslemSpravu(POSCHODIE_DIODA_4,0xCC,0x01, &diode_DATA[0]);
diode_cislo[4]=0;
stav=4;}
if(prijemSpravy[4]==0x02&&stav==4){wait(1);odomkni();}
+ }
+
break;
case 0xe3: /* info pre odomknutie 3 poschodie */
