Compare commits

..

10 Commits

Author SHA1 Message Date
9be9ccf044 renable display at hour mark
break out of cal loop
2023-10-12 16:02:32 +02:00
70f0f6e34c unblank display only on button release 2023-10-12 15:35:11 +02:00
71969143a5 add display blanking cli option 2023-10-12 15:34:12 +02:00
dcc3669850 fix some compiler warnings 2023-10-12 14:57:59 +02:00
afeaa9f5a7 reformat source in uvosstyle 2023-10-12 14:56:11 +02:00
9f8b9059f9 add missing files, support display blanking 2023-10-12 14:54:29 +02:00
3fc72514a4 increase cmake version 2023-10-12 14:53:47 +02:00
be10365d9f reformat 2023-10-12 14:38:53 +02:00
1d75a5bc77 Cleanup changes 2023-04-03 18:16:58 +02:00
e268d49c48 update to new reciver type 2023-04-03 01:27:03 +02:00
13 changed files with 989 additions and 628 deletions

View File

@ -1,7 +1,8 @@
#include "CL56.h" #include "CL56.h"
#include <avr/interrupt.h>
DualCl56::DualCl56(ShiftReg<16>* shiftReg): DualCl56::DualCl56(ShiftReg<16>* shiftReg):
_shiftReg(shiftReg) _shiftReg(shiftReg)
{ {
} }
@ -9,8 +10,14 @@ _shiftReg(shiftReg)
void DualCl56::tick() void DualCl56::tick()
{ {
++_currentLit; ++_currentLit;
if(_currentLit > 7)_currentLit = 0; if(_currentLit > 7)
unsigned char bits[2] = {0b10000000>>_currentLit, ~(_segments[_currentLit])}; _currentLit = 0;
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));
} }
@ -168,3 +175,20 @@ 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 @@ class DualCl56
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,13 +72,16 @@ class DualCl56
ShiftReg<16>* _shiftReg; ShiftReg<16>* _shiftReg;
public: bool _blank = false;
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,11 +2,12 @@
## 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

85
WirelessRelay.cpp Normal file
View File

@ -0,0 +1,85 @@
#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;
}

27
WirelessRelay.h Normal file
View File

@ -0,0 +1,27 @@
#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

90
dht11.cpp Normal file
View File

@ -0,0 +1,90 @@
#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 Normal file
View File

@ -0,0 +1,24 @@
#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;
};

9
item.cpp Normal file
View File

@ -0,0 +1,9 @@
#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 Normal file
View File

@ -0,0 +1,14 @@
#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,17 +18,19 @@
#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 "HELO " #define welcomeString "HELOJANA"
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);
@ -55,28 +57,41 @@ volatile bool ringging = false;
char buffer[SNPRINTF_BUFFER_SIZE]; char buffer[SNPRINTF_BUFFER_SIZE];
volatile bool sensorsPaused = true; volatile bool sensorsPaused = false;
volatile bool relaySetting = false; volatile bool relaySetting = false;
volatile uint8_t timer = 0; volatile uint8_t timer = 0;
volatile uint8_t displayDevider = 1;
ISR(INT1_vect) ISR(TIMER1_COMPA_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)) ) writePin(&PORTD, PD4, true); if(ringging && ((timer % 4 == 0 && timer < 128) || (timer > 128 && timer % 16 == 0)))
else writePin(&PORTD, PD4, false); writePin(&PORTD, PD4, true);
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)
@ -88,10 +103,17 @@ 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(++alm > 3) alm = 0; if(!ringging)
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 )
{ {
@ -113,9 +135,12 @@ 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) serial->write_p(PSTR(" TEMPERATURE: ")); if(sensor.type == 1)
else if(sensor.type == 2) serial->write_p(PSTR(" HUMIDITY: ")); serial->write_p(PSTR(" TEMPERATURE: "));
else serial->write_p(PSTR(" FIELD: ")); else if(sensor.type == 2)
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');
} }
@ -139,9 +164,11 @@ void packetHandler(uint32_t packet, void* data)
found = true; found = true;
} }
} }
if(!found) sensors.push_back(sensor); if(!found)
sensors.push_back(sensor);
if(!sensorsPaused) printSensor(sensor, serial); if(!sensorsPaused)
printSensor(sensor, serial);
} }
void reciverError(uint8_t code, void* userData) void reciverError(uint8_t code, void* userData)
@ -157,19 +184,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"
beep : Test buzzer.\n\ "display [on/off] : blank or unblank the display\n"
list : List sensors.\n")); "beep : Test buzzer.\n"
"list : List sensors.\n"));
} }
int freeRAM() int freeRAM()
{ {
extern int __heap_start, *__brkval; extern int __heap_start, *__brkval;
@ -189,7 +216,8 @@ 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, time.min, time.sec); snprintf(buffer, SNPRINTF_BUFFER_SIZE, "%04u.%02u.%02u %02u:%02u:%02u\n", time.year, time.month, time.day, time.hour,
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)
@ -202,13 +230,21 @@ 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 = {atoi(sec),atoi(min),atoi(hour),atoi(day),atoi(mon),atoi(year)}; DS1302::Timeval time = {static_cast<uint8_t>(atoi(sec)),
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 serial->write_p(PSTR("usage: set [yyyy] [mm] [dd] [hh] [mm] [ss]\n")); else
{
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)
{ {
@ -222,8 +258,11 @@ 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) printSensor(sensors->at(i), serial); for(uint8_t i = 0; i < sensors->count(); ++i)
printSensor(sensors->at(i), serial);
serial->write('\n'); serial->write('\n');
} }
else if(strcmp(token, "erase") == 0) else if(strcmp(token, "erase") == 0)
@ -246,6 +285,38 @@ 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"));
@ -258,7 +329,10 @@ void serialDispatch(Serial* serial, SVector<Sensor, MAX_SENSORS>* sensors)
{ {
printHelp(serial); printHelp(serial);
} }
else serial->write_p(PSTR("Not a valid command\n")); else
{
serial->write_p(PSTR("Not a valid command\n"));
}
} }
} }
} }
@ -296,7 +370,8 @@ 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 || sensors[displaying-2].type == 2 ? DualCl56::DP_G : 0); display.setString(buffer, sensors[displaying-DPY_FIXED_ITEMS].type == 1
|| sensors[displaying-2].type == 2 ? DualCl56::DP_G : 0);
} }
} }
@ -327,17 +402,17 @@ void setAlarm(DS1302::Timeval* alarm, uint8_t leadingSegment = 0)
int main() int main()
{ {
DDRB = (1 << PB1) | ( 1 << PB2) | ( 1 << PB3) | ( 1 << PB4) | ( 1 << PB5); DDRB |= (1 << PB1) | ( 1 << PB2) | ( 1 << PB3);
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; TCCR2B = 1<<CS22 | 1<<CS20;
TIMSK2 = 1; TIMSK2 = 1;
TCCR1B = 1<<CS10; TCCR1B = 1<<CS10;
EICRA = 1<<ISC10; EICRA = 1<<ISC10;
EIMSK = 1<<INT1;
sei(); sei();
@ -350,40 +425,26 @@ 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(1000); _delay_ms(500);
sensor.read(); sensor.read();
#endif #endif
W433DataReciver reciver(&PIND, PD3, &TCNT1, &TIFR1, &packetHandler, reinterpret_cast<void*>(&serial), &reciverError); //enable interrupt
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;
@ -391,7 +452,9 @@ int main()
uint16_t i = 0; uint16_t i = 0;
#ifdef HAS_TRANSMITTER
bool oldRelaySetting = false; bool oldRelaySetting = false;
#endif
while(true) while(true)
{ {
@ -437,12 +500,13 @@ 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(time.hour == alarmB.hour && time.min == alarmB.min && time.sec == 0) if((alm & almB) && time.hour == alarmB.hour && time.min == alarmB.min && time.sec == 0)
{ {
#ifdef HAS_TRANSMITTER #ifdef HAS_TRANSMITTER
relay.setValue(true); relay.setValue(true);
@ -451,20 +515,37 @@ int main()
#endif #endif
} }
#ifdef HAS_RECIVER
serialDispatch(&serial, &sensors); serialDispatch(&serial, &sensors);
#ifdef HAS_RECIVER
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(1000); _delay_ms(500);
} }
#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 Executable file → Normal 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) //I have seen worse interrupt sintax ISR(USART_RX_vect)
{ {
rxBuffer.write(UDR0); rxBuffer.write(UDR0);
if(serialFlowControl && !stopped && rxBuffer.remainingCapacity() < 32) if(serialFlowControl && !stopped && rxBuffer.remainingCapacity() < 32)
@ -125,4 +125,7 @@ void Serial::flush()
rxBuffer.flush(); rxBuffer.flush();
} }
void Serial::setTerminator(char terminator){_terminator = terminator;} void Serial::setTerminator(char terminator)
{
_terminator = terminator;
}