Example #1
0
static void main_window_load(Window *window) {
  // Setup the Window layer
  window_set_background_color(window, GColorBlack);
  
  // Create date TextLayer
  s_date_layer = text_layer_create(GRect(5, 35, 139, 45));
  text_layer_set_background_color(s_date_layer, GColorClear);
  text_layer_set_text_color(s_date_layer, GColorWhite);
  text_layer_set_text(s_date_layer, "0000");
  
  // Create time TextLayer
  s_time_layer = text_layer_create(GRect(5, 82, 139, 50));
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, GColorWhite);
  text_layer_set_text(s_time_layer, "0000");

  // Setup fonts
  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ZDYK_42));
  text_layer_set_font(s_time_layer, s_time_font);
  text_layer_set_font(s_date_layer, s_time_font);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);

  // Add it as a child layer to the Window's root layer
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));

  // Make sure the time is displayed from the start
  update_datetime();
}
Example #2
0
//Uses all the sensors to update all of the global variables that have to do with logging.
int update_data() {
    p_sensor.Barometer_MS5803(); //Gathers data from external temp/pressure sensor 
    //Updates temperatures, pressure, and power 
    pressure = p_sensor.MS5803_Pressure();
    external_temp = p_sensor.MS5803_Temperature();
    internal_temp = temperature.read();
    power = ain.read();
    //Data gathered from GPS 
    bool gps_ready = gps_readable();
    int max_gps_requests = 4;
    int gps_counter = 0;
    while (!gps_ready && gps_counter < max_gps_requests) {
        gps_ready = gps_readable();
        gps_counter++;
        //printf("Waiting!\n");
    }
    if (gps_ready) {
        update_lat_long();
        altitude = gps.f_altitude();
        precision = gps.hdop();
        gps.stats(&encoded_chars, &good_sentences, &failed_checksums);
        update_datetime();
    } else {
        //Place DUMMY GPS VALUES 
        latitude = -1000.0;
        longitude = -1000.0; 
        altitude = -1000.0; 
        precision = -1000;
        sprintf(date,"20000 BC");
        encoded_chars = -1;
        good_sentences = -1;
        failed_checksums = -1;
    }
    return 0; //Data update was a success! 
}
Example #3
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_datetime();
}
Example #4
0
int main()
{
  uint8_t i = 0;
  uint8_t n = 0;
  uint8_t pos;
  char strbuf[64];
  char timebuf[16];
  uint8_t seconds_last = seconds;
  uint8_t minutes_last = minutes;
  unsigned int ch;

  // FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  // stdin = stdout = &uart_stream;

  // always calibrate the internal RC oscillator using external 32Khz crystal
  do_calibration();
  // OSCCAL = 55;

  rtc_init();
  key_init();
  extra_init();
  ht1632_setup(1); // use ram

#ifdef USE_UARTSYNC
  uart_init();
#else

  #ifdef USE_V0
  uart_init( UART_BAUD_SELECT(9600,F_CPU) );
  #else
  // uart_init( UART_BAUD_SELECT(38400,F_CPU) );
  uart_init( UART_BAUD_SELECT(9600,F_CPU) );
  #endif

#endif

  sei(); // turn on interrupt handler

  // strncpy(strbuf, "ready: ", 7);
  // sprintf(&strbuf[7], "%d", OSCCAL);
  // ht1632_scrollstr(strbuf, 10, 10);
  int start = 5;
  ht1632_putchar(start,1,'L'); 
  ht1632_putchar(start+6,1,'E'); 
  ht1632_putchar(start+12,1,'D'); 
  ht1632_putchar(start+18,1,'I'); 
  delay_ms(5000); 

  set_time(timebuf);
  disp_time(timebuf);

  // play tone to indicate we started
  play_tone(A5, 4); _delay_ms(5);
  play_tone(A5, 4); _delay_ms(10);

  while(1)
  {
    n = term_recvstr(BUF, BUFSIZE);

    if(n<0)
    {
      term_sendstr(PSTR("error occurred on uart\r\n"));
    }
    if(n>0)
    {
      MODE = term_check_mode(BUF,n);
      switch(MODE)
      {
        case MODE_TIMESET:
          mode_timeset(BUF,n);
          break;
        case MODE_DRAW:
          mode_draw();
          break;
        case MODE_INVALID:
        default:
          mode_msg(BUF,n);
          break;
      }
      // just to be paranoid
      stop_led_sync_timer();

      // hack to force time display
      minutes_last = minutes - 1;
    }

    if(last_button1state == 1)
    {
      demo_life(); 
      // if we come out of demo_life, we show time 
      set_time(timebuf);
      disp_time(timebuf);
    }

    if(seconds_last != seconds || last_buttonstate & BT_PRESS) 
    {
      seconds_last = seconds;

      if(minutes_last != minutes)
      {
        minutes_last = minutes;
        set_time(timebuf);
        disp_time(timebuf);
      }

      disp_bindots();
    }

    // fast cycle
    if(last_buttonstate & BT_HOLD)
    {
      while(!(PINC & (1<<BUTTON2)))
      {
        minutes++;
        update_datetime(1);
        set_time(timebuf);
        disp_time(timebuf);
        minutes_last = minutes;
        _delay_ms(20);
      }
      intcount = 0;
    }

    // while ((ASSR & (1<<OCR2BUB)) != 0) {} 
  }
}