Пример #1
0
int main(void)
{
    flash_led(LED1);

    // init logger
	log_init(&mainlog, "main");

	lcd_init();
	graphics_init();
	touch_panel_init();
	lcd_backlight_init();
	lcd_backlight_auto_off(false);
	lcd_backlight_enable();
	set_background_colour(BLACK);

	panel_meter_init(&panelmeter, buffer, BOX_LOCATION, BOX_SIZE, true, "%.3f", "C", BOX_MAIN_FONT, BOX_UNIT_FONT);
	panel_meter_enable_touch(&panelmeter, (touch_callback_t)touch_key_callback, panelmeter_touch_appdata);

	float val = 0;
	while(1)
	{
		printf("val %.3f\n", (double)val);
		panel_meter_update(&panelmeter, val);
		val += 0.1;
		sleep(1);
	}

	pthread_exit(0);

    return 0;
}
Пример #2
0
int stm32_hw_lcd_init(void)
{
    _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t) * RT_HW_LCD_WIDTH * RT_HW_LCD_HEIGHT, 32);
    if (_rt_framebuffer == RT_NULL) 
        return -1; /* no memory yet */
    
    LTDC_CLK_Config();
    MX_LTDC_Init();
    lcd_backlight_init();
    MX_DMA2D_Init();
    
    _lcd_info.bits_per_pixel = LCD_BITS_PER_PIXEL;
    _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;		// RTGRAPHIC_PIXEL_FORMAT_ARGB888
    _lcd_info.framebuffer = (void *)_rt_framebuffer;
    _lcd_info.width = RT_HW_LCD_WIDTH;
    _lcd_info.height = RT_HW_LCD_HEIGHT;
    
        /* init device structure */
    lcd.type = RT_Device_Class_Graphic;
    lcd.init = rt_lcd_init;
    lcd.open = rt_lcd_open;
    lcd.close = rt_lcd_close;
    lcd.read = NULL;
    lcd.write = NULL;
    lcd.control = rt_lcd_control;
    lcd.user_data = (void *)&_lcd_info;
    
    /* register lcd device to RT-Thread */
    rt_device_register(&lcd, "lcd", RT_DEVICE_FLAG_RDWR);
    
    return 0;
}
Пример #3
0
int main(void)
{
    flash_led(LED1);
    // init logger
    log_init(&mainlog, "main");

    lcd_init();
    graphics_init();
    touch_panel_init();
    lcd_backlight_init();

    set_background_colour(BACKGROUND);
    lcd_backlight_auto_off(true);
    lcd_backlight_enable();
    lcd_backlight_timeout(30000);
    statusbar_init();

    // init filesystem
    sdfs_init();
    log_info(&mainlog, "wait for filesystem...");
    while(!sdfs_ready());

    // init networking
    net_config(&netconf, DEFAULT_RESOLV_CONF_PATH, DEFAULT_NETIF_CONF_PATH);
    net_init(&netconf);

    log_info(&mainlog, "device init done...");

    init_heater_cooler();

    log_info(&mainlog, "service init done...");

    while(1)
    {
        usleep(250000);
        update_heater_cooler();
    }

    return 0;
}
Пример #4
0
void radio_rtgui_init(void)
{
    rtgui_rect_t rect;

    rtgui_system_server_init();

    /* register dock panel */
    rect.x1 = 0;
    rect.y1 = 0;
    rect.x2 = 240;
    rect.y2 = 25;
    rtgui_panel_register("info", &rect);
    rtgui_panel_set_nofocused("info");

    /* register main panel */
    rect.x1 = 0;
    rect.y1 = 25;
    rect.x2 = 240;
    rect.y2 = 320;
    rtgui_panel_register("main", &rect);
    rtgui_panel_set_default_focused("main");

    //rt_hw_lcd_init();
    {
#if LCD_VERSION == 1
#include "fmt0371/FMT0371.h"
        _rtgui_lcd_driver.name            = "lcd";
        _rtgui_lcd_driver.byte_per_pixel  = 2;
        _rtgui_lcd_driver.width           = 240;
        _rtgui_lcd_driver.height          = 320;
        _rtgui_lcd_driver.draw_hline      = fmt_lcd_draw_hline;
        _rtgui_lcd_driver.draw_raw_hline  = fmt_lcd_draw_raw_hline;
        _rtgui_lcd_driver.draw_vline      = fmt_lcd_draw_vline;
        _rtgui_lcd_driver.get_pixel       = fmt_lcd_get_pixel;
        _rtgui_lcd_driver.set_pixel       = fmt_lcd_set_pixel;
        _rtgui_lcd_driver.screen_update   = fmt_lcd_update;
        _rtgui_lcd_driver.get_framebuffer = fmt_lcd_get_framebuffer;
        fmt_lcd_init();
#elif LCD_VERSION == 2
#include "ili_lcd_general.h"
        _rtgui_lcd_driver.name            = "lcd";
        _rtgui_lcd_driver.byte_per_pixel  = 2;
        _rtgui_lcd_driver.width           = 240;
        _rtgui_lcd_driver.height          = 320;
        _rtgui_lcd_driver.draw_hline      = rt_hw_lcd_draw_hline;
        _rtgui_lcd_driver.draw_raw_hline  = rt_hw_lcd_draw_raw_hline;
        _rtgui_lcd_driver.draw_vline      = rt_hw_lcd_draw_vline;
        _rtgui_lcd_driver.get_pixel       = rt_hw_lcd_get_pixel;
        _rtgui_lcd_driver.set_pixel       = rt_hw_lcd_set_pixel;
        _rtgui_lcd_driver.screen_update   = rt_hw_lcd_update;
        _rtgui_lcd_driver.get_framebuffer = rt_hw_lcd_get_framebuffer;
        lcd_Initializtion();
#elif LCD_VERSION == 3
#include "ssd1289.h"
        _rtgui_lcd_driver.name            = "lcd";
        _rtgui_lcd_driver.byte_per_pixel  = 2;
        _rtgui_lcd_driver.width           = 240;
        _rtgui_lcd_driver.height          = 320;
        _rtgui_lcd_driver.draw_hline      = ssd1289_lcd_draw_hline;
        _rtgui_lcd_driver.draw_raw_hline  = ssd1289_lcd_draw_raw_hline;
        _rtgui_lcd_driver.draw_vline      = ssd1289_lcd_draw_vline;
        _rtgui_lcd_driver.get_pixel       = ssd1289_lcd_get_pixel;
        _rtgui_lcd_driver.set_pixel       = ssd1289_lcd_set_pixel;
        _rtgui_lcd_driver.screen_update   = ssd1289_lcd_update;
        _rtgui_lcd_driver.get_framebuffer = ssd1289_lcd_get_framebuffer;
        ssd1289_init();
#endif
    }//rt_hw_lcd_init

    /* add lcd driver into graphic driver */
    rtgui_graphic_driver_add(&_rtgui_lcd_driver);

    info_init();
    player_init();

    lcd_backlight_init();
}
Пример #5
0
static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
    (void)arg;

    GListener event_listener;
    geventListenerInit(&event_listener);
    geventAttachSource(&event_listener, (GSourceHandle)&current_status, 0);

    visualizer_keyboard_status_t initial_status = {
        .default_layer = 0xFFFFFFFF,
        .layer = 0xFFFFFFFF,
        .mods = 0xFF,
        .leds = 0xFFFFFFFF,
        .suspended = false,
    };

    visualizer_state_t state = {
        .status = initial_status,
        .current_lcd_color = 0,
#ifdef LCD_ENABLE
        .font_fixed5x8 = gdispOpenFont("fixed_5x8"),
        .font_dejavusansbold12 = gdispOpenFont("DejaVuSansBold12")
#endif
    };
    initialize_user_visualizer(&state);
    state.prev_lcd_color = state.current_lcd_color;

#ifdef LCD_BACKLIGHT_ENABLE
    lcd_backlight_color(
            LCD_HUE(state.current_lcd_color),
            LCD_SAT(state.current_lcd_color),
            LCD_INT(state.current_lcd_color));
#endif

    systemticks_t sleep_time = TIME_INFINITE;
    systemticks_t current_time = gfxSystemTicks();

    while(true) {
        systemticks_t new_time = gfxSystemTicks();
        systemticks_t delta = new_time - current_time;
        current_time = new_time;
        bool enabled = visualizer_enabled;
        if (!same_status(&state.status, &current_status)) {
            if (visualizer_enabled) {
                if (current_status.suspended) {
                    stop_all_keyframe_animations();
                    visualizer_enabled = false;
                    state.status = current_status;
                    user_visualizer_suspend(&state);
                }
                else {
                    state.status = current_status;
                    update_user_visualizer_state(&state);
                }
                state.prev_lcd_color = state.current_lcd_color;
            }
        }
        if (!enabled && state.status.suspended && current_status.suspended == false) {
            // Setting the status to the initial status will force an update
            // when the visualizer is enabled again
            state.status = initial_status;
            state.status.suspended = false;
            stop_all_keyframe_animations();
            user_visualizer_resume(&state);
            state.prev_lcd_color = state.current_lcd_color;
        }
        sleep_time = TIME_INFINITE;
        for (int i=0;i<MAX_SIMULTANEOUS_ANIMATIONS;i++) {
            if (animations[i]) {
                update_keyframe_animation(animations[i], &state, delta, &sleep_time);
            }
        }
#ifdef LED_ENABLE
        gdispGFlush(LED_DISPLAY);
#endif

#ifdef EMULATOR
        draw_emulator();
#endif
        // The animation can enable the visualizer
        // And we might need to update the state when that happens
        // so don't sleep
        if (enabled != visualizer_enabled) {
            sleep_time = 0;
        }

        systemticks_t after_update = gfxSystemTicks();
        unsigned update_delta = after_update - current_time;
        if (sleep_time != TIME_INFINITE) {
            if (sleep_time > update_delta) {
                sleep_time -= update_delta;
            }
            else {
                sleep_time = 0;
            }
        }
        dprintf("Update took %d, last delta %d, sleep_time %d\n", update_delta, delta, sleep_time);
#ifdef PROTOCOL_CHIBIOS
        // The gEventWait function really takes milliseconds, even if the documentation says ticks.
        // Unfortunately there's no generic ugfx conversion from system time to milliseconds,
        // so let's do it in a platform dependent way.

        // On windows the system ticks is the same as milliseconds anyway
        if (sleep_time != TIME_INFINITE) {
            sleep_time = ST2MS(sleep_time);
        }
#endif
        geventEventWait(&event_listener, sleep_time);
    }
#ifdef LCD_ENABLE
    gdispCloseFont(state.font_fixed5x8);
    gdispCloseFont(state.font_dejavusansbold12);
#endif

    return 0;
}

void visualizer_init(void) {
    gfxInit();

#ifdef LCD_BACKLIGHT_ENABLE
    lcd_backlight_init();
#endif

#ifdef SERIAL_LINK_ENABLE
    add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t*) );
#endif

#ifdef LCD_ENABLE
    LCD_DISPLAY = get_lcd_display();
#endif
#ifdef LED_ENABLE
    LED_DISPLAY = get_led_display();
#endif

    // We are using a low priority thread, the idea is to have it run only
    // when the main thread is sleeping during the matrix scanning
    gfxThreadCreate(visualizerThreadStack, sizeof(visualizerThreadStack),
                              VISUALIZER_THREAD_PRIORITY, visualizerThread, NULL);
}

void update_status(bool changed) {
    if (changed) {
        GSourceListener* listener = geventGetSourceListener((GSourceHandle)&current_status, NULL);
        if (listener) {
            geventSendEvent(listener);
        }
    }
#ifdef SERIAL_LINK_ENABLE
    static systime_t last_update = 0;
    systime_t current_update = chVTGetSystemTimeX();
    systime_t delta = current_update - last_update;
    if (changed || delta > MS2ST(10)) {
        last_update = current_update;
        visualizer_keyboard_status_t* r = begin_write_current_status();
        *r = current_status;
        end_write_current_status();
    }
#endif
}

uint8_t visualizer_get_mods() {
  uint8_t mods = get_mods();

#ifndef NO_ACTION_ONESHOT
  if (!has_oneshot_mods_timed_out()) {
    mods |= get_oneshot_mods();
  }
#endif  
  return mods;
}

void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds) {
    // Note that there's a small race condition here, the thread could read
    // a state where one of these are set but not the other. But this should
    // not really matter as it will be fixed during the next loop step.
    // Alternatively a mutex could be used instead of the volatile variables

    bool changed = false;
#ifdef SERIAL_LINK_ENABLE
    if (is_serial_link_connected ()) {
        visualizer_keyboard_status_t* new_status = read_current_status();
        if (new_status) {
            if (!same_status(&current_status, new_status)) {
                changed = true;
                current_status = *new_status;
            }
        }
    }
    else {
#else
   {
#endif
        visualizer_keyboard_status_t new_status = {
            .layer = state,
            .default_layer = default_state,
            .mods = mods,
            .leds = leds,
            .suspended = current_status.suspended,
        };
        if (!same_status(&current_status, &new_status)) {
            changed = true;
            current_status = new_status;
        }
    }
    update_status(changed);
}

void visualizer_suspend(void) {
    current_status.suspended = true;
    update_status(true);
}

void visualizer_resume(void) {
    current_status.suspended = false;
    update_status(true);
}