Compare commits

..

No commits in common. "master" and "99ba609f6fd8a32c1baf8c9fdc0b9d3e21ef48b4" have entirely different histories.

13 changed files with 627 additions and 988 deletions

View file

@ -1,8 +1,7 @@
#include "CL56.h" #include "CL56.h"
#include <avr/interrupt.h>
DualCl56::DualCl56(ShiftReg<16>* shiftReg): DualCl56::DualCl56(ShiftReg<16>* shiftReg):
_shiftReg(shiftReg) _shiftReg(shiftReg)
{ {
} }
@ -10,14 +9,8 @@ DualCl56::DualCl56(ShiftReg<16>* shiftReg):
void DualCl56::tick() void DualCl56::tick()
{ {
++_currentLit; ++_currentLit;
if(_currentLit > 7) if(_currentLit > 7)_currentLit = 0;
_currentLit = 0; unsigned char bits[2] = {0b10000000>>_currentLit, ~(_segments[_currentLit])};
unsigned char bits[2] = {static_cast<unsigned char>(0b10000000 >> _currentLit),
static_cast<unsigned char>(~(_segments[_currentLit]))
};
if(!_blank)
_shiftReg->write(reinterpret_cast<unsigned char*>(&bits)); _shiftReg->write(reinterpret_cast<unsigned char*>(&bits));
} }
@ -175,20 +168,3 @@ void DualCl56::setSegments(const uint8_t segments, const uint8_t place)
{ {
_segments[place] = segments; _segments[place] = segments;
} }
void DualCl56::setBlank(bool blankIn)
{
_blank = blankIn;
if(_blank)
{
cli();
_shiftReg->clear();
_shiftReg->clear();
sei();
}
}
bool DualCl56::getBlank()
{
return _blank;
}

11
CL56.h
View file

@ -5,7 +5,7 @@
class DualCl56 class DualCl56
{ {
public: public:
static constexpr uint8_t SEG_A = 0b10000000; static constexpr uint8_t SEG_A = 0b10000000;
static constexpr uint8_t SEG_B = 0b01000000; static constexpr uint8_t SEG_B = 0b01000000;
@ -27,7 +27,7 @@ public:
static constexpr uint8_t DP_G = 0b01000000; static constexpr uint8_t DP_G = 0b01000000;
static constexpr uint8_t DP_H = 0b10000000; static constexpr uint8_t DP_H = 0b10000000;
private: private:
static constexpr uint8_t ZERO = SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F; static constexpr uint8_t ZERO = SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F;
static constexpr uint8_t ONE = SEG_B | SEG_C; static constexpr uint8_t ONE = SEG_B | SEG_C;
@ -72,16 +72,13 @@ private:
ShiftReg<16>* _shiftReg; ShiftReg<16>* _shiftReg;
bool _blank = false; public:
public:
DualCl56(ShiftReg<16>* shiftReg); DualCl56(ShiftReg<16>* shiftReg);
void tick(); void tick();
void setBlank(bool blank);
bool getBlank();
void setString(const char* string, const uint8_t dp = 0); void setString(const char* string, const uint8_t dp = 0);
void setSegments(const uint8_t segments, const uint8_t place); void setSegments(const uint8_t segments, const uint8_t place);
}; };

View file

@ -2,12 +2,11 @@
## Adjust the settings according to your board. ## Adjust the settings according to your board.
## The settings here work for the Arduino Uno, Rev. 3. ## The settings here work for the Arduino Uno, Rev. 3.
# CMake version
cmake_minimum_required(VERSION 3.20)
# Project name # Project name
project(SensorDisplay) project(SensorDisplay)
# CMake version
cmake_minimum_required(VERSION 2.6)
# Options # Options
# Adjust to your board # Adjust to your board

View file

@ -1,85 +0,0 @@
#include"WirelessRelay.h"
#include <avr/io.h>
#include <string.h>
volatile unsigned char *_port = &PORTD;
unsigned char _pin = PD2;
void WirelessRelay::sendId()
{
writePin(_port,_pin,true);
_delay_us(SMALL_TIME);
writePin(_port,_pin,false);
_delay_us(LARGE_TIME);
for(short i = 0; i<10; i++)
{
sendBit( id & 1 << (15 - i) );
}
}
void WirelessRelay::sendBit(const bool in)
{
switch(in)
{
case true:
//Der Code fuer '0'
writePin(_port,_pin,true);
_delay_us(SMALL_TIME);
writePin(_port,_pin,false);
_delay_us(LARGE_TIME);
writePin(_port,_pin,true);
_delay_us(SMALL_TIME);
writePin(_port,_pin,false);
_delay_us(LARGE_TIME);
break;
case false:
//Der Code fuer '1'
writePin(_port,_pin,true);
_delay_us(LARGE_TIME);
writePin(_port,_pin,false);
_delay_us(SMALL_TIME);
writePin(_port,_pin,true);
_delay_us(SMALL_TIME);
writePin(_port,_pin,false);
_delay_us(LARGE_TIME);
break;
}
}
void WirelessRelay::sync()
{
writePin(_port,_pin,false);
_delay_us(SMALL_TIME*31);
}
void WirelessRelay::setValue(const uint8_t value)
{
lastValue = value;
for(short z = 0; z<10; z++)
{
sendId();
sendBit(value);
sendBit(!value);
sync();
}
}
void WirelessRelay::resend()
{
setValue(lastValue);
}
WirelessRelay::WirelessRelay(const uint16_t idIn, char nameIn[])
{
id = idIn;
setName(nameIn);
type = 0;
}
WirelessRelay::WirelessRelay(const Item& item)
{
Item::operator=(item);
type = 0;
}

View file

@ -1,27 +0,0 @@
#ifndef RF433_H
#define RF433_H
#include<util/delay.h>
#include"writepin.h"
#include "item.h"
class WirelessRelay: public Item
{
public:
static constexpr uint16_t LARGE_TIME = 750;
static constexpr uint8_t SMALL_TIME = 250;
static constexpr uint16_t MAX_NAME_LENGTH = 16;
private:
void sendBit(const bool i);
void sync();
void sendId();
public:
WirelessRelay(const uint16_t idIn, char nameIn[]);
WirelessRelay(const Item& item);
void setValue(const uint8_t value);
void resend();
};
#endif

View file

@ -1,90 +0,0 @@
#include "dht11.h"
Dht11::Dht11(volatile unsigned char * const port, volatile unsigned char * const inPort,
volatile unsigned char * const port_ctl, const unsigned char pin): _port(port), _port_ctl(port_ctl), _inPort(inPort),
_pin(pin)
{}
uint8_t Dht11::read()
{
// BUFFER TO RECEIVE
uint8_t bits[5];
uint8_t cnt = 7;
uint8_t idx = 0;
// EMPTY BUFFER
for (uint8_t i=0; i< 5; i++) bits[i] = 0;
// REQUEST SAMPLE
setDirection(_port_ctl, _pin, true);
writePin(_port, _pin, false);
_delay_ms(18);
writePin(_port, _pin, true);
setDirection(_port_ctl, _pin, false);
_delay_us(42);
// ACKNOWLEDGE or TIMEOUT
unsigned int loopCnt = LOOP_TIMEOUT_COUNT;
while(!readPin(_inPort, _pin)) if (loopCnt-- == 0) return 1;
loopCnt = LOOP_TIMEOUT_COUNT;
while(readPin(_inPort, _pin) ) if (loopCnt-- == 0) return 2;
PORTD |= 1 << PD1;
PORTD &= ~(1 << PD1);
PORTD |= 1 << PD1;
PORTD &= ~(1 << PD1);
// READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
for (uint8_t i=0; i<40; i++)
{
loopCnt = LOOP_TIMEOUT_COUNT;
while(!readPin(_inPort, _pin))
if (loopCnt-- == 0)
{
PORTD |= 1 << PD1;
return 3;
}
loopCnt = 0;
while(readPin(_inPort, _pin))
{
_delay_us(10);
if (loopCnt++ > LOOP_TIMEOUT_SMALL_COUNT) return 4;
}
if( loopCnt > BIT_COUNT )
{
PORTD |= 1 << PD1;
PORTD &= ~(1 << PD1);
bits[idx] |= (1 << cnt);
}
if (cnt == 0) // next byte?
{
cnt = 7; // restart at MSB
idx++; // next byte!
}
else cnt--;
}
uint8_t sum;
if constexpr(DHT22) sum= bits[0] + bits[1] + bits[2] + bits[3];
else sum = bits[0] + bits[2];
if((bits[4] == sum && sum != 0) || true)
{
if constexpr(DHT22)
{
humidity = (static_cast<uint16_t>(bits[0]) << 8) + bits[1];
temperature = (static_cast<uint16_t>((bits[2] & 0b01111111) << 8) + bits[3]);
if(bits[2] & 0b10000000) temperature=temperature*-1;
}
else
{
humidity = bits[0]*10;
temperature = bits[2]*10;
}
return 0;
}
else return 5;
}

24
dht11.h
View file

@ -1,24 +0,0 @@
#pragma once
#include <stdint.h>
#include<util/delay.h>
#include "writepin.h"
class Dht11
{
static constexpr uint16_t LOOP_TIMEOUT_COUNT = (10000.0 / 16000000.0)*F_CPU;
static constexpr uint8_t LOOP_TIMEOUT_SMALL_COUNT = (100.0 / 16000000.0)*F_CPU;
static constexpr uint8_t BIT_COUNT = 5;//(6.0 / 16000000.0)*F_CPU;
static constexpr bool DHT22 = true;
volatile unsigned char * const _port;
volatile unsigned char * const _port_ctl;
volatile unsigned char * const _inPort;
const unsigned char _pin;
public:
Dht11(volatile unsigned char * const port, volatile unsigned char * const inPort,
volatile unsigned char * const port_ctl, const unsigned char pin);
uint8_t read();
int16_t humidity = 0;
int16_t temperature = 0;
};

View file

@ -1,9 +0,0 @@
#include "item.h"
#include "string.h"
void Item::setName(const char * const nameN)
{
size_t len = strlen(nameN);
if(len < MAX_NAME_LENGTH)memcpy(name, nameN, len+1);
}

14
item.h
View file

@ -1,14 +0,0 @@
#pragma once
#include <stdint.h>
class Item
{
public:
static constexpr uint16_t MAX_NAME_LENGTH = 16;
bool lastValue = 0;
uint16_t id;
char name[MAX_NAME_LENGTH]="";
uint8_t type = 0;
void setName(const char * const name);
};

209
main.cpp
View file

@ -18,19 +18,17 @@
#include "dht11.h" #include "dht11.h"
#include "WirelessRelay.h" #include "WirelessRelay.h"
#define HAS_DHT //#define HAS_DHT
//#define HAS_TRANSMITTER #define HAS_TRANSMITTER
#define HAS_RECIVER //#define HAS_RECIVER
#define MAX_SENSORS 32 #define MAX_SENSORS 32
#define COMMAND_BUFFER_SIZE 64 #define COMMAND_BUFFER_SIZE 64
#define SNPRINTF_BUFFER_SIZE 96 #define SNPRINTF_BUFFER_SIZE 96
#define welcomeString "HELOJANA" #define welcomeString "HELO "
static constexpr bool bdayMsg = false; static constexpr bool bdayMsg = false;
static constexpr int timeOffsetSeconds = 6;
void buttonHandler(uint8_t index, uint8_t type, void* data); void buttonHandler(uint8_t index, uint8_t type, void* data);
SVector<Sensor, MAX_SENSORS> sensors; SVector<Sensor, MAX_SENSORS> sensors;
ShiftReg<16> shiftReg(&PORTB, PB3, PB2, PB1); ShiftReg<16> shiftReg(&PORTB, PB3, PB2, PB1);
@ -57,41 +55,28 @@ volatile bool ringging = false;
char buffer[SNPRINTF_BUFFER_SIZE]; char buffer[SNPRINTF_BUFFER_SIZE];
volatile bool sensorsPaused = false; volatile bool sensorsPaused = true;
volatile bool relaySetting = false; volatile bool relaySetting = false;
volatile uint8_t timer = 0; volatile uint8_t timer = 0;
volatile uint8_t displayDevider = 1;
ISR(TIMER1_COMPA_vect) ISR(INT1_vect)
{ {
TIMSK2 = 0;
W433DataReciver::staticInterrupt(); W433DataReciver::staticInterrupt();
writePin(&PORTB, PB5, !readPin(&PORTB, PB5));
TIMSK2 = 1;
} }
ISR(TIMER2_OVF_vect) ISR(TIMER2_OVF_vect)
{ {
if(timer % displayDevider == 0)
display.tick(); display.tick();
buttons.tick(); buttons.tick();
if(ringging && ((timer % 4 == 0 && timer < 128) || (timer > 128 && timer % 16 == 0))) if(ringging && ((timer % 4 == 0 && timer < 128) || (timer > 128 && timer % 16 == 0)) ) writePin(&PORTD, PD4, true);
writePin(&PORTD, PD4, true); else writePin(&PORTD, PD4, false);
else
writePin(&PORTD, PD4, false);
++timer; ++timer;
} }
void buttonHandler(uint8_t index, uint8_t type, void* data) void buttonHandler(uint8_t index, uint8_t type, void* data)
{ {
if(display.getBlank() && type == Buttons::RELEASED)
{
display.setBlank(false);
return;
}
if(!setting) if(!setting)
{ {
if(index == 0 && type == Buttons::RELEASED) if(index == 0 && type == Buttons::RELEASED)
@ -103,17 +88,10 @@ void buttonHandler(uint8_t index, uint8_t type, void* data)
{ {
relaySetting = !relaySetting; relaySetting = !relaySetting;
} }
else if(index == 1 && type == Buttons::RELEASED) else if(index == 1 && type == Buttons::RELEASED )
{ {
if(!ringging) if(!ringging) if(++alm > 3) alm = 0;
{ else ringging = false;
if(++alm > 3)
alm = 0;
}
else
{
ringging = false;
}
} }
else if(index == 1 && type == Buttons::LONG_PRESSED ) else if(index == 1 && type == Buttons::LONG_PRESSED )
{ {
@ -135,12 +113,9 @@ void printSensor(const Sensor& sensor, Serial* serial)
serial->write_p(PSTR(" ID: ")); serial->write_p(PSTR(" ID: "));
serial->write(sensor.id); serial->write(sensor.id);
if(sensor.type == 1) if(sensor.type == 1) serial->write_p(PSTR(" TEMPERATURE: "));
serial->write_p(PSTR(" TEMPERATURE: ")); else if(sensor.type == 2) serial->write_p(PSTR(" HUMIDITY: "));
else if(sensor.type == 2) else serial->write_p(PSTR(" FIELD: "));
serial->write_p(PSTR(" HUMIDITY: "));
else
serial->write_p(PSTR(" FIELD: "));
serial->write(sensor.field); serial->write(sensor.field);
serial->putChar('\n'); serial->putChar('\n');
} }
@ -164,11 +139,9 @@ void packetHandler(uint32_t packet, void* data)
found = true; found = true;
} }
} }
if(!found) if(!found) sensors.push_back(sensor);
sensors.push_back(sensor);
if(!sensorsPaused) if(!sensorsPaused) printSensor(sensor, serial);
printSensor(sensor, serial);
} }
void reciverError(uint8_t code, void* userData) void reciverError(uint8_t code, void* userData)
@ -184,19 +157,19 @@ void reciverError(uint8_t code, void* userData)
inline static void printHelp(Serial* serial) inline static void printHelp(Serial* serial)
{ {
serial->write_p(PSTR("Available Commands: \n" serial->write_p(PSTR("Available Commands: \n\
"help : Show this prompt.\n" help : Show this prompt.\n\
"date : Show current date and time.\n" date : Show current date and time.\n\
"set [yyyy] [mm] [dd] [hh] [mm] [ss] : Show current date and time.\n" set [yyyy] [mm] [dd] [hh] [mm] [ss] : Show current date and time.\n\
"pause : pause sensor output.\n" pause : pause sensor output.\n\
"resume : resume sensor output.\n" resume : resume sensor output.\n\
"dump : Dump epprom.\n" dump : Dump epprom.\n\
"free : Show free ram.\n" free : Show free ram.\n\
"display [on/off] : blank or unblank the display\n" beep : Test buzzer.\n\
"beep : Test buzzer.\n" list : List sensors.\n"));
"list : List sensors.\n"));
} }
int freeRAM() int freeRAM()
{ {
extern int __heap_start, *__brkval; extern int __heap_start, *__brkval;
@ -216,8 +189,7 @@ void serialDispatch(Serial* serial, SVector<Sensor, MAX_SENSORS>* sensors)
if(strcmp(token, "date") == 0) if(strcmp(token, "date") == 0)
{ {
DS1302::Timeval time = clock.getTime(); DS1302::Timeval time = clock.getTime();
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "%04u.%02u.%02u %02u:%02u:%02u\n", time.year, time.month, time.day, time.hour, snprintf(buffer, SNPRINTF_BUFFER_SIZE, "%04u.%02u.%02u %02u:%02u:%02u\n", time.year, time.month, time.day, time.hour, time.min, time.sec);
time.min, time.sec);
serial->write(buffer, SNPRINTF_BUFFER_SIZE); serial->write(buffer, SNPRINTF_BUFFER_SIZE);
} }
else if(strcmp(token, "set") == 0) else if(strcmp(token, "set") == 0)
@ -230,21 +202,13 @@ void serialDispatch(Serial* serial, SVector<Sensor, MAX_SENSORS>* sensors)
char* sec = strtok(NULL, " \n"); char* sec = strtok(NULL, " \n");
if(year != NULL && mon != NULL && day != NULL && hour != NULL && min != NULL && sec != NULL) if(year != NULL && mon != NULL && day != NULL && hour != NULL && min != NULL && sec != NULL)
{ {
DS1302::Timeval time = {static_cast<uint8_t>(atoi(sec)), DS1302::Timeval time = {atoi(sec),atoi(min),atoi(hour),atoi(day),atoi(mon),atoi(year)};
static_cast<uint8_t>(atoi(min)),
static_cast<uint8_t>(atoi(hour)),
static_cast<uint8_t>(atoi(day)),
static_cast<uint8_t>(atoi(mon)),
static_cast<uint8_t>(atoi(year))};
clock.setTime(time); clock.setTime(time);
serial->write_p(PSTR("date and time set\n")); serial->write_p(PSTR("date and time set\n"));
display.setString("SET "); display.setString("SET ");
_delay_ms(1000); _delay_ms(1000);
} }
else else serial->write_p(PSTR("usage: set [yyyy] [mm] [dd] [hh] [mm] [ss]\n"));
{
serial->write_p(PSTR("usage: set [yyyy] [mm] [dd] [hh] [mm] [ss]\n"));
}
} }
else if(strcmp(token, "pause") == 0) else if(strcmp(token, "pause") == 0)
{ {
@ -258,11 +222,8 @@ void serialDispatch(Serial* serial, SVector<Sensor, MAX_SENSORS>* sensors)
} }
else if(strcmp(token, "list") == 0) else if(strcmp(token, "list") == 0)
{ {
serial->write(sensors->count());
serial->putChar(' ');
serial->write_p(PSTR("Sensors:\n")); serial->write_p(PSTR("Sensors:\n"));
for(uint8_t i = 0; i < sensors->count(); ++i) for(uint8_t i = 0; i < sensors->count(); ++i) printSensor(sensors->at(i), serial);
printSensor(sensors->at(i), serial);
serial->write('\n'); serial->write('\n');
} }
else if(strcmp(token, "erase") == 0) else if(strcmp(token, "erase") == 0)
@ -285,38 +246,6 @@ void serialDispatch(Serial* serial, SVector<Sensor, MAX_SENSORS>* sensors)
serial->write(freeRAM()); serial->write(freeRAM());
serial->write_p(PSTR(" Bytes.\n")); serial->write_p(PSTR(" Bytes.\n"));
} }
else if(strcmp(token, "display") == 0)
{
char* on = strtok(NULL, " \n");
if(on && strcmp(on, "on") == 0)
{
if(display.getBlank())
{
serial->write_p(PSTR("Display unblanked\n"));
display.setBlank(false);
}
else
{
serial->write_p(PSTR("Display already unblanked\n"));
}
}
else if(on && strcmp(on, "off") == 0)
{
if(!display.getBlank())
{
serial->write_p(PSTR("Display blanked\n"));
display.setBlank(true);
}
else
{
serial->write_p(PSTR("Display already blanked\n"));
}
}
else
{
serial->write_p(PSTR("usage: display [on/off]\n"));
}
}
else if(strcmp(token, "beep") == 0) else if(strcmp(token, "beep") == 0)
{ {
serial->write_p(PSTR("Beeping\n")); serial->write_p(PSTR("Beeping\n"));
@ -329,10 +258,7 @@ void serialDispatch(Serial* serial, SVector<Sensor, MAX_SENSORS>* sensors)
{ {
printHelp(serial); printHelp(serial);
} }
else else serial->write_p(PSTR("Not a valid command\n"));
{
serial->write_p(PSTR("Not a valid command\n"));
}
} }
} }
} }
@ -370,8 +296,7 @@ void displayItems(const DS1302::Timeval& time, int16_t temp, int16_t humid)
sensors[displaying-DPY_FIXED_ITEMS].id, sensors[displaying-DPY_FIXED_ITEMS].id,
sensors[displaying-DPY_FIXED_ITEMS].type, sensors[displaying-DPY_FIXED_ITEMS].type,
sensors[displaying-DPY_FIXED_ITEMS].field); sensors[displaying-DPY_FIXED_ITEMS].field);
display.setString(buffer, sensors[displaying-DPY_FIXED_ITEMS].type == 1 display.setString(buffer, sensors[displaying-DPY_FIXED_ITEMS].type == 1 || sensors[displaying-2].type == 2 ? DualCl56::DP_G : 0);
|| sensors[displaying-2].type == 2 ? DualCl56::DP_G : 0);
} }
} }
@ -402,17 +327,17 @@ void setAlarm(DS1302::Timeval* alarm, uint8_t leadingSegment = 0)
int main() int main()
{ {
DDRB |= (1 << PB1) | ( 1 << PB2) | ( 1 << PB3); DDRB = (1 << PB1) | ( 1 << PB2) | ( 1 << PB3) | ( 1 << PB4) | ( 1 << PB5);
DDRB |= ( 1 << PB4) | ( 1 << PB5);
DDRD = (1<<PD4) | (1<<PD2); DDRD = (1<<PD4) | (1<<PD2);
PORTD |= (1<<PD6) | (1<<PD7); PORTD |= (1<<PD6) | (1<<PD7);
TCCR2B = 1<<CS22 | 1<<CS20; TCCR2B = 1<<CS22;
TIMSK2 = 1; TIMSK2 = 1;
TCCR1B = 1<<CS10; TCCR1B = 1<<CS10;
EICRA = 1<<ISC10; EICRA = 1<<ISC10;
EIMSK = 1<<INT1;
sei(); sei();
@ -425,26 +350,40 @@ int main()
alm = EEPROM_read_char(0); alm = EEPROM_read_char(0);
uint8_t oldAlm = alm; uint8_t oldAlm = alm;
#ifdef HAS_TRANSMITTER #ifdef HAS_TRANSMITTER
char name[] = "relay"; char name[] = "relay";
WirelessRelay relay(0b1011010001000000, name); WirelessRelay relay(0b1011010001000000, name);
#endif #endif
display.setString(welcomeString);
_delay_ms(500);
#ifdef HAS_DHT #ifdef HAS_DHT
Dht11 sensor(&PORTD, &PIND, &DDRD, PD2); Dht11 sensor(&PORTD, &PIND, &DDRD, PD2);
#endif
if(time.day == 28 && time.month == 5)
{
if constexpr(bdayMsg)
{
display.setString("HAPPY ");
_delay_ms(1000);
display.setString("b-DAY ");
_delay_ms(1000);
display.setString("SASA ");
_delay_ms(1000);
}
}
else
{
display.setString(welcomeString);
_delay_ms(1000);
}
#ifdef HAS_DHT
sensor.read(); sensor.read();
_delay_ms(500); _delay_ms(1000);
sensor.read(); sensor.read();
#endif #endif
//enable interrupt W433DataReciver reciver(&PIND, PD3, &TCNT1, &TIFR1, &packetHandler, reinterpret_cast<void*>(&serial), &reciverError);
TIMSK1 |= 1 << OCIE1A;
OCR1A = W433DataReciver::calculateOverflowRegister(2000, 1);
TCCR1B = 1<<CS10 | 1<<WGM12;
W433DataReciver reciver(&PIND, PD3, &packetHandler, reinterpret_cast<void*>(&serial), &reciverError);
uint8_t deleteDate = 0; uint8_t deleteDate = 0;
@ -452,9 +391,7 @@ int main()
uint16_t i = 0; uint16_t i = 0;
#ifdef HAS_TRANSMITTER
bool oldRelaySetting = false; bool oldRelaySetting = false;
#endif
while(true) while(true)
{ {
@ -500,13 +437,12 @@ int main()
#else #else
displayItems(time, 0, 0); displayItems(time, 0, 0);
#endif #endif
if(time.hour == alarmA.hour && time.min == alarmA.min && time.sec == 0)
if((alm & almA) && time.hour == alarmA.hour && time.min == alarmA.min && time.sec == 0)
{ {
ringging = true; ringging = true;
} }
if((alm & almB) && time.hour == alarmB.hour && time.min == alarmB.min && time.sec == 0) if(time.hour == alarmB.hour && time.min == alarmB.min && time.sec == 0)
{ {
#ifdef HAS_TRANSMITTER #ifdef HAS_TRANSMITTER
relay.setValue(true); relay.setValue(true);
@ -515,37 +451,20 @@ int main()
#endif #endif
} }
serialDispatch(&serial, &sensors);
#ifdef HAS_RECIVER #ifdef HAS_RECIVER
serialDispatch(&serial, &sensors);
if(deleteDate != time.day) if(deleteDate != time.day)
{ {
displaying = 0; displaying = 0;
sensors.clear(); sensors.clear();
deleteDate = time.day; deleteDate = time.day;
display.setString("CLEAR "); display.setString("CLEAR ");
_delay_ms(500); _delay_ms(1000);
} }
#endif #endif
if(time.min == 45 && time.sec == 0)
display.setBlank(true);
else if(time.min == 0 && time.sec == 0)
display.setBlank(false);
if(time.hour == 0 && time.min == 0 && time.sec == timeOffsetSeconds+10)
{
DS1302::Timeval timeSet = time;
timeSet.sec = 10;
clock.setTime(timeSet);
while(clock.getTime().sec <= timeOffsetSeconds+10)
{
display.setString("CAL ");
_delay_ms(500);
}
}
++i; ++i;
} }
return 0; return 0;
} }

0
ringbuffer.h Normal file → Executable file
View file

View file

@ -5,7 +5,7 @@ volatile RingBuffer<SERIAL_BUFFER_SIZE, volatile uint8_t> rxBuffer;
bool stopped = false; bool stopped = false;
ISR(USART_RX_vect) ISR(USART_RX_vect) //I have seen worse interrupt sintax
{ {
rxBuffer.write(UDR0); rxBuffer.write(UDR0);
if(serialFlowControl && !stopped && rxBuffer.remainingCapacity() < 32) if(serialFlowControl && !stopped && rxBuffer.remainingCapacity() < 32)
@ -125,7 +125,4 @@ void Serial::flush()
rxBuffer.flush(); rxBuffer.flush();
} }
void Serial::setTerminator(char terminator) void Serial::setTerminator(char terminator){_terminator = terminator;}
{
_terminator = terminator;
}