/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
*/
/* Copyright (c) 2015 King Kévin */
/* the spark counter transmits electricity measurements over radio
* the electricity measurements (voltage, current, power, energy) are query everry second from a peacefair PZEM-004 power meter
* they are then transmitted using an nRF2L01+ transceiver
*/
#include // Standard Integer Types
#include // Standard IO facilities
#include // General utilities
#include // Boolean
#include // Strings
#include // AVR device-specific IO definitions
#include // Convenience functions for busy-wait delay loops
#include // Interrupts
#include // Watchdog timer handling
#include // Program Space Utilities
#include // Power Management and Sleep Modes
#include // EEPROM handling
#include // CRC Computations
#include "main.h" // main definitions
#include "usart.h" // basic USART functions
#include "nrf24.h" // nRF24L01 functions
/* variables */
bool query_pzem004 = false; // flag to query the PZEM-004 power meter
volatile uint8_t timer_seconds = 0; // how many seconds have passed
/* disable watchdog when booting */
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
void wdt_init(void)
{
MCUSR = 0;
wdt_disable();
return;
}
/* initialize GPIO */
void io_init(void)
{
/* use UART as terminal */
usart_init();
stdout = &usart_output;
stdin = &usart_input;
/* use nRF24L01 */
nrf24_init();
/* set up timer 1 to regularly wake up and request data from the power meter */
TCCR1B |= (0<=7) { // wait for an answer to be available
action = true; // an action is performed
//printf(PSTR("got value\n"));
// store answer
uint8_t answer[7];
for (uint8_t i=0; i