From 81dd29d3e7abed27ee90e826e31818d029ae5dfe Mon Sep 17 00:00:00 2001 From: maxxir_w Date: Mon, 18 Mar 2019 13:39:39 +0400 Subject: [PATCH] Added Two feedback examples --- 19_m1284p_WIZNET_blynk/.cproject | 1 - .../Application/Blynk/blynkDependency.c | 18 +++++++++-- 19_m1284p_WIZNET_blynk/globals.h | 2 ++ 19_m1284p_WIZNET_blynk/main.c | 36 ++++++++++++++++++---- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/19_m1284p_WIZNET_blynk/.cproject b/19_m1284p_WIZNET_blynk/.cproject index b5431c1..5201eba 100644 --- a/19_m1284p_WIZNET_blynk/.cproject +++ b/19_m1284p_WIZNET_blynk/.cproject @@ -33,7 +33,6 @@ diff --git a/19_m1284p_WIZNET_blynk/Application/Blynk/blynkDependency.c b/19_m1284p_WIZNET_blynk/Application/Blynk/blynkDependency.c index 49e0b08..0ad570c 100644 --- a/19_m1284p_WIZNET_blynk/Application/Blynk/blynkDependency.c +++ b/19_m1284p_WIZNET_blynk/Application/Blynk/blynkDependency.c @@ -60,6 +60,8 @@ void digitalWrite(uint8_t pin, uint8_t val) { led1_high(); } + //Rise flag to PUSH message to Virtual pin 20 + v20_changed = 1; } #endif } @@ -104,6 +106,8 @@ void analogWrite(uint8_t pin, uint8_t val) if(pin == 15) { OCR2A = val; + //Rise flag to PUSH message to Virtual pin 15 + v15_changed = 1; } #endif } @@ -151,13 +155,23 @@ uint16_t virtualRead(uint8_t pin) { //Digital read example from Virtual Pin 13 val = led2_read()?1:0; - PRINTF("LED2 is: %d %s\r\n", val, val?"HIGH":"LOW"); + //PRINTF("LED2 is: %d %s\r\n", val, val?"HIGH":"LOW"); } else if(pin == 6) { //Analog read example from Virtual Pin 6 val = adc_read(6); - PRINTF("analog pin %d = %d\r\n", pin, val); + //PRINTF("analog pin %d = %d\r\n", pin, val); + } + else if(pin == 15) + { + //PWM Value PIN15/PD7 + val = (uint16_t)OCR2A; + } + else if(pin == 20) + { + //Digital OUT Value PIN20/PC4 + val = led1_read()?1:0; } return val; } diff --git a/19_m1284p_WIZNET_blynk/globals.h b/19_m1284p_WIZNET_blynk/globals.h index b081755..3390fe4 100644 --- a/19_m1284p_WIZNET_blynk/globals.h +++ b/19_m1284p_WIZNET_blynk/globals.h @@ -74,4 +74,6 @@ extern uint8_t DNS_2nd[4]; extern uint16_t adc_read(uint8_t channel); extern uint8_t auth[]; +extern uint8_t v15_changed; +extern uint8_t v20_changed; #endif /* GLOBALS_H_ */ diff --git a/19_m1284p_WIZNET_blynk/main.c b/19_m1284p_WIZNET_blynk/main.c index 2deb7ad..df8c0eb 100644 --- a/19_m1284p_WIZNET_blynk/main.c +++ b/19_m1284p_WIZNET_blynk/main.c @@ -21,10 +21,13 @@ * OK (v1.7) Add push event to Virtual PIN1. Every 10sec push message: "Uptime: xxx sec", to BLYNK server (widget Terminal) * OK (v1.8) Need compare local blynk.c code with modern library - (Too old version here - 0.2.1 (On git blynk March 2019 - 0.6.x) ) * OK (v1.8) Made fix correction blynk.h/blynk.c 16.02.2019 to match BLYNK protocol 0.6.0 - * + * OK (v1.9) Two feedback examples from: + * D20/PC4(digitalWrite(20))->V20(virtualRead(20)) + * PWM D15/PD7(analogWrite(15))->V15(virtualRead(15)) + * using push events && on change state flags * PS. - * Further correction of the code from MBED authors (Vladimir Shimansky, Dmitriy Dumanskiy ..) is highly desirable. - * Because I'm not the author of mbed libs. And I do not quite well understand how this should work in their opinion. + * Further correction, or advices about the code from BLYNK authors (Vladimir Shimansky, Dmitriy Dumanskiy ..) is highly desirable. + * Because I'm not the author of blynk libs. And I do not quite well understand how this should work in right manner. * * Author of unofficial porting to AVR Mega1284p/644p + W5500 Ethernet NIC (Wiznet sockets library using without Arduino): * Ibragimov Maxim aka maxxir, Russia Togliatty ~xx.03.2019 @@ -61,6 +64,10 @@ uint8_t BLYNK_TX_BUF[BLYNK_DATA_BUF_SIZE]; +//BLYNK Virtual pins state changed flags +uint8_t v15_changed; +uint8_t v20_changed; + //***********BLYNK related: END //***************** DNS: BEGIN @@ -79,8 +86,7 @@ uint8_t Domain_name[] = BLYNK_DEFAULT_DOMAIN; // BLYNK server URI uint8_t Domain_IP[4] = {0, }; // Translated IP address by DNS Server //***************** DNS: END - -//***********Prologue for fast WDT disable & and save reason of reset/power-up: END +//***********Prologue for fast WDT disable & and save reason of reset/power-up: BEGIN uint8_t mcucsr_mirror __attribute__ ((section (".noinit"))); // This is for fast WDT disable & and save reason of reset/power-up @@ -102,7 +108,7 @@ volatile unsigned long _millis; // for millis tick !! Overflow every ~49.7 days //*********Program metrics const char compile_date[] PROGMEM = __DATE__; // Mmm dd yyyy - Дата компиляции const char compile_time[] PROGMEM = __TIME__; // hh:mm:ss - Время компиляции -const char str_prog_name[] PROGMEM = "\r\nAtMega1284p v1.8 Static IP BLYNK WIZNET_5500 ETHERNET 16/03/2019\r\n"; // Program name +const char str_prog_name[] PROGMEM = "\r\nAtMega1284p v1.9 Static IP BLYNK WIZNET_5500 ETHERNET 18/03/2019\r\n"; // Program name #if defined(__AVR_ATmega128__) const char PROGMEM str_mcu[] = "ATmega128"; //CPU is m128 @@ -393,6 +399,9 @@ int main() avr_init(); spi_init(); //SPI Master, MODE0, 4Mhz(DIV4), CS_PB.3=HIGH - suitable for WIZNET 5x00(1/2/5) + //Bullet proof: clear Virtual pins state change flags + v15_changed = 0; + v20_changed = 0; // Print program metrics PRINTF("%S", str_prog_name);// Название программы @@ -498,6 +507,21 @@ int main() blynk_syncAll(); } } + + //Virtual pins state change check here + if(v15_changed) + { + v15_changed = 0; //Drop flag + //Push message with changed V15 value (LED PWM PIN15/PD7 ) + blynk_push_virtual_pin(15); + + } + else if(v20_changed) + { + v20_changed = 0; //Drop flag + //Push message with changed V20 value (LED1 D20/PC4) + blynk_push_virtual_pin(20); + } //Every 10sec event for LED2 PIN13, and uptime device if(++timer_led2_push_10sec == 10) {