Beispiel #1
0
void tetris_init()
{
    tetris_set_defaults();
    
    pieces = (tetris_piece***)malloc(sizeof(tetris_piece*)*TETRIS_W);
    uint16_t y, z;
    for(y = 0; y < TETRIS_W; ++y)
    {
        pieces[y] = (tetris_piece**)malloc(sizeof(tetris_piece*)*TETRIS_H);
        for(z = 0; z < TETRIS_H; ++z)
            pieces[y][z] = NULL;
    }

    pthread_mutex_init(tetris_draw_mutex, NULL);
    t_tetris = (pthread_t*)malloc(sizeof(pthread_t));
    pthread_create(t_tetris, NULL, tetris_thread, NULL);

    bootmgr_display->bg_img = 0;
    bootmgr_set_lines_count(0);
    bootmgr_set_fills_count(0);
    bootmgr_print_fill(9,                      29,  TETRIS_W*BLOCK_SIZE+1, 1,                     WHITE, TETRIS_BORDER_TOP);
    bootmgr_print_fill(9,                      29,  1,                     TETRIS_H*BLOCK_SIZE+1, WHITE, TETRIS_BORDER_LEFT);
    bootmgr_print_fill(TETRIS_W*BLOCK_SIZE+10, 29,  1,                     TETRIS_H*BLOCK_SIZE+1, WHITE, TETRIS_BORDER_RIGHT);
    bootmgr_print_fill(9,                      470, TETRIS_W*BLOCK_SIZE+1, 1,                     WHITE, TETRIS_BORDER_BOTTOM);

    tetris_print_score();
    tetris_print_batt();
    bootmgr_printf(243, 1, WHITE, "Next");
    bootmgr_printf(243, 2, WHITE, "piece:");
    bootmgr_printf(10+((220 - 21*8)/2), 15, WHITE, "Press \"Home\" to start");
    bootmgr_draw();
}
void bootmgr_setup_touch()
{
    if(!settings.touch_ui)
        return;

    bootmgr_set_touches_count(0);
    switch(bootmgr_phase)
    {
        case BOOTMGR_MAIN:
            bootmgr_add_touch(40,  125, 160, 245, bootmgr_touch_int,    1);
            bootmgr_add_touch(160, 125, 280, 245, bootmgr_touch_sd,     2);
            bootmgr_add_touch(40,  245, 160, 365, bootmgr_touch_ums,    3);
            bootmgr_add_touch(160, 245, 280, 365, bootmgr_touch_tetris, 4);
            break;
        case BOOTMGR_UMS:
            bootmgr_add_touch(80, 370, 240, 410, bootmgr_touch_exit_ums, 1);
            bootmgr_print_fill(80, 370, 160, 40, WHITE, 24);
            bootmgr_printf(-1, 24, BLACK, "Exit");
            break;
        case BOOTMGR_SD_SEL:
        {
            bootmgr_add_touch(0,   430, 78,  480, bootmgr_touch_sd_up,     1);
            bootmgr_add_touch(80,  430, 158, 480, bootmgr_touch_sd_down,   2);
            bootmgr_add_touch(160, 430, 238, 480, bootmgr_touch_sd_select, 3);
            bootmgr_add_touch(240, 430, 320, 480, bootmgr_touch_sd_exit,   4);
            bootmgr_printf(31, 28, BLACK, "Up       Down     Select     Exit");
            bootmgr_print_fill(0,   430, 78, 49, WHITE, 28);
            bootmgr_print_fill(80,  430, 78, 49, WHITE, 29);
            bootmgr_print_fill(160, 430, 78, 49, WHITE, 30);
            bootmgr_print_fill(240, 430, 78, 49, WHITE, 31);
            break;
        }
    }
}
Beispiel #3
0
uint8_t bootmgr_boot_sd(void)
{
    bootmgr_set_lines_count(0);
    bootmgr_set_fills_count(0);

    char *path = (char*)malloc(200);
    if(selected == 2)
    {
        bootmgr_printf(-1, 20, WHITE, "Booting from SD-card...");
        sprintf(path, "/sdroot/multirom/rom");
    }
    else
    {
        sprintf(path, "/sdroot/multirom/backup/%s", backups[selected-5]);
        bootmgr_printf(-1, 20, WHITE, "Booting \"%s\"...", backups[selected-5]);
    }

    selected = -1;
    bootmgr_draw();

    char *p = (char*)malloc(200);
    char *s = (char*)malloc(50);
    sprintf(p, "%s/boot", path);
    bootmgr_import_boot(p);

    char * mount_args[] = { NULL, "ext4", p, s, "bind" };

    // /system
    sprintf(p, "%s/system", path);
    strcpy(s, "/system");
    if(do_mount(5, mount_args) < 0)
    {
        bootmgr_printf(-1, 20, WHITE, "Mount %s failed", mount_args[2]);
        bootmgr_draw();
        return 0;
    }

    // /data
    sprintf(p, "%s/data", path);
    strcpy(s, "/data");
    do_mount(5, mount_args);

    // /cache
    sprintf(p, "%s/cache", path);
    strcpy(s, "/cache");
    do_mount(5, mount_args);

    free(p);
    free(s);
    free(path);

    return 1;
}
void bootmgr_setup_touch(void)
{
    if(!settings.touch_ui)
        return;

    bootmgr_set_touches_count(0);
    switch(bootmgr_phase)
    {
        case BOOTMGR_MAIN:
            bootmgr_add_touch(40,  125, 160, 245, bootmgr_touch_int,    1);
            bootmgr_add_touch(160, 125, 280, 245, bootmgr_touch_sd,     2);
            bootmgr_add_touch(40,  245, 160, 365, bootmgr_touch_ums,    3);
            bootmgr_add_touch(160, 245, 280, 365, bootmgr_touch_misc,   4);
            break;
        case BOOTMGR_UMS:
            bootmgr_add_touch(80, 370, 240, 410, bootmgr_touch_exit_ums, 1);
            bootmgr_print_fill(80, 370, 160, 40, WHITE, 24);
            bootmgr_printf(-1, 24, BLACK, "Exit");
            break;
        case BOOTMGR_SD_SEL:
        {
            bootmgr_add_touch(0,   430, 78,  480, bootmgr_touch_sd_up,     1);
            bootmgr_add_touch(80,  430, 158, 480, bootmgr_touch_sd_down,   2);
            bootmgr_add_touch(160, 430, 238, 480, bootmgr_touch_sd_select, 3);
            bootmgr_add_touch(240, 430, 320, 480, bootmgr_touch_sd_exit,   4);
            bootmgr_printf(31, 28, BLACK, "Up       Down     Select     Exit");
            bootmgr_print_fill(0,   430, 78, 49, WHITE, 28);
            bootmgr_print_fill(80,  430, 78, 49, WHITE, 29);
            bootmgr_print_fill(160, 430, 78, 49, WHITE, 30);
            bootmgr_print_fill(240, 430, 78, 49, WHITE, 31);
            break;
        }
        case BOOTMGR_CHARGER:
        {
            bootmgr_add_touch(80, 370, 240, 410, bootmgr_touch_exit_charger, 1);
            bootmgr_print_fill(80, 370, 160, 40, WHITE, 24);
            bootmgr_printf(-1, 24, BLACK, "Back to main menu");
            break;
        }
        case BOOTMGR_MISC:
        {
            int itr = 0;
            for(; misc_callbacks[itr] != NULL; ++itr)
                bootmgr_add_touch(0, itr*ISO_CHAR_HEIGHT*3, BOOTMGR_DIS_W, (itr+1)*ISO_CHAR_HEIGHT*3, misc_callbacks[itr], itr);

            bootmgr_add_touch(80, 370, 240, 410, bootmgr_touch_exit_misc, itr);
            bootmgr_print_fill(80, 370, 160, 40, WHITE, 24);
            bootmgr_printf(-1, 24, BLACK, "Back to main menu");
            break;
        }
    }
}
Beispiel #5
0
void *bootmgr_time_thread(void *cookie)
{
    time_t tm;

    char status[50];
    int8_t hours;
    int8_t mins;
    int battery;

    const uint16_t update_val = settings.show_seconds ? 10 : 600;
    uint16_t timer = update_val;

    while(bootmgr_time_run)
    {
        if(sleep_mode)
        {
            usleep(500000);
            continue;
        }

        if(timer == update_val || force_update_time)
        {
            time(&tm);

            battery = bootmgr_get_battery_pct();
            bootmgr_get_file(battery_status, status, 50);

            // Timezone lame handling
            hours = (tm%86400/60/60) + settings.timezone;
            mins = tm%3600/60 + settings.timezone_mins;

            if     (mins >= 60) { mins -= 60; ++hours; }
            else if(mins < 0)   { mins = 60 - mins; --hours; }

            if     (hours >= 24) hours -= 24;
            else if(hours < 0)   hours = 24 + hours;

            if(settings.show_seconds)
                bootmgr_printf(0, 0, WHITE, "%2u:%02u:%02u    Battery: %u%%, %s", hours, mins, tm%60, battery, status);
            else
                bootmgr_printf(0, 0, WHITE, "%2u:%02u         Battery: %u%%, %s", hours, mins, battery, status);

            bootmgr_draw();
            timer = 0;
            force_update_time = 0;
        }
        usleep(100000);
        ++timer;
    }
    return NULL;
}
Beispiel #6
0
uint8_t bootmgr_toggle_ums(void)
{
    bootmgr_printf(-1, 21, WHITE, "%sabling USB mass storage...", ums_enabled ? "dis" : "en");
    bootmgr_draw();

    sync();

    static const char* gadget_files[] =
    {
        "/sys/devices/platform/msm_hsusb/gadget/lun0/file",
        "/sys/devices/platform/usb_mass_storage/lun0/file",
        NULL
    };

    FILE *f = NULL;

    uint8_t i = 0;
    for(; gadget_files[i] != NULL && f == NULL; ++i)
        f = fopen(gadget_files[i], "w+");

    if(!f)
    {
        bootmgr_erase_text(21);
        return 0;
    }

    if(!ums_enabled)
    {
        bootmgr_toggle_sdcard(1, 1);
        fputs(SD_FAT_BLOCK, f);
        bootmgr_printf(-1, 20, WHITE, "USB mass storage enabled");
        bootmgr_printf(-1, 21, WHITE, "Press \"search\" again to exit");
    }
    else
    {
        fputc(0, f);
        bootmgr_erase_text(20);
        bootmgr_erase_text(21);
        bootmgr_toggle_sdcard(0, 1);
    }
    fclose(f);

    bootmgr_display->bg_img = ums_enabled;
    bootmgr_draw();

    ums_enabled = !ums_enabled;
    return 1;
}
Beispiel #7
0
void tetris_print_batt()
{
    char pct[5];
    bootmgr_get_file(battery_pct, &pct, 4);
    char *n = strchr(&pct, '\n');
    *n = NULL;
    bootmgr_printf(234, 28, WHITE, "Batt: %s%%", &pct);
}
Beispiel #8
0
void *bootmgr_time_thread(void *cookie)
{
    time_t tm;

    char pct[5];
    char status[50];
    int8_t hours;
    int8_t mins;

    const uint16_t update_val = settings.show_seconds ? 10 : 600;
    uint16_t timer = update_val;

    while(bootmgr_time_run)
    {
        if(timer == update_val)
        {
            time(&tm);
            bootmgr_get_file(battery_pct, &pct, 4);
            char *n = strchr(&pct, '\n');
            *n = NULL;
            bootmgr_get_file(battery_status, &status, 50);

            // Timezone lame handling
            hours = (tm%86400/60/60) + settings.timezone;
            mins = tm%3600/60 + settings.timezone_mins;

            if     (mins >= 60) { mins -= 60; ++hours; }
            else if(mins < 0)   { mins = 60 - mins; --hours; }

            if     (hours >= 24) hours -= 24;
            else if(hours < 0)   hours = 24 + hours;

            if(settings.show_seconds)
                bootmgr_printf(0, 0, WHITE, "%2u:%02u:%02u    Battery: %s%%, %s", hours, mins, tm%60, &pct, &status);
            else
                bootmgr_printf(0, 0, WHITE, "%2u:%02u         Battery: %s%%, %s", hours, mins, &pct, &status);

            bootmgr_draw();
            timer = 0;
        }
        usleep(100000);
        ++timer;
    }
    return NULL;
}
Beispiel #9
0
void bootmgr_start()
{
    bootmgr_load_settings();
    bootmgr_init_display();

    bootmgr_set_brightness(settings.brightness);

    int key = 0;
    int8_t last_selected = -1;
    int8_t last_phase = -1;
    uint8_t key_pressed = (settings.timeout_seconds == -1);
    int16_t timer = settings.timeout_seconds*10;
    uint16_t x, y;
    uint8_t touch;
    selected = -1;

    pthread_t t_input;
    pthread_create(&t_input, NULL, bootmgr_input_thread, NULL);
    bootmgr_set_time_thread(1);

    while(bootmgr_run)
    {
        if(last_selected != bootmgr_selected)
        {
            bootmgr_draw();
            last_selected = bootmgr_selected;
        }

        if(last_phase != bootmgr_phase)
        {
            bootmgr_setup_touch();
            bootmgr_draw();
            last_phase = bootmgr_phase;
        }

        key = bootmgr_get_last_key();
        touch = bootmgr_get_last_touch(&x, &y);
        if(key != -1 || touch)
        {
            if(!key_pressed)
            {
                bootmgr_erase_text(25);
                bootmgr_draw();
                key_pressed = 1;
            }

            if(bootmgr_handle_key(key))
                break;

            if(touch)
            {
                key = bootmgr_check_touch(x, y);
                if(key & TCALL_EXIT_MGR)
                    break;
            }
        }

        usleep(100000);
        if(!key_pressed)
        {
            if(timer%10 == 0)
            {
                bootmgr_printf(-1, 25, WHITE, "Boot from internal mem in %us", timer/10);
                bootmgr_draw();
            }

            if(--timer <= 0)
            {
                bootmgr_boot_internal();
                break;
            }
        }
    }
    bootmgr_exit();
}
Beispiel #10
0
void tetris_print_score()
{
    bootmgr_printf(10, 0, WHITE, "Score: %5u   Level: %2u Max: %u", score, level, settings.tetris_max_score);
}
Beispiel #11
0
void tetris_draw(uint8_t move)
{
    if(move && current)
    {
        pthread_mutex_lock(tetris_draw_mutex);
        if(!tetris_can_move_piece(TETRIS_DOWN))
        {
            if(!current->moved)
            {
                uint8_t lines = 2;
                if(settings.tetris_max_score < score)
                {
                    ++lines;
                    settings.tetris_max_score = score;
                    bootmgr_save_settings();
                    bootmgr_printf(10+((220 - 15*8)/2), 16, WHITE, "New high score!");
                }
                bootmgr_print_fill(11, 14*ISO_CHAR_HEIGHT, 219, lines*ISO_CHAR_HEIGHT, BLACK, 1);
                bootmgr_printf(10+((220 - 9*8)/2),  14, WHITE, "Game over");
                bootmgr_printf(10+((220 - 23*8)/2), 15, WHITE, "Press \"Home\" to restart");
                bootmgr_draw_fills();
                bootmgr_draw_text();
                fb_update(&fb);
                state = TETRIS_FINISHED;
                pthread_mutex_unlock(tetris_draw_mutex);
                return;
            }

            uint8_t x,y;
            for(x = 0; x < 5; ++x)
                for(y = current->y < 2 ? current->y : 0; y < 5; ++y)
                    if(p_shape[current->type][current->rotation][y][x])
                        pieces[current->x+(x-2)][current->y+(y-2)] = current;

            tetris_check_line();
            tetris_spawn_new();
        }
        else
            tetris_move_piece(TETRIS_DOWN);
        pthread_mutex_unlock(tetris_draw_mutex);
    }

    android_memset16(fb.bits, BLACK, BOOTMGR_DIS_W*BOOTMGR_DIS_H*2);

    tetris_print_batt();
    bootmgr_draw_fills();
    bootmgr_draw_text();


    tetris_piece *itr = current;
    uint8_t i = 0;
    uint16_t *bits;

    uint8_t y, x;
    do
    {
        for(y = 0; y < 5; ++y)
        {
            uint8_t len = 0;
            int8_t st = -1;
            for(x = 0; x < (i ? 4 : 5); ++x)
            {
                if(p_shape[itr->type][itr->rotation][y][x])
                {
                    if(st == -1)
                        st = x;
                    ++len;
                }
            }
            if(st == -1)
                continue;

            bits = fb.bits;
            bits += BOOTMGR_DIS_W*(30+((itr->y-(2-y))*BLOCK_SIZE)) + 10 + (itr->x-(2-st))*BLOCK_SIZE;
            for(x = 0; x < BLOCK_SIZE; ++x)
            {
                android_memset16(bits, tetris_get_color_for_type(itr->type), len*BLOCK_SIZE*2);
                bits += BOOTMGR_DIS_W;
            }
        }
        itr = preview;
        ++i;
    } while(i < 2);

    for(x = 0; x < TETRIS_W; ++x)
    {
        for(y = 0; y < TETRIS_H; ++y)
        {
            if(!pieces[x][y])
                continue;

            bits = fb.bits;
            bits += BOOTMGR_DIS_W*(30+(y*BLOCK_SIZE)) + 10 + x*BLOCK_SIZE;

            for(i = 0; i < BLOCK_SIZE; ++i)
            {
                android_memset16(bits, tetris_get_color_for_type(pieces[x][y]->type), BLOCK_SIZE*2);
                bits += BOOTMGR_DIS_W;
            }
        }
    }

    fb_update(&fb);
}
Beispiel #12
0
uint8_t bootmgr_handle_key(int key)
{
    if(sleep_mode)
    {
        bootmgr_do_sleep(0);
        return 0;
    }

    switch(bootmgr_phase)
    {
        case BOOTMGR_MAIN:
        {
            switch(key)
            {
                case KEY_VOLUMEDOWN:
                {
                   if(++bootmgr_selected == 4)
                       bootmgr_selected = 0;
                   break;
                }
                case KEY_VOLUMEUP:
                {
                   if(--bootmgr_selected == -1)
                       bootmgr_selected = 3;
                   break;
                }
                case KEY_BACK:
                    bootmgr_printf(-1, 25, WHITE, "Rebooting...");
                    bootmgr_draw();
                    __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, "recovery");
                    return 1;
                case KEY_END:
                {
                    bootmgr_do_sleep(!sleep_mode);
                    break;
                }
                case KEY_POWER:
                {
                    reboot(RB_POWER_OFF);
                    return 1;
                }
                case KEY_MENU:
                {
                    switch(bootmgr_selected)
                    {
                        case 0: bootmgr_boot_internal(); return 1;
                        case 1:
                            if(bootmgr_show_rom_list())
                                return 1;
                            break;
                        case 2: bootmgr_touch_ums();    break;
                        case 3: bootmgr_touch_misc(); break;
                    }
                    break;
                }
                case KEY_SEARCH:
                {
                    bootmgr_charger_init();
                    break;
                }
                default: break;
            }
            break;
        }
        case BOOTMGR_SD_SEL:
        {
            switch(key)
            {
                case KEY_VOLUMEDOWN:
                    bootmgr_touch_sd_down();
                    break;
                case KEY_VOLUMEUP:
                    bootmgr_touch_sd_up();
                    break;
                case KEY_MENU:
                    return bootmgr_boot_sd();
                case KEY_BACK:
                    bootmgr_touch_sd_exit();
                    break;
                default:break;
            }
            break;
        }
        case BOOTMGR_TETRIS:
        {
            tetris_key(key);
            break;
        }
        case BOOTMGR_UMS:
        {
            if(key != KEY_SEARCH)
                break;
            bootmgr_touch_exit_ums();
            break;
        }
        case BOOTMGR_CHARGER: return bootmgr_charger_key(key);
        case BOOTMGR_MISC:    return bootmgr_misc_key(key);
    }
    return 0;
}
Beispiel #13
0
void tetris_key(int key)
{
    switch(key)
    {
        case KEY_VOLUMEDOWN:
        {
            if(state & TETRIS_PAUSED)
            {
                bootmgr_erase_text(14);
                bootmgr_erase_text(15);
                bootmgr_erase_fill(1);
                state &= ~(TETRIS_PAUSED);
                state |= TETRIS_STARTED;
            }
            else if(state & TETRIS_STARTED)
            {
                bootmgr_print_fill(11, 14*ISO_CHAR_HEIGHT, 219, 32, BLACK, 1);
                bootmgr_printf(10+((220 - 6*8)/2),  14, WHITE, "Paused");
                bootmgr_printf(10+((220 - 25*8)/2), 15, WHITE, "Press \"VolDown\" to resume");
                bootmgr_draw_fills();
                bootmgr_draw_text();
                fb_update(&fb);
                state &= ~(TETRIS_STARTED);
                state |= TETRIS_PAUSED;
            }
            break;
        }
        case KEY_VOLUMEUP:
            tetris_exit();
            bootmgr_set_time_thread(1);
            break;
        case KEY_HOME:
        {
            if(!(state & TETRIS_STARTED))
            {
                if(state & TETRIS_FINISHED)
                {
                    tetris_clear(0);
                    tetris_set_defaults();
                    bootmgr_erase_text(14);
                    bootmgr_erase_fill(1);
                    tetris_print_score();
                }
                bootmgr_erase_text(15);
                state = (TETRIS_STARTED | TETRIS_SPAWN_NEW);
            }
            else
            {
                pthread_mutex_lock(tetris_draw_mutex);
                tetris_move_piece(TETRIS_DOWN_FAST);
                tetris_draw(0);
                pthread_mutex_unlock(tetris_draw_mutex);
            }
            break;
        }
        case KEY_BACK:
        {
            if(state & TETRIS_STARTED)
            {
                pthread_mutex_lock(tetris_draw_mutex);
                tetris_rotate_piece();
                tetris_draw(0);
                pthread_mutex_unlock(tetris_draw_mutex);
            }
            break;
        }
        case KEY_MENU:
        case KEY_SEARCH:
        {
            if(state & TETRIS_STARTED)
            {
                pthread_mutex_lock(tetris_draw_mutex);
                if(tetris_can_move_piece(key == KEY_MENU ? TETRIS_LEFT : TETRIS_RIGHT))
                    tetris_move_piece(key == KEY_MENU ? TETRIS_LEFT : TETRIS_RIGHT);
                tetris_draw(0);
                pthread_mutex_unlock(tetris_draw_mutex);
            }
            break;
        }
    }
}
Beispiel #14
0
void bootmgr_boot_internal(void)
{
    bootmgr_printf(-1, 25, WHITE, "Booting from internal memory...");
    bootmgr_draw();
}
Beispiel #15
0
uint8_t bootmgr_handle_key(int key)
{
    switch(bootmgr_phase)
    {
        case BOOTMGR_MAIN:
        {
            switch(key)
            {
                case KEY_VOLUMEDOWN:
                {
                   if(++bootmgr_selected == 4)
                       bootmgr_selected = 0;
                   break;
                }
                case KEY_VOLUMEUP:
                {
                   if(--bootmgr_selected == -1)
                       bootmgr_selected = 3;
                   break;
                }
                case KEY_BACK:
                    bootmgr_printf(-1, 25, WHITE, "Rebooting...");
                    bootmgr_draw();
                case KEY_POWER:
                    bootmgr_close_framebuffer();
                    bootmgr_input_run = 0;
                    reboot(key == KEY_POWER ? RB_POWER_OFF : RB_AUTOBOOT);
                    return 1;
                case KEY_MENU:
                {
                    switch(bootmgr_selected)
                    {
                        case 0: bootmgr_boot_internal(); return 1;
                        case 1:
                            if(bootmgr_show_rom_list())
                                return 1;
                            break;
                        case 2: bootmgr_touch_ums();    break;
                        case 3: bootmgr_touch_tetris(); break;
                    }
                    break;
                }
                default:break;
            }
            break;
        }
        case BOOTMGR_SD_SEL:
        {
            switch(key)
            {
                case KEY_VOLUMEDOWN:
                    bootmgr_touch_sd_down();
                    break;
                case KEY_VOLUMEUP:
                    bootmgr_touch_sd_up();
                    break;
                case KEY_MENU:
                    return bootmgr_boot_sd();
                case KEY_BACK:
                    bootmgr_touch_sd_exit();
                    break;
                default:break;
            }
            break;
        }
        case BOOTMGR_TETRIS:
        {
            tetris_key(key);
            break;
        }
        case BOOTMGR_UMS:
        {
            if(key != KEY_SEARCH)
                break;
            bootmgr_touch_exit_ums();
            break;
        }
    }
    return 0;
}
Beispiel #16
0
uint8_t bootmgr_show_rom_list(void)
{
    bootmgr_set_time_thread(0);
    bootmgr_phase = BOOTMGR_SD_SEL;
    bootmgr_display->bg_img = 0;
    bootmgr_printf(-1, 20, WHITE, "Mounting sd-ext...");
    bootmgr_draw();

    if(!backups_loaded)
    {
        // mknod
        mknod(SD_EXT_BLOCK, (0666 | S_IFBLK), makedev(179, 2));

        //mkdir
        mkdir("/sdroot", (mode_t)0775);
        uid_t uid = decode_uid("system");
        gid_t gid = decode_uid("system");
        chown("/sdroot", uid, gid);

        //mount
        static const char *mount_args[] = { NULL, "ext4", SD_EXT_BLOCK, "/sdroot" };
        int res = do_mount(4, mount_args);
        if(res < 0)
        {
            bootmgr_printf(-1, 20, WHITE, "Failed to mount sd-ext!");
            bootmgr_printf(-1, 21, WHITE, "Press back to return.");
            return 0;
        }

        DIR *dir = opendir("/sdroot/multirom/backup");
        if(dir)
        {
            struct dirent * de = NULL;
            while ((de = readdir(dir)) != NULL)
            {
                if (de->d_name[0] == '.')
                    continue;
                backups[total_backups] = (char*)malloc(128);
                strcpy(backups[total_backups++], de->d_name);

                if(total_backups >= BOOTMGR_BACKUPS_MAX-1)
                    break;
            }
            closedir(dir);
            backups[total_backups] = NULL;
        }
        dir = opendir("/sdroot/multirom/rom");
        if(dir)
            backups_has_active = 1;
    }

    backups_loaded = 1;

    bootmgr_printf(0, 0, (0x3F << 11), "Select ROM to boot. Press back to return");
    if(backups_has_active)
    {
        bootmgr_printf(0, 2, WHITE, "Current active ROM");
        bootmgr_select(2);
    }
    bootmgr_printf(0, 4, (0x3F << 11), "Backup folder:");

    uint16_t i = 0;
    for(; i <= 25 && i < total_backups; ++i)
        bootmgr_printf(0, i + 5, WHITE, "%s", backups[i]);

    if(total_backups)
    {
        if(!backups_has_active)
        {
            bootmgr_printf(-1, 2, WHITE, "No active ROM");
            bootmgr_select(5);
        }
        bootmgr_erase_text(20);
    }
    // Useless to print this, because it will be deleted immediately
    //else if(backups_has_active)
    //    bootmgr_printf(-1, 19, WHITE, "No backups present.");
    else
    {
        bootmgr_printf(-1, 20, WHITE, "No active ROM nor backups present.");
        bootmgr_printf(-1, 21, WHITE, "Press \"back\" to return");
    }

    while(bootmgr_get_last_key() != -1); // clear key queue
    while(bootmgr_get_last_touch(&i, &i));     // clear touch queue
    if(!total_backups && backups_has_active)
        return bootmgr_boot_sd();
    bootmgr_draw();
    return 0;
}
Beispiel #17
0
void bootmgr_start(int charger)
{
    settings.default_boot_sd = (char*)malloc(256);
    bootmgr_load_settings();
    bootmgr_init_display();

    bootmgr_set_brightness(settings.brightness);

    int key = 0;
    int8_t last_selected = -1;
    int8_t last_phase = -1;
    uint8_t key_pressed = (settings.timeout_seconds == -1);
    int16_t timer = settings.timeout_seconds*10;
    uint16_t x, y;
    uint8_t touch;
    selected = -1;

    pthread_t t_input;
    pthread_create(&t_input, NULL, bootmgr_input_thread, NULL);
    bootmgr_set_time_thread(1);

    bootmgr_selected = settings.default_boot;

    if(charger && (settings.charger_settings & CHARGER_AUTO_START))
    {
        char status[50];
        bootmgr_get_file(battery_status, status, 50);
        if(strstr(status, "Charging") == status)
        {
            key_pressed = 1;
            bootmgr_charger_init();
        }
    }
    disable_lg_charger = (settings.charger_settings & CHARGER_DISABLE_LG);

    while(bootmgr_run)
    {
        if(last_selected != bootmgr_selected)
        {
            bootmgr_draw();
            last_selected = bootmgr_selected;
        }

        if(last_phase != bootmgr_phase)
        {
            bootmgr_setup_touch();
            bootmgr_draw();
            last_phase = bootmgr_phase;
        }

        key = bootmgr_get_last_key();
        touch = bootmgr_get_last_touch(&x, &y);
        if(key != -1 || touch)
        {
            if(!key_pressed)
            {
                bootmgr_erase_text(25);
                bootmgr_draw();
                key_pressed = 1;
            }

            if(bootmgr_handle_key(key))
                break;

            if(touch && !sleep_mode)
            {
                key = bootmgr_check_touch(x, y);
                if(key & TCALL_EXIT_MGR)
                    break;
            }
        }

        usleep(100000);
        if(!key_pressed)
        {
            if(timer%10 == 0)
            {
                bootmgr_printf(-1, 25, WHITE, "Boot from %s in %us", bootmgr_selected == 0 ? "internal mem" : "SD card", timer/10);
                bootmgr_draw();
            }

            if(--timer <= 0)
            {
                bootmgr_erase_text(25);
                if(bootmgr_selected == 0)
                {
                    bootmgr_boot_internal();
                    break;
                }
                else
                {
                    if(bootmgr_boot_sd_auto())
                        break;
                }
                key_pressed = 1;
            }
        }
    }
    bootmgr_exit();
}