Esempio n. 1
0
/**
 * Dim the screen if necessary. Called by the Controller. Will dim in
 * several steps (one dim level at each call)
 */
void Controller::do_dimming() {

  if(m_never_dim) return;

  // only dim if not in brightness changing mode
  if(!m_dim_off) {
    // Check for no key presses then dim screen
    uint32_t release_time = cap_last_press_any();
    uint32_t   press_time = cap_last_release_any();
    uint32_t current_time = realtime_get_unixtime();

    uint8_t current_brightness = display_get_brightness();
    if(((current_time - press_time) > 10) && ((current_time - release_time) > 10)) {
      if(current_brightness > 1) display_set_brightness(current_brightness-1);
    } else {
      const char *sbright = flashstorage_keyval_get("BRIGHTNESS");
      unsigned int user_brightness=15;
      if(sbright != 0) {
        sscanf(sbright, "%u", &user_brightness);
      }
      if(current_brightness < user_brightness) {
        display_set_brightness(current_brightness+1);
      }
    }
  }
}
Esempio n. 2
0
void serial_setrtc() {

  char info[100];
  sprintf(info,"Current unixtime is %u\r\n",realtime_get_unixtime());
  serial_write_string(info);
  serial_write_string("#>");
  in_setrtc=true;
}
/**
 * Gets current time on the device
 */
void cmd_getrtc() {
  JSONNODE *n = json_new(JSON_NODE);
  json_push_back(n, json_new_i("rtc", realtime_get_unixtime()));
  json_char *jc = json_write_formatted(n);
  serial_write_string(jc);
  json_free(jc);
  json_delete(n);
}
Esempio n. 4
0
void Controller::event_totaltimer(const char *event,const char *value) {
  system_geiger->reset_total_count();
  m_total_timer_start = realtime_get_unixtime();

  const char *blank = "              ";
  m_gui->receive_update("TTCOUNT",blank);
  m_gui->receive_update("TTTIME" ,blank);
  m_gui->redraw();
}
/**
 * Sets the real time clock (unix time). Part 1
 */
void cmd_setrtc(char *line) {
  char info[100];
  sprintf(info,"Current unixtime is %"PRIu32"\r\n",realtime_get_unixtime());
  serial_write_string(info);
  serial_write_string("#>");

  command_stack[command_stack_size] = serial_setrtc_run;
  command_stack_size++;
}
Esempio n. 6
0
void Controller::save_loginterval() {
  int l1 = m_gui->get_item_state_uint8("LOGINTER1");
  int l2 = m_gui->get_item_state_uint8("LOGINTER2");
  int l3 = m_gui->get_item_state_uint8("LOGINTER3");
  int32_t log_interval_mins = (l1*100) + (l2*10) + l3;
  m_log_interval_seconds = log_interval_mins*60;

  char sloginterval[50];
  sprintf(sloginterval,"%"PRIu32"",m_log_interval_seconds);
  flashstorage_keyval_set("LOGINTERVAL",sloginterval);
  uint32_t current_time = realtime_get_unixtime();

if(m_log_interval_seconds > 0){
  rtc_set_alarm(RTC,current_time+m_log_interval_seconds);
}else{
     rtc_disable_alarm(RTC);
}

  m_gui->jump_to_screen(0);

}
Esempio n. 7
0
/**
 * Total counts
 */
void Controller::send_total_timer() {
  char text_totaltimer_count[50];
  char text_totaltimer_time [50];
  uint32_t ctime = realtime_get_unixtime();
  uint32_t totaltimer_time = ctime - m_total_timer_start;

  char temp[50];
  sprintf(text_totaltimer_time ,"%"PRIu32"s",totaltimer_time);
  sprintf(temp,"  %6.3f  " ,((float)system_geiger->get_total_count()/((float)totaltimer_time))*60);
  int len = strlen(temp);
  int pad = (16-len)/2;
  for(int n=0;n<16;n++) {
    if((n > pad) && (n < (pad+len))) {text_totaltimer_count[n] = temp[n-pad];}
                                else {text_totaltimer_count[n] = ' ';}
    text_totaltimer_count[n+1] = 0;
  }

  m_gui->receive_update("DELAYA",NULL);
  m_gui->receive_update("DELAYB",NULL);
  m_gui->receive_update("TTCOUNT",text_totaltimer_count);
  m_gui->receive_update("TTTIME" ,text_totaltimer_time);
}
Esempio n. 8
0
/**
 * Interrupt handler for capacitive keyboard events
 */
static void cap_change(void) {

	// Read keyboard
	int key_state = mpr121Read(TCH_STATL) | (mpr121Read(TCH_STATH) << 8);
	uint32_t ts = realtime_get_unixtime();

	// there appears to be a bug where it suddenly outputs a lot of bits set.
	unsigned int v = key_state; // count the number of bits set in v
	unsigned int c; // c accumulates the total bits set in v
	for (c = 0; v; c++) {
		v &= v - 1; // clear the least significant bit set
	}
	if (c > 3)
		return;

	// clear unconnected electrodes
	key_state &= touchList;

	// detect keys pressed & released
	int keys_pressed = key_state & (~last_key_state); //TODO: ! bitwise NOT
	int keys_released = (~key_state) & last_key_state; //TODO: ! bitwise NOT

	if (!captouch_disable_messages) {
		for (int key = 0; key < 16; key++) {
			if (keys_pressed & (1 << key)) {
				system_gui->receive_key(key, KEY_PRESSED);
				press_time[key] = ts;
				press_time_any = ts;
			}
			if (keys_released & (1 << key)) {
				system_gui->receive_key(key, KEY_RELEASED);
				release_time[key] = ts;
				release_time_any = ts;
			}
		}
		last_key_state = key_state;
	}

}
Esempio n. 9
0
void cap_init(void) {

	// 63 2 4 1 63 2 4 1 0 8 4
	cap_set_mhd_r(63);
	cap_set_nhd_r(2);
	cap_set_ncl_r(4);
	cap_set_fdl_r(1);
	cap_set_mhd_f(63);
	cap_set_nhd_f(2);
	cap_set_ncl_r(4);
	cap_set_fdl_f(1);
	cap_set_dbr(0);
	cap_set_touch_threshold(8);
	cap_set_release_threshold(4);

	/**
	gpio_set_mode(PIN_MAP[BOARD_I2C_SDA].gpio_device, PIN_MAP[BOARD_I2C_SDA].gpio_bit, GPIO_OUTPUT_PP);
	gpio_set_mode(PIN_MAP[BOARD_I2C_SCL].gpio_device, PIN_MAP[BOARD_I2C_SCL].gpio_bit, GPIO_OUTPUT_PP);
	gpio_write_bit(PIN_MAP[BOARD_I2C_SDA].gpio_device, PIN_MAP[BOARD_I2C_SDA].gpio_bit, 1);
	gpio_write_bit(PIN_MAP[BOARD_I2C_SCL].gpio_device, PIN_MAP[BOARD_I2C_SCL].gpio_bit, 1);
	delay_us(1000);
	gpio_set_mode(PIN_MAP[BOARD_I2C_SDA].gpio_device, PIN_MAP[BOARD_I2C_SDA].gpio_bit, GPIO_INPUT_PD); // Can also be floating, but PD is safer if components misplaced.
	gpio_set_mode(PIN_MAP[BOARD_I2C_SCL].gpio_device, PIN_MAP[BOARD_I2C_SCL].gpio_bit, GPIO_INPUT_PD);
	*/

	i2c = CAPTOUCH_I2C;
	i2c_init(i2c);
	i2c_master_enable(i2c, I2C_BUS_RESET);

	mpr121Write(0x80, 0x63); // soft reset
	delay_us(1000);
	mpr121Write(ELE_CFG, 0x00);   // disable electrodes for config
	delay_us(100);

	// Section A and B - R (rise) F (fall) T (touch)
	mpr121Write(MHD_R, cap_mhd_r); // (1 to 63)
	mpr121Write(NHD_R, cap_nhd_r); // (1 to 63)
	mpr121Write(NCL_R, cap_ncl_r); // (0 to 255)
	mpr121Write(FDL_R, cap_fdl_r); // (0 to 255)

	mpr121Write(MHD_F, cap_mhd_f); // (1 to 63) largest value to pass through filer
	mpr121Write(NHD_F, cap_nhd_f); // (1 to 63) maximum change allowed
	mpr121Write(NCL_F, cap_ncl_f); // (0 to 255) number of samples required to determine non-noise
	mpr121Write(FDL_F, cap_fdl_f); // (0 to 255) rate of filter operation, larger = slower.

	// Section D
	// Set the Filter Configuration
	// Set ESI2

	// was 0x01, 0x25
	mpr121Write(AFE_CONF, 0x01); //AFE_CONF  0x5C
	mpr121Write(FIL_CFG, 0x04); //FIL_CFG   0x5D

	// Section F
	mpr121Write(ATO_CFG0, 0x0B); // ATO_CFG0 0x7B

	// limits
	// was0xFF,0x00,0x0E
	mpr121Write(ATO_CFGU, 0x9C); // ATO_CFGU 0x7D
	mpr121Write(ATO_CFGL, 0x65); // ATO_CFGL 0x7E
	mpr121Write(ATO_CFGT, 0x8C); // ATO_CFGT 0x7F

	// enable debouncing
	mpr121Write(DBR, cap_dbr); // set debouncing, in this case 7 for both touch and release.

	// Section C
	// This group sets touch and release thresholds for each electrode
	mpr121Write(ELE0_T, cap_touch_threshold);
	mpr121Write(ELE0_R, cap_release_threshold);
	mpr121Write(ELE1_T, cap_touch_threshold);
	mpr121Write(ELE1_R, cap_release_threshold);
	mpr121Write(ELE2_T, cap_touch_threshold);
	mpr121Write(ELE2_R, cap_release_threshold);
	mpr121Write(ELE3_T, cap_touch_threshold);
	mpr121Write(ELE3_R, cap_release_threshold);
	mpr121Write(ELE4_T, cap_touch_threshold);
	mpr121Write(ELE4_R, cap_release_threshold);
	mpr121Write(ELE5_T, cap_touch_threshold);
	mpr121Write(ELE5_R, cap_release_threshold);
	mpr121Write(ELE6_T, cap_touch_threshold);
	mpr121Write(ELE6_R, cap_release_threshold);
	mpr121Write(ELE7_T, cap_touch_threshold);
	mpr121Write(ELE7_R, cap_release_threshold);
	mpr121Write(ELE8_T, cap_touch_threshold);
	mpr121Write(ELE8_R, cap_release_threshold);
	mpr121Write(ELE9_T, cap_touch_threshold);
	mpr121Write(ELE9_R, cap_release_threshold);
	mpr121Write(ELE10_T, cap_touch_threshold);
	mpr121Write(ELE10_R, cap_release_threshold);
	mpr121Write(ELE11_T, cap_touch_threshold);
	mpr121Write(ELE11_R, cap_release_threshold);

	delay_us(100);

	// Section E
	// Electrode Configuration
	// Enable 6 Electrodes and set to run mode
	// Set ELE_CFG to 0x00 to return to standby mode
	mpr121Write(ELE_CFG, 0x0C);   // Enables all 12 Electrodes
	delay_us(100);

	// This can also be FLOATING, but PU is safer if components misplaced.
	gpio_set_mode(PIN_MAP[CAPTOUCH_GPIO].gpio_device,
			PIN_MAP[CAPTOUCH_GPIO].gpio_bit, GPIO_INPUT_PU);
	exti_attach_interrupt((afio_exti_num) (PIN_MAP[CAPTOUCH_GPIO].gpio_bit),
			gpio_exti_port(PIN_MAP[CAPTOUCH_GPIO].gpio_device), cap_change,
			EXTI_FALLING);

	// Clears the first interrupt
	uint32_t ts = realtime_get_unixtime();
	for (int n = 0; n < 16; n++)
		press_time[n] = ts;
	for (int n = 0; n < 16; n++)
		release_time[n] = ts;
	press_time_any = ts;
	release_time_any = ts;

	// Set the cap_enabled flag to remember the captouch is on
	cap_enabled = 1;

	return;
}
Esempio n. 10
0
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;
}