|
|
|
#include "sevenseg.h"
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
#include <util/atomic.h>
|
|
|
|
#include <util/delay.h>
|
|
|
|
#include <avr/sleep.h>
|
|
|
|
#include "time_base.h"
|
|
|
|
#include "high_voltage.h"
|
|
|
|
#include "radiation.h"
|
|
|
|
#include "user_interface.h"
|
|
|
|
|
|
|
|
/* globals */
|
|
|
|
volatile bool req_update_display = false;
|
|
|
|
volatile bool is_weak_battery = false;
|
|
|
|
|
|
|
|
static void shutdown_due_to_weak_battery();
|
|
|
|
|
|
|
|
|
|
|
|
void __attribute__((noreturn)) main()
|
|
|
|
{
|
|
|
|
init_user_interface();
|
|
|
|
|
|
|
|
show_loading_screen(0, true);
|
|
|
|
while(1){}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
init_timebase();
|
|
|
|
init_radiation();
|
|
|
|
|
|
|
|
// --- let's go ---
|
|
|
|
sei();
|
|
|
|
|
|
|
|
// this needs interrupts enabled
|
|
|
|
init_high_voltage();
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
_delay_ms(100);
|
|
|
|
|
|
|
|
// check if redraw is needed
|
|
|
|
bool update_display = false;
|
|
|
|
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
|
|
|
update_display = req_update_display;
|
|
|
|
req_update_display = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_display) {
|
|
|
|
show_current_radiation();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_weak_battery) {
|
|
|
|
shutdown_due_to_weak_battery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void __attribute__((noreturn)) shutdown_due_to_weak_battery()
|
|
|
|
{
|
|
|
|
cli();
|
|
|
|
hv_disable();
|
|
|
|
|
|
|
|
show_empty_battery();
|
|
|
|
// try to preserve power; but the display will still drain the battery.
|
|
|
|
// we should probably shut it off too.
|
|
|
|
|
|
|
|
_delay_ms(2000);
|
|
|
|
turn_off_display();
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
sleep_enable();
|
|
|
|
sleep_cpu();
|
|
|
|
}
|
|
|
|
}
|