![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Seminar iz kolegija Mikroupravljaci
Dependencies: mbed Akvizicija
565656klkl
main.cpp@0:5b31abb1ab50, 2019-11-17 (annotated)
- Committer:
- jkordek
- Date:
- Sun Nov 17 07:48:15 2019 +0000
- Revision:
- 0:5b31abb1ab50
Inkubator - seminar iz kolegija Mikroupravljaci
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jkordek | 0:5b31abb1ab50 | 1 | #include "mbed.h" |
jkordek | 0:5b31abb1ab50 | 2 | #include "Akvizicija.h" // simulacija vrijednosti temperature i vlage - očitavanje vrijednosti s potenciometra |
jkordek | 0:5b31abb1ab50 | 3 | |
jkordek | 0:5b31abb1ab50 | 4 | #define debug true //flag za debug |
jkordek | 0:5b31abb1ab50 | 5 | |
jkordek | 0:5b31abb1ab50 | 6 | Akvizicija pot(p19,p20); //stvaranje objekta pot, p19 - pin potenciometra koji simulira temperaturu, p20 - pin potenciometra koji simulira vlagu |
jkordek | 0:5b31abb1ab50 | 7 | |
jkordek | 0:5b31abb1ab50 | 8 | Serial nextion(p13, p14); // tx, rx pinovi za Nextion zaslon |
jkordek | 0:5b31abb1ab50 | 9 | Serial pc(USBTX, USBRX, 115200); //PC monitor |
jkordek | 0:5b31abb1ab50 | 10 | LocalFileSystem local("local"); // Stvaranje objekta localfilesystem-a pod nazivom "local" |
jkordek | 0:5b31abb1ab50 | 11 | |
jkordek | 0:5b31abb1ab50 | 12 | Ticker akvizicija; //ticker za dohvaćanje vrijednosti temperature i vlage |
jkordek | 0:5b31abb1ab50 | 13 | Ticker NextionIspis; //ticker za slanje podataka s lpc-a na zaslon |
jkordek | 0:5b31abb1ab50 | 14 | |
jkordek | 0:5b31abb1ab50 | 15 | PwmOut vent(p21); //stvaranje pwm objekta pod nazivom "vent" |
jkordek | 0:5b31abb1ab50 | 16 | |
jkordek | 0:5b31abb1ab50 | 17 | char buffer[40]; //veličina buffera za primanje znakova sa nextion zaslona (dovoljno je 40 znakova) |
jkordek | 0:5b31abb1ab50 | 18 | int znak = 0; // redni broj znaka u polju znakova (stringu) |
jkordek | 0:5b31abb1ab50 | 19 | char read_string[128]; // veličina buffera za čitanje podataka iz datoteke (dovoljno je 128 znakova) |
jkordek | 0:5b31abb1ab50 | 20 | |
jkordek | 0:5b31abb1ab50 | 21 | //globalne varijable za spremanje trenutnih vrijednosti |
jkordek | 0:5b31abb1ab50 | 22 | //postavljene su u 0 ali se prilikom pokretanja vrijednosti pročitaju iz datoteke i spreme u globalne varijable |
jkordek | 0:5b31abb1ab50 | 23 | float PGZ = 0; |
jkordek | 0:5b31abb1ab50 | 24 | float IGZ = 0; |
jkordek | 0:5b31abb1ab50 | 25 | float DGZ = 0; |
jkordek | 0:5b31abb1ab50 | 26 | int hister = 0; |
jkordek | 0:5b31abb1ab50 | 27 | int pwm_fan = 0; |
jkordek | 0:5b31abb1ab50 | 28 | char ssid[30] = ""; |
jkordek | 0:5b31abb1ab50 | 29 | char pass[30] = ""; |
jkordek | 0:5b31abb1ab50 | 30 | float tset = 0; |
jkordek | 0:5b31abb1ab50 | 31 | int hset = 0; |
jkordek | 0:5b31abb1ab50 | 32 | |
jkordek | 0:5b31abb1ab50 | 33 | //varijavble za spremanje trenutnih vrijednosti temperature i vlage |
jkordek | 0:5b31abb1ab50 | 34 | float temperature = 0; |
jkordek | 0:5b31abb1ab50 | 35 | float humidity = 0; |
jkordek | 0:5b31abb1ab50 | 36 | |
jkordek | 0:5b31abb1ab50 | 37 | int broj_stranice = 0; //podatak o tome koja je stranica trenutno aktivna na Nextion zaslonu |
jkordek | 0:5b31abb1ab50 | 38 | |
jkordek | 0:5b31abb1ab50 | 39 | //funkcija koja je dodijeljena tickeru1 |
jkordek | 0:5b31abb1ab50 | 40 | void dohvativr() |
jkordek | 0:5b31abb1ab50 | 41 | { |
jkordek | 0:5b31abb1ab50 | 42 | if (broj_stranice ==0) { |
jkordek | 0:5b31abb1ab50 | 43 | temperature = pot.getTemp(); |
jkordek | 0:5b31abb1ab50 | 44 | humidity = pot.getVlaga(); |
jkordek | 0:5b31abb1ab50 | 45 | } |
jkordek | 0:5b31abb1ab50 | 46 | } |
jkordek | 0:5b31abb1ab50 | 47 | |
jkordek | 0:5b31abb1ab50 | 48 | //funkcija koja je dodijeljena tickeru2 |
jkordek | 0:5b31abb1ab50 | 49 | void nextion_ispis() |
jkordek | 0:5b31abb1ab50 | 50 | { |
jkordek | 0:5b31abb1ab50 | 51 | if (broj_stranice == 0) {//ispisuj samo ako je aktivna stranica broj 0 |
jkordek | 0:5b31abb1ab50 | 52 | |
jkordek | 0:5b31abb1ab50 | 53 | nextion.printf("add 10,0,"); |
jkordek | 0:5b31abb1ab50 | 54 | nextion.printf("%d",(int)temperature); |
jkordek | 0:5b31abb1ab50 | 55 | nextion.printf("\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 56 | |
jkordek | 0:5b31abb1ab50 | 57 | nextion.printf("add 10,1,"); |
jkordek | 0:5b31abb1ab50 | 58 | nextion.printf("%d",(int)tset); |
jkordek | 0:5b31abb1ab50 | 59 | nextion.printf("\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 60 | |
jkordek | 0:5b31abb1ab50 | 61 | nextion.printf("add 11,0,"); |
jkordek | 0:5b31abb1ab50 | 62 | nextion.printf("%d", (int)humidity); |
jkordek | 0:5b31abb1ab50 | 63 | nextion.printf("\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 64 | |
jkordek | 0:5b31abb1ab50 | 65 | nextion.printf("add 11,1,"); |
jkordek | 0:5b31abb1ab50 | 66 | nextion.printf("%d",(int)hset); |
jkordek | 0:5b31abb1ab50 | 67 | nextion.printf("\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 68 | |
jkordek | 0:5b31abb1ab50 | 69 | nextion.printf("temp.txt=\""); |
jkordek | 0:5b31abb1ab50 | 70 | nextion.printf("%.1f\260C",temperature); // znak 260 je "°" |
jkordek | 0:5b31abb1ab50 | 71 | nextion.printf("\"\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 72 | |
jkordek | 0:5b31abb1ab50 | 73 | nextion.printf("vlaga.txt=\""); |
jkordek | 0:5b31abb1ab50 | 74 | nextion.printf("%.0f%c", humidity, 37); //znak 37 je "%" |
jkordek | 0:5b31abb1ab50 | 75 | nextion.printf("\"\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 76 | } |
jkordek | 0:5b31abb1ab50 | 77 | } |
jkordek | 0:5b31abb1ab50 | 78 | |
jkordek | 0:5b31abb1ab50 | 79 | //funkcija koja vraća substring nekog stringa, argumenti su string, početak (m-ti znak) i kraj (n-ti znak) |
jkordek | 0:5b31abb1ab50 | 80 | char* substr(const char *src, int m, int n) |
jkordek | 0:5b31abb1ab50 | 81 | { |
jkordek | 0:5b31abb1ab50 | 82 | // veličina substringa |
jkordek | 0:5b31abb1ab50 | 83 | int len = n - m; |
jkordek | 0:5b31abb1ab50 | 84 | |
jkordek | 0:5b31abb1ab50 | 85 | // allocate (len + 1) chars for destination (+1 for extra null character) |
jkordek | 0:5b31abb1ab50 | 86 | // The C library function void *malloc(size_t size) allocates the requested memory and returns a pointer to it. |
jkordek | 0:5b31abb1ab50 | 87 | char *dest = (char*)malloc(sizeof(char) * (len + 1)); |
jkordek | 0:5b31abb1ab50 | 88 | |
jkordek | 0:5b31abb1ab50 | 89 | // extracts characters between m'th and n'th index from source string and copy them into the destination string |
jkordek | 0:5b31abb1ab50 | 90 | for (int i = m; i < n && (*src != '\0'); i++) { |
jkordek | 0:5b31abb1ab50 | 91 | *dest = *(src + i); |
jkordek | 0:5b31abb1ab50 | 92 | dest++; |
jkordek | 0:5b31abb1ab50 | 93 | } |
jkordek | 0:5b31abb1ab50 | 94 | |
jkordek | 0:5b31abb1ab50 | 95 | // null-terminate the destination string |
jkordek | 0:5b31abb1ab50 | 96 | *dest = '\0'; |
jkordek | 0:5b31abb1ab50 | 97 | |
jkordek | 0:5b31abb1ab50 | 98 | // return the destination string |
jkordek | 0:5b31abb1ab50 | 99 | return dest - len; |
jkordek | 0:5b31abb1ab50 | 100 | } |
jkordek | 0:5b31abb1ab50 | 101 | |
jkordek | 0:5b31abb1ab50 | 102 | //Rx_interrupt rutina |
jkordek | 0:5b31abb1ab50 | 103 | void Rx_Interrupt(void) |
jkordek | 0:5b31abb1ab50 | 104 | { |
jkordek | 0:5b31abb1ab50 | 105 | char c; |
jkordek | 0:5b31abb1ab50 | 106 | bool zapis; |
jkordek | 0:5b31abb1ab50 | 107 | |
jkordek | 0:5b31abb1ab50 | 108 | if(nextion.readable()) { |
jkordek | 0:5b31abb1ab50 | 109 | c = nextion.getc(); //očitaj znak i pohrani ga u varijablu "c" |
jkordek | 0:5b31abb1ab50 | 110 | buffer[znak] = c; //pohrani znak "c" u polje znakova pod indexom "znak" |
jkordek | 0:5b31abb1ab50 | 111 | znak++; //inkrement indexa |
jkordek | 0:5b31abb1ab50 | 112 | if ((znak >= 3) && (buffer[znak-1] == 0xff) && (buffer[znak-2] == 0xff) && (buffer[znak-3] == 0xff)) { //ako primljena poruka završava s “\xFF\xFF\xFF” (kraj naredbe) |
jkordek | 0:5b31abb1ab50 | 113 | |
jkordek | 0:5b31abb1ab50 | 114 | if (debug) pc.printf("primljeno: %s\n\r", buffer); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 115 | //strstr funkcija vraća index na kojem se prvi puta pojavljuje substring u stringu, ako ne postoji vraća NULL |
jkordek | 0:5b31abb1ab50 | 116 | if(strstr(buffer, "ppage") != NULL) { //ako je primljen broj stranice |
jkordek | 0:5b31abb1ab50 | 117 | broj_stranice = buffer[5] - 48; //npr. ppage2 >> buffer[5]-48 = 50 - 48 = 2 |
jkordek | 0:5b31abb1ab50 | 118 | if (debug) pc.printf("stranica %d\n\r", broj_stranice); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 119 | } |
jkordek | 0:5b31abb1ab50 | 120 | |
jkordek | 0:5b31abb1ab50 | 121 | else if(strstr(buffer, "pPGZ=") != NULL) { |
jkordek | 0:5b31abb1ab50 | 122 | char* dest = substr(buffer, strlen("pPGZ="), znak-3); //pokazivac na vrijednost PGZ-a u bufferu |
jkordek | 0:5b31abb1ab50 | 123 | PGZ = atof(dest); |
jkordek | 0:5b31abb1ab50 | 124 | if (debug) pc.printf("PGZ: %.3f\n\r", PGZ); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 125 | zapis = true; |
jkordek | 0:5b31abb1ab50 | 126 | } else if(strstr(buffer, "pIGZ=") != NULL) { |
jkordek | 0:5b31abb1ab50 | 127 | char* dest = substr(buffer, strlen("pIGZ="), znak-3); //pokazivac na vrijednost IGZ-a u bufferu |
jkordek | 0:5b31abb1ab50 | 128 | IGZ = atof(dest); |
jkordek | 0:5b31abb1ab50 | 129 | if (debug) pc.printf("IGZ: %.3f\n\r", IGZ); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 130 | zapis = true; |
jkordek | 0:5b31abb1ab50 | 131 | } else if(strstr(buffer, "pDGZ=") != NULL) { |
jkordek | 0:5b31abb1ab50 | 132 | char* dest = substr(buffer, strlen("pDGZ="), znak-3); //pokazivac na vrijednost DGZ-a u bufferu |
jkordek | 0:5b31abb1ab50 | 133 | DGZ = atof(dest); |
jkordek | 0:5b31abb1ab50 | 134 | if (debug) pc.printf("DGZ: %.3f\n\r", DGZ); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 135 | zapis = true; |
jkordek | 0:5b31abb1ab50 | 136 | } else if(strstr(buffer, "phister=") != NULL) { |
jkordek | 0:5b31abb1ab50 | 137 | char* dest = substr(buffer, strlen("phister="), znak-3); |
jkordek | 0:5b31abb1ab50 | 138 | hister = atoi(dest); |
jkordek | 0:5b31abb1ab50 | 139 | if (debug) pc.printf("histereza: %d\n\r", hister); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 140 | zapis = true; |
jkordek | 0:5b31abb1ab50 | 141 | } else if(strstr(buffer, "ppwm_fan=") != NULL) { |
jkordek | 0:5b31abb1ab50 | 142 | char* dest = substr(buffer, strlen("ppwm_fan="), znak-3); |
jkordek | 0:5b31abb1ab50 | 143 | pwm_fan = atoi(dest); |
jkordek | 0:5b31abb1ab50 | 144 | if (debug) pc.printf("pwm fan: %d\n\r", pwm_fan); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 145 | vent = pwm_fan/100.0; // postavi vrijednost faktora vođenja |
jkordek | 0:5b31abb1ab50 | 146 | zapis = true; |
jkordek | 0:5b31abb1ab50 | 147 | } else if(strstr(buffer, "ps=") != NULL) { |
jkordek | 0:5b31abb1ab50 | 148 | char* dest = substr(buffer, strlen("ps="), znak-3); |
jkordek | 0:5b31abb1ab50 | 149 | strcpy(ssid, dest); |
jkordek | 0:5b31abb1ab50 | 150 | if (debug) pc.printf("ssid: %s\n\r", ssid); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 151 | zapis = true; |
jkordek | 0:5b31abb1ab50 | 152 | } else if(strstr(buffer, "pp=") != NULL) { |
jkordek | 0:5b31abb1ab50 | 153 | char* dest = substr(buffer, strlen("pp="), znak-3); |
jkordek | 0:5b31abb1ab50 | 154 | strcpy(pass, dest); |
jkordek | 0:5b31abb1ab50 | 155 | if (debug) pc.printf("pass: %s\n\r", pass); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 156 | zapis = true; |
jkordek | 0:5b31abb1ab50 | 157 | } else if(strstr(buffer, "ptset=") != NULL) { |
jkordek | 0:5b31abb1ab50 | 158 | char* dest = substr(buffer, strlen("ptset="), znak-3); |
jkordek | 0:5b31abb1ab50 | 159 | tset = atof(dest); |
jkordek | 0:5b31abb1ab50 | 160 | if (debug) pc.printf("temp set: %.1f\n\r", tset); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 161 | zapis = true; |
jkordek | 0:5b31abb1ab50 | 162 | } else if(strstr(buffer, "phset=") != NULL) { |
jkordek | 0:5b31abb1ab50 | 163 | char* dest = substr(buffer, strlen("phset="), znak-3); |
jkordek | 0:5b31abb1ab50 | 164 | hset = atoi(dest); |
jkordek | 0:5b31abb1ab50 | 165 | if (debug) pc.printf("histereza: %d\n\r", hset); // prikaži primljenu poruku |
jkordek | 0:5b31abb1ab50 | 166 | zapis = true; |
jkordek | 0:5b31abb1ab50 | 167 | } |
jkordek | 0:5b31abb1ab50 | 168 | if(zapis) { //ako je došlo do promjene parametara otvori datoteku i pohrani vrijednosti |
jkordek | 0:5b31abb1ab50 | 169 | FILE *File2 = fopen("/local/textfile.txt", "w"); // Open "out.txt" on the local file system for writing |
jkordek | 0:5b31abb1ab50 | 170 | fprintf(File2, "%.3f\r%.3f\r%.3f\r%d\r%d\r%s\r%s\r%.1f\r%d\r", PGZ, IGZ, DGZ, hister, pwm_fan, ssid, pass, tset, hset); |
jkordek | 0:5b31abb1ab50 | 171 | fclose(File2); |
jkordek | 0:5b31abb1ab50 | 172 | zapis = false; |
jkordek | 0:5b31abb1ab50 | 173 | } |
jkordek | 0:5b31abb1ab50 | 174 | |
jkordek | 0:5b31abb1ab50 | 175 | memset(buffer,0,strlen(buffer)); //isprazni buffer |
jkordek | 0:5b31abb1ab50 | 176 | znak = 0; //ponovno sastavljaj polje znakova od nulte pozicije |
jkordek | 0:5b31abb1ab50 | 177 | } |
jkordek | 0:5b31abb1ab50 | 178 | } |
jkordek | 0:5b31abb1ab50 | 179 | } |
jkordek | 0:5b31abb1ab50 | 180 | |
jkordek | 0:5b31abb1ab50 | 181 | void init(){ |
jkordek | 0:5b31abb1ab50 | 182 | |
jkordek | 0:5b31abb1ab50 | 183 | nextion.baud(115200); |
jkordek | 0:5b31abb1ab50 | 184 | nextion.attach(&Rx_Interrupt, Serial::RxIrq); // Serial prekid |
jkordek | 0:5b31abb1ab50 | 185 | akvizicija.attach(&dohvativr, 0.5); //ticker, svakih 500ms |
jkordek | 0:5b31abb1ab50 | 186 | NextionIspis.attach(&nextion_ispis, 0.5); //ticker, svakih 500ms |
jkordek | 0:5b31abb1ab50 | 187 | |
jkordek | 0:5b31abb1ab50 | 188 | //-------------------------- citanje iz datoteke --------------------------------------------// |
jkordek | 0:5b31abb1ab50 | 189 | |
jkordek | 0:5b31abb1ab50 | 190 | FILE* File2 = fopen ("/local/textfile.txt","r"); // otvori datoteku |
jkordek | 0:5b31abb1ab50 | 191 | fgets(read_string,128,File2); // pročitaj podatke |
jkordek | 0:5b31abb1ab50 | 192 | fclose(File2); // zatvori datoteku |
jkordek | 0:5b31abb1ab50 | 193 | |
jkordek | 0:5b31abb1ab50 | 194 | int init_size = strlen(read_string); |
jkordek | 0:5b31abb1ab50 | 195 | char delim[] = "\n\r"; |
jkordek | 0:5b31abb1ab50 | 196 | |
jkordek | 0:5b31abb1ab50 | 197 | char *ptr = strtok(read_string, delim); |
jkordek | 0:5b31abb1ab50 | 198 | |
jkordek | 0:5b31abb1ab50 | 199 | int i = 0; |
jkordek | 0:5b31abb1ab50 | 200 | |
jkordek | 0:5b31abb1ab50 | 201 | while(ptr != NULL) { |
jkordek | 0:5b31abb1ab50 | 202 | |
jkordek | 0:5b31abb1ab50 | 203 | switch (i) { |
jkordek | 0:5b31abb1ab50 | 204 | |
jkordek | 0:5b31abb1ab50 | 205 | case 0: |
jkordek | 0:5b31abb1ab50 | 206 | PGZ = atof(ptr); |
jkordek | 0:5b31abb1ab50 | 207 | break; |
jkordek | 0:5b31abb1ab50 | 208 | |
jkordek | 0:5b31abb1ab50 | 209 | case 1: |
jkordek | 0:5b31abb1ab50 | 210 | IGZ = atof(ptr); |
jkordek | 0:5b31abb1ab50 | 211 | break; |
jkordek | 0:5b31abb1ab50 | 212 | |
jkordek | 0:5b31abb1ab50 | 213 | case 2: |
jkordek | 0:5b31abb1ab50 | 214 | DGZ = atof(ptr); |
jkordek | 0:5b31abb1ab50 | 215 | break; |
jkordek | 0:5b31abb1ab50 | 216 | |
jkordek | 0:5b31abb1ab50 | 217 | case 3: |
jkordek | 0:5b31abb1ab50 | 218 | hister = atoi(ptr); |
jkordek | 0:5b31abb1ab50 | 219 | break; |
jkordek | 0:5b31abb1ab50 | 220 | |
jkordek | 0:5b31abb1ab50 | 221 | case 4: |
jkordek | 0:5b31abb1ab50 | 222 | pwm_fan = atoi(ptr); |
jkordek | 0:5b31abb1ab50 | 223 | break; |
jkordek | 0:5b31abb1ab50 | 224 | |
jkordek | 0:5b31abb1ab50 | 225 | case 5: |
jkordek | 0:5b31abb1ab50 | 226 | strcpy(ssid, ptr); |
jkordek | 0:5b31abb1ab50 | 227 | break; |
jkordek | 0:5b31abb1ab50 | 228 | |
jkordek | 0:5b31abb1ab50 | 229 | case 6: |
jkordek | 0:5b31abb1ab50 | 230 | strcpy(pass, ptr); |
jkordek | 0:5b31abb1ab50 | 231 | break; |
jkordek | 0:5b31abb1ab50 | 232 | |
jkordek | 0:5b31abb1ab50 | 233 | case 7: |
jkordek | 0:5b31abb1ab50 | 234 | tset = atof(ptr); |
jkordek | 0:5b31abb1ab50 | 235 | break; |
jkordek | 0:5b31abb1ab50 | 236 | |
jkordek | 0:5b31abb1ab50 | 237 | case 8: |
jkordek | 0:5b31abb1ab50 | 238 | hset = atoi(ptr); |
jkordek | 0:5b31abb1ab50 | 239 | break; |
jkordek | 0:5b31abb1ab50 | 240 | |
jkordek | 0:5b31abb1ab50 | 241 | default: |
jkordek | 0:5b31abb1ab50 | 242 | printf("Greska\n\r"); |
jkordek | 0:5b31abb1ab50 | 243 | } |
jkordek | 0:5b31abb1ab50 | 244 | |
jkordek | 0:5b31abb1ab50 | 245 | if (debug) printf("%s", ptr); |
jkordek | 0:5b31abb1ab50 | 246 | ptr = strtok(NULL, delim); |
jkordek | 0:5b31abb1ab50 | 247 | i++; |
jkordek | 0:5b31abb1ab50 | 248 | |
jkordek | 0:5b31abb1ab50 | 249 | } |
jkordek | 0:5b31abb1ab50 | 250 | i = 0; //jel treba uopće ovo? |
jkordek | 0:5b31abb1ab50 | 251 | //---------------------------------------------------------------------------------------------------// |
jkordek | 0:5b31abb1ab50 | 252 | |
jkordek | 0:5b31abb1ab50 | 253 | //-------------------------- slanje zaslonu prilikom inicijalizacije --------------------------------------------// |
jkordek | 0:5b31abb1ab50 | 254 | |
jkordek | 0:5b31abb1ab50 | 255 | nextion.printf("page2.t0.txt=\""); |
jkordek | 0:5b31abb1ab50 | 256 | nextion.printf("%.3f",PGZ); |
jkordek | 0:5b31abb1ab50 | 257 | nextion.printf("\"\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 258 | |
jkordek | 0:5b31abb1ab50 | 259 | nextion.printf("page2.t1.txt=\""); |
jkordek | 0:5b31abb1ab50 | 260 | nextion.printf("%.3f",IGZ); |
jkordek | 0:5b31abb1ab50 | 261 | nextion.printf("\"\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 262 | |
jkordek | 0:5b31abb1ab50 | 263 | nextion.printf("page2.t2.txt=\""); |
jkordek | 0:5b31abb1ab50 | 264 | nextion.printf("%.3f",DGZ); |
jkordek | 0:5b31abb1ab50 | 265 | nextion.printf("\"\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 266 | |
jkordek | 0:5b31abb1ab50 | 267 | nextion.printf("page2.n0.val="); |
jkordek | 0:5b31abb1ab50 | 268 | nextion.printf("%d",hister); |
jkordek | 0:5b31abb1ab50 | 269 | nextion.printf("\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 270 | |
jkordek | 0:5b31abb1ab50 | 271 | nextion.printf("page2.n1.val="); |
jkordek | 0:5b31abb1ab50 | 272 | nextion.printf("%d", pwm_fan); |
jkordek | 0:5b31abb1ab50 | 273 | nextion.printf("\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 274 | |
jkordek | 0:5b31abb1ab50 | 275 | nextion.printf("page4.t0.txt=\""); |
jkordek | 0:5b31abb1ab50 | 276 | nextion.printf("%s",ssid); |
jkordek | 0:5b31abb1ab50 | 277 | nextion.printf("\"\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 278 | |
jkordek | 0:5b31abb1ab50 | 279 | nextion.printf("page4.t1.txt=\""); |
jkordek | 0:5b31abb1ab50 | 280 | nextion.printf("%s",pass); |
jkordek | 0:5b31abb1ab50 | 281 | nextion.printf("\"\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 282 | |
jkordek | 0:5b31abb1ab50 | 283 | nextion.printf("page0.t6.txt=\""); |
jkordek | 0:5b31abb1ab50 | 284 | nextion.printf("%.1f",tset); |
jkordek | 0:5b31abb1ab50 | 285 | nextion.printf("\"\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 286 | |
jkordek | 0:5b31abb1ab50 | 287 | nextion.printf("page0.t2.txt=\""); |
jkordek | 0:5b31abb1ab50 | 288 | nextion.printf("%d",hset); |
jkordek | 0:5b31abb1ab50 | 289 | nextion.printf("\"\xFF\xFF\xFF"); |
jkordek | 0:5b31abb1ab50 | 290 | |
jkordek | 0:5b31abb1ab50 | 291 | //---------------------------------------------------------------------------------------------------// |
jkordek | 0:5b31abb1ab50 | 292 | |
jkordek | 0:5b31abb1ab50 | 293 | } |
jkordek | 0:5b31abb1ab50 | 294 | |
jkordek | 0:5b31abb1ab50 | 295 | void pwmInit(){ |
jkordek | 0:5b31abb1ab50 | 296 | vent.period(0.010); //pwm frekvencija 100 Hz |
jkordek | 0:5b31abb1ab50 | 297 | vent = pwm_fan/100.0; //skaliraj pwm |
jkordek | 0:5b31abb1ab50 | 298 | } |
jkordek | 0:5b31abb1ab50 | 299 | |
jkordek | 0:5b31abb1ab50 | 300 | int main() |
jkordek | 0:5b31abb1ab50 | 301 | { |
jkordek | 0:5b31abb1ab50 | 302 | init(); |
jkordek | 0:5b31abb1ab50 | 303 | pwmInit(); |
jkordek | 0:5b31abb1ab50 | 304 | |
jkordek | 0:5b31abb1ab50 | 305 | while (1) { |
jkordek | 0:5b31abb1ab50 | 306 | wait(0.5); // Ne radi ništa |
jkordek | 0:5b31abb1ab50 | 307 | } |
jkordek | 0:5b31abb1ab50 | 308 | } |
jkordek | 0:5b31abb1ab50 | 309 | |
jkordek | 0:5b31abb1ab50 | 310 |