Re: FLIRS ISSUE
Posted: 04 Sep 2017 19:49
Code: Select all
// 2.1.0 FLiRS example by user "petergebruers"
// FLiRS capable channels: Siren and Valve control only!
ZUNO_SETUP_CHANNELS(ZUNO_SIREN(getter, setter));
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);
void setup() {
}
void loop() {
zunoSendDeviceToSleep();
}
void setter(BYTE value) {
}
BYTE getter() {
return 1;
}
Code: Select all
// LED pin number
// 13 pin - user LED of Z-Uno board
#define LED_PIN 13
#include <EEPROM.h>
#define STATE_ADDR 1
#define MAGIC_ADDR 2
ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_BINARY(getter, setter));
// next macro sets up the sleeping mode
// device will wake up by user request and regulary listening for packets
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);
// Just a trick to keep device ready for some loops
byte g_loop_count = 100;
byte state_changed = false;
byte current_val;
// the setup routine runs once when you press reset:
void setup() {
pinMode(LED_PIN, OUTPUT); // setup pin as output
if( NZRAM.read(MAGIC_ADDR) != 0x42) // Check a magic value (if memory was initialized value have to be correct)
{
NZRAM.write(STATE_ADDR, 0); // Switched of by default
NZRAM.write(MAGIC_ADDR, 0x42);
Serial0.println("Reinit");
}
current_val = NZRAM.read(STATE_ADDR);
// We have to reinitialize the pin state every wake up
digitalWrite(LED_PIN, current_val);
}
// the loop routine runs over and over again forever:
void loop() {
if(state_changed)
{
if (current_val > 0) { // if greater then zero
digitalWrite (LED_PIN, HIGH); //turn the LED on (HIGH is the voltage level)
} else { // if equals zero
digitalWrite(LED_PIN, LOW); //turn the LED off by making the voltage LOW
}
NZRAM.write(STATE_ADDR, current_val);
state_changed = false;
}
g_loop_count--;
if(!g_loop_count)
{
// this function sends the device into sleep
zunoSendDeviceToSleep();
}
delay(20);
}
void setter(byte value) {
// Here we just store new state and tell the main logic that state was changed
current_val = value;
state_changed = true;
}
byte getter() {
return current_val;
}
Code: Select all
// 2.1.0 FLiRS example by user "petergebruers"
// FLiRS capable channels: Siren and Valve control only!
#include "EEPROM.h"
ZUNO_SETUP_CHANNELS(ZUNO_SIREN(getter, setter));
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);
// LED pin number 13 = white user LED of Z-Uno board
#define LED_PIN LED_BUILTIN
// loopcounter counts number of loop calls and
// is used to send device to slaap after 2 rounds
// to avoid "getter issues"
BYTE loopcounter;
void setup() {
loopcounter = 0;
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
}
void loop() {
loopcounter++;
if (loopcounter == 2)
zunoSendDeviceToSleep();
}
void setter(BYTE value) {
}
BYTE getter() {
return 42;
}
Thank you for confirming this. I will continue my work on a nice working example when the known issues have been resolved. Please contact me if you want me to beta test something.