Added Two feedback examples

master
maxxir_w 7 years ago
parent 14da65684c
commit 81dd29d3e7

@ -33,7 +33,6 @@
<option id="de.innot.avreclipse.compiler.option.incpath.478254702" name="Include Paths (-I)" superClass="de.innot.avreclipse.compiler.option.incpath" valueType="includePath"> <option id="de.innot.avreclipse.compiler.option.incpath.478254702" name="Include Paths (-I)" superClass="de.innot.avreclipse.compiler.option.incpath" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Ethernet}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Ethernet}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Ethernet/W5500}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Ethernet/W5500}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Application/loopback}&quot;"/>
</option> </option>
<inputType id="de.innot.avreclipse.compiler.winavr.input.167604838" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/> <inputType id="de.innot.avreclipse.compiler.winavr.input.167604838" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/>
</tool> </tool>

@ -60,6 +60,8 @@ void digitalWrite(uint8_t pin, uint8_t val)
{ {
led1_high(); led1_high();
} }
//Rise flag to PUSH message to Virtual pin 20
v20_changed = 1;
} }
#endif #endif
} }
@ -104,6 +106,8 @@ void analogWrite(uint8_t pin, uint8_t val)
if(pin == 15) if(pin == 15)
{ {
OCR2A = val; OCR2A = val;
//Rise flag to PUSH message to Virtual pin 15
v15_changed = 1;
} }
#endif #endif
} }
@ -151,13 +155,23 @@ uint16_t virtualRead(uint8_t pin)
{ {
//Digital read example from Virtual Pin 13 //Digital read example from Virtual Pin 13
val = led2_read()?1:0; 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) else if(pin == 6)
{ {
//Analog read example from Virtual Pin 6 //Analog read example from Virtual Pin 6
val = adc_read(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; return val;
} }

@ -74,4 +74,6 @@ extern uint8_t DNS_2nd[4];
extern uint16_t adc_read(uint8_t channel); extern uint16_t adc_read(uint8_t channel);
extern uint8_t auth[]; extern uint8_t auth[];
extern uint8_t v15_changed;
extern uint8_t v20_changed;
#endif /* GLOBALS_H_ */ #endif /* GLOBALS_H_ */

@ -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.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 <blynk> library - (Too old version here - 0.2.1 (On git blynk March 2019 - 0.6.x) ) * OK (v1.8) Need compare local blynk.c code with modern <blynk> 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.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. * PS.
* Further correction of the code from MBED authors (Vladimir Shimansky, Dmitriy Dumanskiy ..) is highly desirable. * Further correction, or advices about the code from BLYNK 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. * 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): * 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 * Ibragimov Maxim aka maxxir, Russia Togliatty ~xx.03.2019
@ -61,6 +64,10 @@
uint8_t BLYNK_TX_BUF[BLYNK_DATA_BUF_SIZE]; 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 //***********BLYNK related: END
//***************** DNS: BEGIN //***************** 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 uint8_t Domain_IP[4] = {0, }; // Translated IP address by DNS Server
//***************** DNS: END //***************** DNS: END
//***********Prologue for fast WDT disable & and save reason of reset/power-up: BEGIN
//***********Prologue for fast WDT disable & and save reason of reset/power-up: END
uint8_t mcucsr_mirror __attribute__ ((section (".noinit"))); uint8_t mcucsr_mirror __attribute__ ((section (".noinit")));
// This is for fast WDT disable & and save reason of reset/power-up // 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 //*********Program metrics
const char compile_date[] PROGMEM = __DATE__; // Mmm dd yyyy - Дата компиляции const char compile_date[] PROGMEM = __DATE__; // Mmm dd yyyy - Дата компиляции
const char compile_time[] PROGMEM = __TIME__; // hh:mm:ss - Время компиляции 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__) #if defined(__AVR_ATmega128__)
const char PROGMEM str_mcu[] = "ATmega128"; //CPU is m128 const char PROGMEM str_mcu[] = "ATmega128"; //CPU is m128
@ -393,6 +399,9 @@ int main()
avr_init(); avr_init();
spi_init(); //SPI Master, MODE0, 4Mhz(DIV4), CS_PB.3=HIGH - suitable for WIZNET 5x00(1/2/5) 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 // Print program metrics
PRINTF("%S", str_prog_name);// Название программы PRINTF("%S", str_prog_name);// Название программы
@ -498,6 +507,21 @@ int main()
blynk_syncAll(); 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 //Every 10sec event for LED2 PIN13, and uptime device
if(++timer_led2_push_10sec == 10) if(++timer_led2_push_10sec == 10)
{ {