reformat
This commit is contained in:
		
							parent
							
								
									1d75a5bc77
								
							
						
					
					
						commit
						be10365d9f
					
				
					 4 changed files with 241 additions and 201 deletions
				
			
		
							
								
								
									
										89
									
								
								main.cpp
									
										
									
									
									
								
							
							
						
						
									
										89
									
								
								main.cpp
									
										
									
									
									
								
							|  | @ -29,6 +29,8 @@ | ||||||
| #define welcomeString "HELOJANA" | #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,19 +57,27 @@ 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(TIMER1_COMPA_vect) | ISR(TIMER1_COMPA_vect) | ||||||
| { | { | ||||||
|  | 	if(displayDevider > 1) | ||||||
|  | 	{ | ||||||
|  | 		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))) | ||||||
|  | @ -90,7 +100,7 @@ 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) | ||||||
| 			{ | 			{ | ||||||
|  | @ -122,9 +132,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'); | ||||||
| } | } | ||||||
|  | @ -148,9 +161,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) | ||||||
|  | @ -166,16 +181,16 @@ 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\ | 		"beep                                 :  Test buzzer.\n" | ||||||
|                 list                                 :  List sensors.\n")); | 		"list                                 :  List sensors.\n")); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -232,8 +247,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) | ||||||
|  | @ -268,7 +286,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")); | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | @ -338,11 +359,12 @@ 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; | ||||||
|  | @ -366,12 +388,12 @@ int main() | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| 	display.setString(welcomeString); | 	display.setString(welcomeString); | ||||||
| 	_delay_ms(1000); | 	_delay_ms(500); | ||||||
| 
 | 
 | ||||||
| #ifdef HAS_DHT | #ifdef HAS_DHT | ||||||
| 	Dht11 sensor(&PORTD, &PIND, &DDRD, PD2); | 	Dht11 sensor(&PORTD, &PIND, &DDRD, PD2); | ||||||
| 	sensor.read(); | 	sensor.read(); | ||||||
| 	_delay_ms(1000); | 	_delay_ms(500); | ||||||
| 	sensor.read(); | 	sensor.read(); | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | @ -434,12 +456,12 @@ int main() | ||||||
| 		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); | ||||||
|  | @ -449,6 +471,7 @@ int main() | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		serialDispatch(&serial, &sensors); | 		serialDispatch(&serial, &sensors); | ||||||
|  | 
 | ||||||
| #ifdef HAS_RECIVER | #ifdef HAS_RECIVER | ||||||
| 		if(deleteDate != time.day) | 		if(deleteDate != time.day) | ||||||
| 		{ | 		{ | ||||||
|  | @ -456,9 +479,23 @@ int main() | ||||||
| 			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) | ||||||
|  | 			displayDevider = 16; | ||||||
|  | 		else | ||||||
|  | 			displayDevider = 1; | ||||||
|  | 
 | ||||||
|  | 		if(time.hour == 0 && time.min == 0 && time.sec == timeOffsetSeconds+10) | ||||||
|  | 		{ | ||||||
|  | 			DS1302::Timeval timeSet = time; | ||||||
|  | 			timeSet.sec = 10; | ||||||
|  | 			clock.setTime(timeSet); | ||||||
|  | 			display.setString("CAL     "); | ||||||
|  | 			_delay_ms(500); | ||||||
|  | 		} | ||||||
| 		++i; | 		++i; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										0
									
								
								ringbuffer.h
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										0
									
								
								ringbuffer.h
									
										
									
									
									
										
										
										Executable file → Normal 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; | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue