Version 1.1
Added saving device ID to EEPROM.
This commit is contained in:
parent
680f7692e9
commit
603efb8a08
@ -6,9 +6,6 @@ board_build.f_cpu = 8000000L
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = usbasp
|
upload_protocol = usbasp
|
||||||
build_flags =
|
build_flags =
|
||||||
-D OPEN=1
|
|
||||||
-D CLOSE=0
|
|
||||||
-D OPEN_CLOSE=7
|
|
||||||
-D ID=$UNIX_TIME
|
-D ID=$UNIX_TIME
|
||||||
board_fuses.hfuse = 0xDE
|
board_fuses.hfuse = 0xDE
|
||||||
board_fuses.lfuse = 0xE2
|
board_fuses.lfuse = 0xE2
|
||||||
@ -17,8 +14,9 @@ upload_flags =
|
|||||||
-Pusb
|
-Pusb
|
||||||
-e
|
-e
|
||||||
lib_deps =
|
lib_deps =
|
||||||
feilipu/FreeRTOS@^10.5.0-0
|
https://github.com/aZholtikov/ZHConfig
|
||||||
nrf24/RF24@^1.4.5
|
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||||
|
https://github.com/nRF24/RF24
|
||||||
|
|
||||||
[env:ATmega168P]
|
[env:ATmega168P]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
@ -28,9 +26,6 @@ board_build.f_cpu = 8000000L
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = usbasp
|
upload_protocol = usbasp
|
||||||
build_flags =
|
build_flags =
|
||||||
-D OPEN=1
|
|
||||||
-D CLOSE=0
|
|
||||||
-D OPEN_CLOSE=7
|
|
||||||
-D ID=$UNIX_TIME
|
-D ID=$UNIX_TIME
|
||||||
board_fuses.hfuse = 0xDE
|
board_fuses.hfuse = 0xDE
|
||||||
board_fuses.lfuse = 0xE2
|
board_fuses.lfuse = 0xE2
|
||||||
@ -39,8 +34,9 @@ upload_flags =
|
|||||||
-Pusb
|
-Pusb
|
||||||
-e
|
-e
|
||||||
lib_deps =
|
lib_deps =
|
||||||
feilipu/FreeRTOS@^10.5.0-0
|
https://github.com/aZholtikov/ZHConfig
|
||||||
nrf24/RF24@^1.4.5
|
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||||
|
https://github.com/nRF24/RF24
|
||||||
|
|
||||||
[env:ATmega168PB]
|
[env:ATmega168PB]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
@ -50,9 +46,6 @@ board_build.f_cpu = 8000000L
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = usbasp
|
upload_protocol = usbasp
|
||||||
build_flags =
|
build_flags =
|
||||||
-D OPEN=1
|
|
||||||
-D CLOSE=0
|
|
||||||
-D OPEN_CLOSE=7
|
|
||||||
-D ID=$UNIX_TIME
|
-D ID=$UNIX_TIME
|
||||||
board_fuses.hfuse = 0xDE
|
board_fuses.hfuse = 0xDE
|
||||||
board_fuses.lfuse = 0xE2
|
board_fuses.lfuse = 0xE2
|
||||||
@ -61,8 +54,9 @@ upload_flags =
|
|||||||
-Pusb
|
-Pusb
|
||||||
-e
|
-e
|
||||||
lib_deps =
|
lib_deps =
|
||||||
feilipu/FreeRTOS@^10.5.0-0
|
https://github.com/aZholtikov/ZHConfig
|
||||||
nrf24/RF24@^1.4.5
|
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||||
|
https://github.com/nRF24/RF24
|
||||||
|
|
||||||
[env:ATmega328]
|
[env:ATmega328]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
@ -72,9 +66,6 @@ board_build.f_cpu = 8000000L
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = usbasp
|
upload_protocol = usbasp
|
||||||
build_flags =
|
build_flags =
|
||||||
-D OPEN=1
|
|
||||||
-D CLOSE=0
|
|
||||||
-D OPEN_CLOSE=7
|
|
||||||
-D ID=$UNIX_TIME
|
-D ID=$UNIX_TIME
|
||||||
board_fuses.hfuse = 0xDE
|
board_fuses.hfuse = 0xDE
|
||||||
board_fuses.lfuse = 0xE2
|
board_fuses.lfuse = 0xE2
|
||||||
@ -83,8 +74,9 @@ upload_flags =
|
|||||||
-Pusb
|
-Pusb
|
||||||
-e
|
-e
|
||||||
lib_deps =
|
lib_deps =
|
||||||
feilipu/FreeRTOS@^10.5.0-0
|
https://github.com/aZholtikov/ZHConfig
|
||||||
nrf24/RF24@^1.4.5
|
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||||
|
https://github.com/nRF24/RF24
|
||||||
|
|
||||||
[env:ATmega328P]
|
[env:ATmega328P]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
@ -94,9 +86,6 @@ board_build.f_cpu = 8000000L
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = usbasp
|
upload_protocol = usbasp
|
||||||
build_flags =
|
build_flags =
|
||||||
-D OPEN=1
|
|
||||||
-D CLOSE=0
|
|
||||||
-D OPEN_CLOSE=7
|
|
||||||
-D ID=$UNIX_TIME
|
-D ID=$UNIX_TIME
|
||||||
board_fuses.hfuse = 0xDE
|
board_fuses.hfuse = 0xDE
|
||||||
board_fuses.lfuse = 0xE2
|
board_fuses.lfuse = 0xE2
|
||||||
@ -105,8 +94,9 @@ upload_flags =
|
|||||||
-Pusb
|
-Pusb
|
||||||
-e
|
-e
|
||||||
lib_deps =
|
lib_deps =
|
||||||
feilipu/FreeRTOS@^10.5.0-0
|
https://github.com/aZholtikov/ZHConfig
|
||||||
nrf24/RF24@^1.4.5
|
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||||
|
https://github.com/nRF24/RF24
|
||||||
|
|
||||||
[env:ATmega328PB]
|
[env:ATmega328PB]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
@ -116,9 +106,6 @@ board_build.f_cpu = 8000000L
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = usbasp
|
upload_protocol = usbasp
|
||||||
build_flags =
|
build_flags =
|
||||||
-D OPEN=1
|
|
||||||
-D CLOSE=0
|
|
||||||
-D OPEN_CLOSE=7
|
|
||||||
-D ID=$UNIX_TIME
|
-D ID=$UNIX_TIME
|
||||||
board_fuses.hfuse = 0xDE
|
board_fuses.hfuse = 0xDE
|
||||||
board_fuses.lfuse = 0xE2
|
board_fuses.lfuse = 0xE2
|
||||||
@ -127,5 +114,6 @@ upload_flags =
|
|||||||
-Pusb
|
-Pusb
|
||||||
-e
|
-e
|
||||||
lib_deps =
|
lib_deps =
|
||||||
feilipu/FreeRTOS@^10.5.0-0
|
https://github.com/aZholtikov/ZHConfig
|
||||||
nrf24/RF24@^1.4.5
|
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||||
|
https://github.com/nRF24/RF24
|
41
src/main.cpp
41
src/main.cpp
@ -3,20 +3,15 @@
|
|||||||
#include "RF24.h"
|
#include "RF24.h"
|
||||||
#include "avr/interrupt.h"
|
#include "avr/interrupt.h"
|
||||||
#include "semphr.h"
|
#include "semphr.h"
|
||||||
|
#include "EEPROM.h"
|
||||||
typedef struct
|
#include "ZHConfig.h"
|
||||||
{
|
|
||||||
int16_t sensor_id{0};
|
|
||||||
int16_t sensor_type{0};
|
|
||||||
int16_t value_1{0};
|
|
||||||
int16_t value_2{0};
|
|
||||||
int16_t value_3{0};
|
|
||||||
int16_t value_4{0};
|
|
||||||
int16_t value_5{0};
|
|
||||||
} transmitted_data_t;
|
|
||||||
|
|
||||||
void sendButtonStatus(void *pvParameters);
|
void sendButtonStatus(void *pvParameters);
|
||||||
float getBatteryLevelCharge(void);
|
float getBatteryLevelCharge(void);
|
||||||
|
void loadConfig(void);
|
||||||
|
void saveConfig(void);
|
||||||
|
|
||||||
|
int16_t id{abs((int16_t)ID)};
|
||||||
|
|
||||||
RF24 radio(9, 10);
|
RF24 radio(9, 10);
|
||||||
SemaphoreHandle_t buttonSemaphore;
|
SemaphoreHandle_t buttonSemaphore;
|
||||||
@ -56,13 +51,13 @@ void sendButtonStatus(void *pvParameters)
|
|||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
xSemaphoreTake(buttonSemaphore, portMAX_DELAY);
|
xSemaphoreTake(buttonSemaphore, portMAX_DELAY);
|
||||||
transmitted_data_t sensor{abs((int16_t)ID), OPEN_CLOSE};
|
rf_transmitted_data_t sensor{id, RFST_OPEN_CLOSE};
|
||||||
sensor.value_1 = getBatteryLevelCharge() * 100;
|
sensor.value_1 = getBatteryLevelCharge() * 100;
|
||||||
sensor.value_2 = digitalRead(PD2) ? OPEN : CLOSE; // Normally closed.
|
sensor.value_2 = digitalRead(PD2) ? OPEN : CLOSE; // Normally closed.
|
||||||
// sensor.value_2 = digitalRead(PD2) ? CLOSE : OPEN; // Normally open.
|
// sensor.value_2 = digitalRead(PD2) ? CLOSE : OPEN; // Normally open.
|
||||||
radio.powerUp();
|
radio.powerUp();
|
||||||
radio.flush_tx();
|
radio.flush_tx();
|
||||||
radio.write(&sensor, sizeof(transmitted_data_t));
|
radio.write(&sensor, sizeof(rf_transmitted_data_t));
|
||||||
radio.powerDown();
|
radio.powerDown();
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
@ -82,6 +77,26 @@ float getBatteryLevelCharge()
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loadConfig()
|
||||||
|
{
|
||||||
|
cli();
|
||||||
|
if (EEPROM.read(511) == 254)
|
||||||
|
EEPROM.get(0, id);
|
||||||
|
else
|
||||||
|
saveConfig();
|
||||||
|
delay(50);
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveConfig()
|
||||||
|
{
|
||||||
|
cli();
|
||||||
|
EEPROM.write(511, 254);
|
||||||
|
EEPROM.put(0, id);
|
||||||
|
delay(50);
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
|
||||||
ISR(INT0_vect)
|
ISR(INT0_vect)
|
||||||
{
|
{
|
||||||
cli();
|
cli();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user