Esempio n. 1
0
/* Entry point */
void vm_main(void) {
#if defined(__HDK_LINKIT_ASSIST_2502__)
	lcd_st7789s_init();
	lcd_backlight_level(60);
#endif
	vm_pmng_register_system_event_callback(handle_sysevt);
}
void screen_resume(void)
{
    if (g_screen_off_timeout == 0) {
    	vm_pwr_lcd_sleep_out();
        lcd_backlight_level(g_brightness_table[g_settings_brightness]);
    }
    
    g_screen_off_timeout = SCREEN_OFF_TIME;
}
int screen_suspend(void)
{
    if (g_screen_off_timeout > 0) {
        g_screen_off_timeout--;
        if (g_screen_off_timeout == 0) {
            lcd_backlight_level(0);
            vm_pwr_lcd_sleep_in();
        } else {
        	return 0;
        }
    }

    return 1;
}
void settings_load()
{
    unsigned long size = 0;
    file_size("settings.txt", &size);
    if (size < 24) {
        return;
    }

    char *ptr = vm_malloc(size);
    if (NULL == ptr) {
        return;
    }

    file_read("settings.txt", ptr, size, 0);

    cJSON *root = cJSON_Parse(ptr);
    if (NULL == root) {
        vm_free(ptr);
        return;
    }

    g_settings_brightness = cJSON_GetObjectItem(root, "brightness")->valueint;
    g_settings_sound = cJSON_GetObjectItem(root, "sound")->valueint;

    if (g_settings_brightness > 6) {
        g_settings_brightness = 6;
    }
    snprintf(g_settings_brightness_str, sizeof(g_settings_brightness_str), "%d", g_settings_brightness);

    if (g_settings_sound > 6) {
        g_settings_sound = 6;
    }
    g_settings_sound_str[0] = '0' + g_settings_sound;

    lcd_backlight_level(g_brightness_table[g_settings_brightness]);
    audioSetVolume(g_settings_sound);

    UG_ButtonSetText(&g_settings_window, 7, g_settings_brightness_str);
    UG_ButtonSetText(&g_settings_window, 4, g_settings_sound_str);

    vm_free(ptr);
}
static void settings_window_callback(UG_MESSAGE *msg)
{
    if (msg->type == MSG_TYPE_OBJECT) {
        if (msg->id == OBJ_TYPE_BUTTON && msg->event == OBJ_EVENT_RELEASED) {
            switch (msg->sub_id) {
                case 0: // back
                    if (g_settings_is_changed) {
                        g_settings_is_changed = 0;
                        settings_save();
                    }
                    UG_WindowShow(&g_home_window);
                    break;
                case 3: // -
                    if (g_settings_sound > 0) {
                        g_settings_is_changed = 1;
                        g_settings_sound--;
                        audioSetVolume(g_settings_sound);
                        g_settings_sound_str[0] = '0' + g_settings_sound;
                        UG_ButtonSetText(&g_settings_window, 4,
                                g_settings_sound_str);
                    }
                    break;
                case 5: // +
                    if (g_settings_sound < 6) {
                        g_settings_is_changed = 1;
                        g_settings_sound++;
                        audioSetVolume(g_settings_sound);
                        g_settings_sound_str[0] = '0' + g_settings_sound;
                        UG_ButtonSetText(&g_settings_window, 4,
                                g_settings_sound_str);
                    }
                    break;
                case 6: // -
                    if (g_settings_brightness > 0) {
                        g_settings_is_changed = 1;
                        g_settings_brightness--;
                        lcd_backlight_level(g_brightness_table[g_settings_brightness]);

                        itoa(g_settings_brightness, g_settings_brightness_str,
                                10);
                        UG_ButtonSetText(&g_settings_window, 7,
                                g_settings_brightness_str);
                    }
                    break;
                case 8: // +
                    if (g_settings_brightness < 6) {
                        g_settings_is_changed = 1;
                        g_settings_brightness++;
                        lcd_backlight_level(g_brightness_table[g_settings_brightness]);

                        itoa(g_settings_brightness, g_settings_brightness_str,
                                10);
                        UG_ButtonSetText(&g_settings_window, 7,
                                g_settings_brightness_str);
                    }
                    break;
                default:
                    break;
            }
        }
    }
}