Exemplo n.º 1
0
static void time_greyscale(void)
{
    char str[32];     /* text buffer */
    long time_start;  /* start tickcount */
    long time_end;    /* end tickcount */
    long time_1, time_2;
    int frames_1, frames_2;
    int fps, load;

    gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
    if (!grey_init(gbuf, gbuf_size, GREY_ON_COP,
                   LCD_WIDTH, LCD_HEIGHT, NULL))
    {
        log_text("greylib: out of memory.");
        return;
    }
    make_grey_rect(LCD_WIDTH, LCD_HEIGHT);

    /* Test 1 - greyscale overlay not yet enabled */
    frames_1 = 0;
    rb->sleep(0); /* sync to tick */
    time_start = *rb->current_tick;
    while((time_end = *rb->current_tick) - time_start < DURATION)
    {
        grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
        frames_1++;
    }
    time_1 = time_end - time_start;
    
    /* Test 2 - greyscale overlay enabled */
    grey_show(true);
    frames_2 = 0;
    rb->sleep(0); /* sync to tick */
    time_start = *rb->current_tick;
    while((time_end = *rb->current_tick) - time_start < DURATION)
    {
        grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
        frames_2++;
    }
    time_2 = time_end - time_start;

    grey_release();
    fps = calc_tenth_fps(frames_2, time_2);
    load = 100 - (100 * frames_2 * time_1) / (frames_1 * time_2);
    rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
    log_text(str);

    if (load > 0 && load < 100)
    {
        rb->snprintf(str, sizeof(str), "CPU load: %d%%", load);
        log_text(str);
    }
    else
        log_text("CPU load err (boost?)");
}
Exemplo n.º 2
0
/* this is the plugin entry point */
enum plugin_status plugin_start(const void* parameter)
{
    void * plugin_buf;
    size_t plugin_buf_len;
    static char filename[MAX_PATH];
    struct bitmap grey_bm = {
        .width = LCD_WIDTH,
        .height = LCD_HEIGHT,
        .data = grey_bm_buf
    };
    int ret, x, y;

    if(!parameter) return PLUGIN_ERROR;

    rb->strcpy(filename, parameter);

    ret = BMP_LOAD(filename, &grey_bm, sizeof(grey_bm_buf),
                   FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
                   &format_grey);
    
    if(ret < 1)
    {
        rb->splash(HZ*2, "failed to load bitmap");
        return PLUGIN_ERROR;
    }

    plugin_buf = rb->plugin_get_buffer(&plugin_buf_len);
    if(!grey_init(plugin_buf, plugin_buf_len, 0, LCD_WIDTH, LCD_HEIGHT,
                  NULL))
    {
        rb->splash(HZ*2,"grey init failed");
        return PLUGIN_ERROR;
    }
    grey_ub_clear_display();
    x = (LCD_WIDTH - grey_bm.width) / 2;
    y = (LCD_HEIGHT - grey_bm.height) / 2;
    grey_ub_gray_bitmap(grey_bm_buf, x, y, grey_bm.width, grey_bm.height);
    grey_show(true);

    /* wait until user closes plugin */
    while (rb->button_get(true) != GBS_QUIT);

    grey_release();
    
    return PLUGIN_OK;
}
Exemplo n.º 3
0
static void time_greyscale(void)
{
    char str[32];     /* text buffer */
    long time_start;  /* start tickcount */
    long time_end;    /* end tickcount */
    long time_1, time_2;
    int frames_1, frames_2;
    int fps, load;
    size_t gbuf_size;
    unsigned char *gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);

#if NUM_CORES > 1
    int i;
    for (i = 0; i < NUM_CORES; i++)
    {
        rb->snprintf(str, sizeof(str), "Greyscale (%s)",
                     (i > 0) ? "COP" : "CPU");
        log_text(str);
#else
    const int i = 0;
    log_text("Greyscale library");
    {
#endif

        if (!grey_init(gbuf, gbuf_size, (i > 0) ? GREY_ON_COP : 0,
                       LCD_WIDTH, LCD_HEIGHT, NULL))
        {
            log_text("greylib: out of memory.");
            return;
        }
        make_grey_rect(LCD_WIDTH, LCD_HEIGHT);

        /* Test 1 - greyscale overlay not yet enabled */
        frames_1 = 0;
        rb->sleep(0); /* sync to tick */
        time_start = *rb->current_tick;
        while((time_end = *rb->current_tick) - time_start < DURATION)
        {
            grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
            frames_1++;
        }
        time_1 = time_end - time_start;
    
        /* Test 2 - greyscale overlay enabled */
        grey_show(true);
        frames_2 = 0;
        rb->sleep(0); /* sync to tick */
        time_start = *rb->current_tick;
        while((time_end = *rb->current_tick) - time_start < DURATION)
        {
            grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
            frames_2++;
        }
        time_2 = time_end - time_start;

        grey_release();
        fps = calc_tenth_fps(frames_2, time_2);
        load = 100 - (100 * frames_2 * time_1) / (frames_1 * time_2);
        rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
        log_text(str);

        if (load > 0 && load < 100)
        {
            rb->snprintf(str, sizeof(str), "CPU load: %d%%", load);
            log_text(str);
        }
        else
            log_text("CPU load err (boost?)");
    }
}
#endif

void plugin_quit(void)
{
#ifdef HAVE_TOUCHSCREEN
    static struct touchbutton button[] = {{
            .action = ACTION_STD_OK,
            .title = "OK",
            /* .vp runtime initialized, rest false/NULL */
    }};
    struct viewport *vp = &button[0].vp;
    struct screen *lcd = rb->screens[SCREEN_MAIN];
    rb->viewport_set_defaults(vp, SCREEN_MAIN);
    const int border = 10;
    const int height = 50;

    lcd->set_viewport(vp);
    /* button matches the bottom center in the grid */
    vp->x = lcd->lcdwidth/3;
    vp->width = lcd->lcdwidth/3;
    vp->height = height;
    vp->y = lcd->lcdheight - height - border;

    touchbutton_draw(button, ARRAYLEN(button));
    lcd->update_viewport();
    if (rb->touchscreen_get_mode() == TOUCHSCREEN_POINT)
    {
        while(touchbutton_get(button, ARRAYLEN(button)) != ACTION_STD_OK);
    }
    else
#endif
        while (1)
        {
            int btn = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts,
                                                   ARRAYLEN(plugin_contexts));
            exit_on_usb(btn);
            if ((btn == FPS_QUIT) || (btn == FPS_QUIT2))
                break;
        }
}
Exemplo n.º 4
0
int main(void)
{
    plasma_frequency = 1;
    int button, delay, x, y;
    unsigned char p1,p2,p3,p4,t1,t2,t3,t4, z,z0;
    long last_tick = *rb->current_tick;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
    int cumulated_lag = 0;
#endif
#ifdef HAVE_LCD_COLOR
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
    unsigned char *ptr;
#else
    fb_data *ptr;
#endif
    int time=0;
#else
    unsigned char *ptr;
#endif

    /*Generate the neccesary pre calced stuff*/
    wave_table_generate();

#ifndef HAVE_LCD_COLOR
    shades_generate();  /* statically */

    /* get the remainder of the plugin buffer */
    gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);

    grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL);
    /* switch on greyscale overlay */
    grey_show(true);
#endif
    sp1 = 4;
    sp2 = 2;
    sp3 = 4;
    sp4 = 2;
    p1=p2=p3=p4=0;
    while (true)
    {
#ifdef HAVE_LCD_COLOR
        shades_generate(time++); /* dynamically */
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
        ptr = (unsigned char*)rb->lcd_framebuffer;
#else
        ptr = rb->lcd_framebuffer;
#endif

#else
        ptr = greybuffer;
#endif
        t1=p1;
        t2=p2;
        for(y = 0; y < LCD_HEIGHT; ++y)
        {
            t3=p3;
            t4=p4;
            z0 = wave_array[t1] + wave_array[t2];
            for(x = 0; x < LCD_WIDTH; ++x)
            {
                z = z0 + wave_array[t3] + wave_array[t4];
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
                *ptr++ = z;
#else
                *ptr++ = colours[z];
#endif
                t3+=1;
                t4+=2;
            }
            t1+=2;
            t2+=1;
            rb->yield();
        }
        p1+=sp1;
        p2-=sp2;
        p3+=sp3;
        p4-=sp4;
#ifdef HAVE_LCD_COLOR
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
        rb->lcd_blit_pal256(    (unsigned char*)rb->lcd_framebuffer,
                                0,0,0,0,LCD_WIDTH,LCD_HEIGHT);
#else
        rb->lcd_update();
#endif
#else
        grey_ub_gray_bitmap(greybuffer, 0, 0, LCD_WIDTH, LCD_HEIGHT);
#endif

        delay = last_tick - *rb->current_tick + HZ/33;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
        if (!boosted && delay < 0)
        {
            cumulated_lag -= delay;     /* proportional increase */
            if (cumulated_lag >= HZ)
                rb->cpu_boost(boosted = true);
        }
        else if (boosted && delay > 1)  /* account for jitter */
        {
            if (--cumulated_lag <= 0)   /* slow decrease */
                rb->cpu_boost(boosted = false);
        }
#endif
        button = rb->button_get_w_tmo(MAX(0, delay));
        last_tick = *rb->current_tick;

        switch(button)
        {
#ifdef PLASMA_RC_QUIT
            case PLASMA_RC_QUIT:
#endif
            case(PLASMA_QUIT):
                cleanup(NULL);
                return PLUGIN_OK;
                break;

            case (PLASMA_INCREASE_FREQUENCY):
                ++plasma_frequency;
                wave_table_generate();
                break;

            case (PLASMA_DECREASE_FREQUENCY):
                if(plasma_frequency>1)
                {
                    --plasma_frequency;
                    wave_table_generate();
                }
                break;
#ifdef HAVE_LCD_COLOR
            case (PLASMA_REGEN_COLORS):
                redfactor=rb->rand()%4;
                greenfactor=rb->rand()%4;
                bluefactor=rb->rand()%4;
                redphase=rb->rand()%256;
                greenphase=rb->rand()%256;
                bluephase=rb->rand()%256;
                break;
#endif

            default:
                if (rb->default_event_handler_ex(button, cleanup, NULL)
                    == SYS_USB_CONNECTED)
                    return PLUGIN_USB_CONNECTED;
                break;
        }
    }
}
Exemplo n.º 5
0
int main(void)
{
    plasma_frequency = 1;
    int action, x, y;
    unsigned char p1,p2,p3,p4,t1,t2,t3,t4, z,z0;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
    long last_tick = *rb->current_tick;
    int delay;
    int cumulated_lag = 0;
#endif
#ifdef HAVE_LCD_COLOR
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
    unsigned char *ptr;
#else
    fb_data *ptr;
#endif
    int time=0;
#else
    unsigned char *ptr;
#endif

    /*Generate the neccesary pre calced stuff*/
    wave_table_generate();

#ifndef HAVE_LCD_COLOR
    shades_generate();  /* statically */

    /* get the remainder of the plugin buffer */
    gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);

    if (!grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL))
    {
        rb->splash(HZ, "Couldn't init greyscale display");
        return PLUGIN_ERROR;
    }
    /* switch on greyscale overlay */
    grey_show(true);
#endif
    atexit(cleanup);
    sp1 = 4;
    sp2 = 2;
    sp3 = 4;
    sp4 = 2;
    p1=p2=p3=p4=0;
    while (true)
    {
#ifdef HAVE_LCD_COLOR
        shades_generate(time++); /* dynamically */
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
        ptr = (unsigned char*)rb->lcd_framebuffer;
#else
        ptr = rb->lcd_framebuffer;
#endif

#else
        ptr = greybuffer;
#endif
        t1=p1;
        t2=p2;
        for(y = 0; y < LCD_HEIGHT; ++y)
        {
            t3=p3;
            t4=p4;
            z0 = wave_array[t1] + wave_array[t2];
            for(x = 0; x < LCD_WIDTH; ++x)
            {
                z = z0 + wave_array[t3] + wave_array[t4];
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
                *ptr++ = z;
#else
                *ptr++ = colours[z];
#endif
                t3+=1;
                t4+=2;
            }
            t1+=2;
            t2+=1;
            rb->yield();
        }
        p1+=sp1;
        p2-=sp2;
        p3+=sp3;
        p4-=sp4;
#ifdef HAVE_LCD_COLOR
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
        rb->lcd_blit_pal256(    (unsigned char*)rb->lcd_framebuffer,
                                0,0,0,0,LCD_WIDTH,LCD_HEIGHT);
#else
        rb->lcd_update();
#endif
#else
        grey_ub_gray_bitmap(greybuffer, 0, 0, LCD_WIDTH, LCD_HEIGHT);
#endif

#ifdef HAVE_ADJUSTABLE_CPU_FREQ
        delay = last_tick - *rb->current_tick + HZ/33;
        if (!boosted && delay < 0)
        {
            cumulated_lag -= delay;     /* proportional increase */
            if (cumulated_lag >= HZ)
                rb->cpu_boost(boosted = true);
        }
        else if (boosted && delay > 1)  /* account for jitter */
        {
            if (--cumulated_lag <= 0)   /* slow decrease */
                rb->cpu_boost(boosted = false);
        }
        last_tick = *rb->current_tick;
#endif
        action = pluginlib_getaction(0, plugin_contexts,
                        ARRAYLEN(plugin_contexts));

        switch(action)
        {
            case PLA_EXIT:
            case PLA_CANCEL:
                return PLUGIN_OK;
                break;

#ifdef HAVE_SCROLLWHEEL
            case PLA_SCROLL_FWD:
            case PLA_SCROLL_FWD_REPEAT:
#endif
            case PLA_UP:
            case PLA_UP_REPEAT:
                ++plasma_frequency;
                wave_table_generate();
                break;

#ifdef HAVE_SCROLLWHEEL
            case PLA_SCROLL_BACK:
            case PLA_SCROLL_BACK_REPEAT:
#endif
            case PLA_DOWN:
            case PLA_DOWN_REPEAT:
                if(plasma_frequency>1)
                {
                    --plasma_frequency;
                    wave_table_generate();
                }
                break;
#ifdef HAVE_LCD_COLOR
            case PLA_SELECT:
                redfactor=rb->rand()%4;
                greenfactor=rb->rand()%4;
                bluefactor=rb->rand()%4;
                redphase=rb->rand()%256;
                greenphase=rb->rand()%256;
                bluephase=rb->rand()%256;
                break;
#endif

            default:
                exit_on_usb(action);
                break;
        }
    }
}