/** * Append a new entry to the log if necessary. Checks the * state of m_alarm_log to determine if we should append a log * entry. */ void Controller::do_logging() { if(rtc_alarmed()) { m_alarm_log = true; m_last_alarm_time = rtc_get_time(RTC); #ifndef DISABLE_ACCEL accel_read_state(&m_accel_x_stored,&m_accel_y_stored,&m_accel_z_stored); #endif //m_magsensor_stored = gpio_read_bit(PIN_MAP[29].gpio_device,PIN_MAP[29].gpio_bit); // set new alarm for log_interval_seconds from now. rtc_clear_alarmed(); } if(m_alarm_log == true) { if(system_geiger->is_cpm30_valid()) { log_data_t data; #ifndef DISABLE_ACCEL accel_read_state(&data.accel_x_end,&data.accel_y_end,&data.accel_z_end); #endif //data.magsensor_end = gpio_read_bit(PIN_MAP[29].gpio_device,PIN_MAP[29].gpio_bit); data.time = rtc_get_time(RTC); data.cpm = system_geiger->get_cpm30(); data.accel_x_start = m_accel_x_stored; data.accel_y_start = m_accel_y_stored; data.accel_z_start = m_accel_z_stored; //data.magsensor_start = m_magsensor_stored; data.log_type = UINT_MAX; flashstorage_log_pushback((uint8_t *) &data,sizeof(log_data_t)); bool full = flashstorage_log_isfull(); if((full == true) && (!m_sleeping)) { m_gui->show_dialog("Flash Log","is full",0,0,0,43,44,255,255); } m_alarm_log = false; rtc_set_alarm(RTC,m_last_alarm_time+m_log_interval_seconds); rtc_enable_alarm(RTC); if(m_sleeping) { power_standby(); } } } }
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; }