void Controller::event_cpm_cps_auto(const char *event,const char *value) { if(m_cpm_cps_switch == false) { m_cpm_cps_switch = true; flashstorage_keyval_set("CPMCPSAUTO","true"); tick_item("CPM/CPS Auto",true); } else { m_cpm_cps_switch = false; flashstorage_keyval_set("CPMCPSAUTO","false"); tick_item("CPM/CPS Auto",false); } }
void Controller::event_neverdim(const char *event,const char *value) { if(m_never_dim == false) { flashstorage_keyval_set("NEVERDIM","true"); tick_item("Never Dim" ,true); m_never_dim=true; } else { flashstorage_keyval_set("NEVERDIM","false"); tick_item("Never Dim" ,false); m_never_dim=false; } }
/** * Initialize the system controller. In particular: * - Load settings * - Setup the log interval alarm. */ Controller::Controller() { m_sleeping=false; m_powerup=false; //m_log_interval_seconds = 60*30; m_log_interval_seconds = 0; // default set to zero to save power rtc_clear_alarmed(); rtc_enable_alarm(RTC); m_interval_stored = rtc_get_time(RTC); m_counts_stored = 0; m_alarm_log = false; system_controller = this; m_last_switch_state = true; m_never_dim = false; bool sstate = switch_state(); m_last_switch_state = sstate; m_warning_raised = false; m_dim_off = false; m_cpm_cps_switch = false; m_current_units = 2; m_cpm_cps_threshold = 1100.0; m_cps_cpm_threshold = 1000.0; // Get warning cpm from flash m_warncpm = 0; const char *swarncpm = flashstorage_keyval_get("WARNCPM"); if(swarncpm != 0) { int32_t c; sscanf(swarncpm, "%"PRIu32"", &c); m_warncpm = c; } // Get never dim from flash m_warncpm = -1; const char *sneverdim = flashstorage_keyval_get("NEVERDIM"); if(sneverdim != 0) { if(strcmp(sneverdim,"true") == 0) m_never_dim=true; else m_never_dim=false; } else m_never_dim=false; if(m_never_dim) tick_item("Never Dim" ,true); // Get logging interval from flash const char *sloginter = flashstorage_keyval_get("LOGINTERVAL"); if(sloginter != 0) { int32_t c; sscanf(sloginter, "%"PRIu32"", &c); m_log_interval_seconds = c; } else { // m_log_interval_seconds = 30*60; m_log_interval_seconds = 0; // default set to zero to save power } rtc_set_alarm(RTC,rtc_get_time(RTC)+m_log_interval_seconds); }
void Controller::event_rem(const char *event,const char *value) { flashstorage_keyval_set("SVREM","REM"); tick_item("\x80Sv" ,false); tick_item("\x80R",true); }
void Controller::event_geiger_beep(const char *event,const char *value) { system_geiger->toggle_beep(); if(system_geiger->is_beeping()) { flashstorage_keyval_set("GEIGERBEEP","true"); tick_item("Geiger Beep",true); } else { flashstorage_keyval_set("GEIGERBEEP","false"); tick_item("Geiger Beep",false); } }
void Controller::event_english(const char *event,const char *value) { m_gui->set_language(LANGUAGE_ENGLISH); flashstorage_keyval_set("LANGUAGE","English"); tick_item("English" ,true); tick_item("Japanese",false); }
int main(void) { Geiger g; power_initialise(); if(power_battery_level() < 1) { power_standby(); } flashstorage_initialise(); buzzer_initialise(); realtime_initialise(); g.initialise(); uint8_t *private_key = ((uint8_t *) &_binary___binary_data_private_key_data_start); if(private_key[0] != 0) delay_us(1000); delay_us(10000); // can be removed? #ifndef DISABLE_ACCEL accel_init(); #endif Controller c(g); switch_initialise(); // if we woke up on an alarm, we're going to be sending the system back. #ifndef NEVERSLEEP if(power_get_wakeup_source() == WAKEUP_RTC) { c.m_sleeping = true; } else { buzzer_nonblocking_buzz(0.05); display_initialise(); const char *devicetag = flashstorage_keyval_get("DEVICETAG"); char revtext[10]; sprintf(revtext,"VERSION: %s ",OS100VERSION); display_splashscreen(devicetag,revtext); delay_us(3000000); display_clear(0); } #endif #ifdef NEVERSLEEP buzzer_nonblocking_buzz(0.05); display_initialise(); #endif GUI m_gui(c); bool full = flashstorage_log_isfull(); if((full == true) && (c.m_sleeping == false)) { m_gui.show_dialog("Flash Log","is full",0,0,0); } c.set_gui(m_gui); UserInput u(m_gui); u.initialise(); serial_initialise(); int8_t utcoffsetmins_n = 0; const char *utcoffsetmins = flashstorage_keyval_get("UTCOFFSETMINS"); if(utcoffsetmins != 0) { unsigned int c; sscanf(utcoffsetmins, "%u", &c); utcoffsetmins_n = c; realtime_setutcoffset_mins(utcoffsetmins_n); } // Need to refactor out stored settings if(c.m_sleeping == false) { const char *sbright = flashstorage_keyval_get("BRIGHTNESS"); if(sbright != 0) { unsigned int c; sscanf(sbright, "%u", &c); display_set_brightness(c); } const char *sbeep = flashstorage_keyval_get("GEIGERBEEP"); if(sbeep != 0) { if(strcmp(sbeep,"true") == 0) { g.set_beep(true); tick_item("Geiger Beep",true); } else g.set_beep(false); } const char *scpmcps = flashstorage_keyval_get("CPMCPSAUTO"); if(scpmcps != 0) { if(strcmp(scpmcps,"true") == 0) { c.m_cpm_cps_switch = true; tick_item("CPM/CPS Auto",true); } } const char *language = flashstorage_keyval_get("LANGUAGE"); if(language != 0) { if(strcmp(language,"English" ) == 0) { m_gui.set_language(LANGUAGE_ENGLISH); tick_item("English" ,true); } else if(strcmp(language,"Japanese") == 0) { m_gui.set_language(LANGUAGE_JAPANESE); tick_item("Japanese" ,true); } } else { m_gui.set_language(LANGUAGE_ENGLISH); tick_item("English",true); } const char *svrem = flashstorage_keyval_get("SVREM"); if(strcmp(svrem,"REM") == 0) { tick_item("Roentgen",true); } else { tick_item("Sievert",true);} } m_gui.jump_to_screen(1); m_gui.push_stack(0,1); for(;;) { if(power_battery_level() < 1) { power_standby(); } //display_draw_text(0,110,"preupdate",0); c.update(); //display_draw_text(0,110,"prerender",0); m_gui.render(); //display_draw_text(0,110,"preserial",0); serial_eventloop(); //display_draw_text(0,110,"preserial",0); // It might be a good idea to move the following code to Controller. // Hack to check that captouch is ok, and reset it if not. bool c = cap_check(); if(c == false) { display_draw_text(0,90,"CAPFAIL",0); cap_init(); } // Screen lock code uint32_t release1_time = cap_last_press(KEY_BACK); uint32_t press1_time = cap_last_release(KEY_BACK); uint32_t release2_time = cap_last_press(KEY_SELECT); uint32_t press2_time = cap_last_release(KEY_SELECT); uint32_t current_time = realtime_get_unixtime(); if((release1_time != 0) && (release2_time != 0) && ((current_time-press1_time) > 3) && ((current_time-press2_time) > 3) && cap_ispressed(KEY_BACK ) && cap_ispressed(KEY_SELECT)) { system_gui->toggle_screen_lock(); cap_clear_press(); } power_wfi(); } // should never get here for(int n=0;n<60;n++) { delay_us(100000); buzzer_blocking_buzz(1000); } return 0; }