Ejemplo n.º 1
0
/**
 * \brief Set the time using a spinner widget
 */
static void set_time_application(void)
{
    struct keyboard_event input;
    struct calendar_date date;
    uint32_t timestamp;
    uint8_t tz_hours;
    uint8_t tz_minutes;
    struct gfx_mono_spinctrl hour_spinner;
    struct gfx_mono_spinctrl minute_spinner;
    struct gfx_mono_spinctrl_spincollection time_spinners;
    uint8_t spinner_status;
    int16_t spinner_results[2];

    // Prepare the spinner widget for time selection
    gfx_mono_spinctrl_init(&hour_spinner, SPINTYPE_INTEGER,
                           datetime_date_spinner_string_hour, NULL, 0, 23, 0);
    gfx_mono_spinctrl_init(&minute_spinner, SPINTYPE_INTEGER,
                           datetime_date_spinner_string_minute, NULL, 0, 59, 0);

    // Create time spincollector
    gfx_mono_spinctrl_spincollection_init(&time_spinners);
    gfx_mono_spinctrl_spincollection_add_spinner(&hour_spinner,
            &time_spinners);
    gfx_mono_spinctrl_spincollection_add_spinner(&minute_spinner,
            &time_spinners);

    // Get timezone settings
    tz_hours = timezone_get_hours();
    tz_minutes = timezone_get_minutes();

    timestamp = rtc_get_time();

    calendar_timestamp_to_date_tz(timestamp, tz_hours, tz_minutes, &date);

    // Set spinners to current time as initial position
    hour_spinner.integer_data = date.hour;
    minute_spinner.integer_data = date.minute;

    gfx_mono_spinctrl_spincollection_show(&time_spinners);

    do {
        do {
            keyboard_get_key_state(&input);
            // Wait for key release
        } while (input.type != KEYBOARD_RELEASE);
        // Send key to spinnercollection
        spinner_status = gfx_mono_spinctrl_spincollection_process_key(
                             &time_spinners, input.keycode, spinner_results);
    } while (spinner_status != GFX_MONO_SPINCTRL_EVENT_FINISH);

    date.hour = spinner_results[0];
    date.minute = spinner_results[1];

    timestamp = calendar_date_to_timestamp_tz(&date, tz_hours, tz_minutes);

    if(timestamp != 0) {
        rtc_set_time(timestamp);
    }
}
Ejemplo n.º 2
0
void set_current_RTC(void)
{
	rtc_timestamp=calendar_date_to_timestamp_tz(&date,5,30);
	rtc_set_time(rtc_timestamp);
	while(1);
}
Ejemplo n.º 3
0
/**
 * \brief Set the date using a spinner widget.
 *
 * This function will set show a spinner widget that lets the user select the
 * current date. This function will leave the clock unchanged, and only change
 * the date part of the RTC32 timestamp.
 */
static void set_date_application(void)
{
    struct calendar_date date;
    struct calendar_date new_date;
    struct keyboard_event input;
    uint32_t current_timestamp;
    uint32_t new_timestamp;
    uint8_t tz_hours;
    uint8_t tz_minutes;
    struct gfx_mono_spinctrl year_spinner;
    struct gfx_mono_spinctrl month_spinner;
    struct gfx_mono_spinctrl day_spinner;
    struct gfx_mono_spinctrl_spincollection date_spinners;
    int16_t spinner_results[3];
    uint8_t spinner_status;

    // Prepare the spinner widget for date selection
    gfx_mono_spinctrl_init(&year_spinner, SPINTYPE_INTEGER,
                           datetime_date_spinner_string_year, NULL, 2011, 2105, 0);
    gfx_mono_spinctrl_init(&month_spinner, SPINTYPE_INTEGER,
                           datetime_date_spinner_string_month, NULL, 1, 12, 0);
    gfx_mono_spinctrl_init(&day_spinner, SPINTYPE_INTEGER,
                           datetime_date_spinner_string_day, NULL, 1, 31, 0);

    // Create date spincollector
    gfx_mono_spinctrl_spincollection_init(&date_spinners);
    gfx_mono_spinctrl_spincollection_add_spinner(&year_spinner,
            &date_spinners);
    gfx_mono_spinctrl_spincollection_add_spinner(&month_spinner,
            &date_spinners);
    gfx_mono_spinctrl_spincollection_add_spinner(&day_spinner,
            &date_spinners);

    // Get timezone settings
    tz_hours = timezone_get_hours();
    tz_minutes = timezone_get_minutes();

    // Get current time
    current_timestamp = rtc_get_time();

    // Convert the current timestamp to a datestruct
    calendar_timestamp_to_date_tz(current_timestamp, tz_hours, tz_minutes,
                                  &date);

    // Set the spinner selection to the current date
    day_spinner.integer_data = date.date + 1;
    month_spinner.integer_data = date.month + 1;
    year_spinner.integer_data = date.year;

    // show the date selection spinner to get a new date
    gfx_mono_spinctrl_spincollection_show(&date_spinners);

    do {
        do {
            keyboard_get_key_state(&input);
            // Wait for key release
        } while (input.type != KEYBOARD_RELEASE);
        // Send key to spinnercollection
        spinner_status = gfx_mono_spinctrl_spincollection_process_key(
                             &date_spinners, input.keycode, spinner_results);
    } while (spinner_status != GFX_MONO_SPINCTRL_EVENT_FINISH);

    /* The result are stored in the same order that they were added
     * we subtract one from month and day, as they are indexed from 0 in the
     * date struct but we present them as starting from 1 in the spinner.
     */
    new_date.year = spinner_results[0];
    new_date.month = spinner_results[1] - 1;
    new_date.date = spinner_results[2] - 1;

    // Verify date set
    new_date.hour = 0;
    new_date.minute = 0;
    new_date.second = 0;
    if (calendar_date_to_timestamp_tz(&new_date, tz_hours, tz_minutes) == 0) {
        //Notify the user that the date was invalid and wait for key
        gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH,
                                  GFX_MONO_LCD_HEIGHT, GFX_PIXEL_CLR);
        gfx_mono_draw_progmem_string(
            (char PROGMEM_PTR_T)datetime_invalid_date_string,
            10, 12, &sysfont);

        while (true) {
            keyboard_get_key_state(&input);
            if (input.type == KEYBOARD_RELEASE) {
                break;
            }
        }
        return;
    }

    // Date OK, change.

    // Get current time
    current_timestamp = rtc_get_time();
    // Convert the current timestamp to a datestruct
    calendar_timestamp_to_date_tz(current_timestamp, tz_hours, tz_minutes,
                                  &date);
    // Set new date in struct
    date.year = new_date.year;
    date.month = new_date.month;
    date.date = new_date.date;

    // Convert back to timestamp
    new_timestamp =
        calendar_date_to_timestamp_tz(&date, tz_hours, tz_minutes);
    // Set new timestamp
    rtc_set_time(new_timestamp);
}