Skip to content

Commit

Permalink
rename constants and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
gitdode committed Sep 14, 2023
1 parent d77edd7 commit ed20073
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions thermidity-avr/thermidity.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@
#include "usart.h"

/* Measure and average temperature and relative humidity every ~32 seconds */
#define MEASURE_SECS 4 // should be a power of 2 to avoid division
#define MEASURE_INTS 4 // should be a power of 2 to avoid division
/* Display should not be updated more frequently than once every 180 seconds */
#define DISP_UPD_SECS 36
#define DISP_UPD_INTS 36
/* Number of fast updates until a full update is done to avoid ghosting */
#define DISP_MAX_FAST 9

static volatile uint8_t secs = 36;
/* 1 int = 8 seconds */
static volatile uint8_t ints = DISP_UPD_INTS;

static uint8_t updates = DISP_MAX_FAST + 1;

ISR(WDT_vect) {
secs++;
ints++;
}

EMPTY_INTERRUPT(ADC_vect);
Expand Down Expand Up @@ -111,7 +112,7 @@ static void initWatchdog(void) {
wdt_reset();
// watchdog change enable
WDTCSR |= (1 << WDCE) | (1 << WDE);
// enable interrupt, disable system reset, bark every 1 seconds
// enable interrupt, disable system reset, bark every 8 seconds
WDTCSR = (1 << WDIE) | (0 << WDE) | (1 << WDP3) | (1 << WDP0);
}

Expand Down Expand Up @@ -199,11 +200,9 @@ int main(void) {

// enable global interrupts
sei();

// _delay_ms(1000);

while (true) {
if (secs % MEASURE_SECS == 0) {
if (ints % MEASURE_INTS == 0) {
powerOnSensors();
// give the humidity sensor time to settle
_delay_ms(100);
Expand All @@ -212,8 +211,8 @@ int main(void) {
disableADC();
powerOffSensors();

if (secs >= DISP_UPD_SECS) {
secs = 0;
if (ints >= DISP_UPD_INTS) {
ints = 0;

// measured battery voltage is /5 by voltage divider
if (getMVBat() < BAT_LOW / 5) {
Expand Down

0 comments on commit ed20073

Please sign in to comment.