Example update

This commit is contained in:
lilian 2016-12-12 10:04:16 +01:00
parent ccf1ef18d2
commit 8453500330

View file

@ -3,6 +3,7 @@
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <task.h> #include <task.h>
#include <queue.h> #include <queue.h>
#include <timers.h>
#include <string.h> #include <string.h>
#include <ssd1306/ssd1306.h> #include <ssd1306/ssd1306.h>
@ -45,6 +46,11 @@ static const ssd1306_t dev = {
/* Local frame buffer */ /* Local frame buffer */
static uint8_t buffer[DISPLAY_WIDTH * DISPLAY_HEIGHT / 8]; static uint8_t buffer[DISPLAY_WIDTH * DISPLAY_HEIGHT / 8];
TimerHandle_t scrol_timer_handle = NULL; // Timer handler
#define SECOND (1000 / portTICK_PERIOD_MS)
static void ssd1306_task(void *pvParameters) static void ssd1306_task(void *pvParameters)
{ {
@ -58,7 +64,7 @@ static void ssd1306_task(void *pvParameters)
ssd1306_set_whole_display_lighting(&dev, false); ssd1306_set_whole_display_lighting(&dev, false);
bool fwd = false; bool fwd = false;
while (1) { while (1) {
vTaskDelay(2000 / portTICK_PERIOD_MS); vTaskDelay(2*SECOND);
printf("%s: still alive, flipping!\n", __FUNCTION__); printf("%s: still alive, flipping!\n", __FUNCTION__);
ssd1306_set_scan_direction_fwd(&dev, fwd); ssd1306_set_scan_direction_fwd(&dev, fwd);
fwd = !fwd; fwd = !fwd;
@ -67,11 +73,22 @@ static void ssd1306_task(void *pvParameters)
error_loop: error_loop:
printf("%s: error while loading framebuffer into SSD1306\n", __func__); printf("%s: error while loading framebuffer into SSD1306\n", __func__);
for(;;){ for(;;){
vTaskDelay(2000 / portTICK_PERIOD_MS); vTaskDelay(2*SECOND);
printf("%s: error loop\n", __FUNCTION__); printf("%s: error loop\n", __FUNCTION__);
} }
} }
void scrolling_timer(TimerHandle_t h)
{
static bool scrol = true ;
if(scrol)
ssd1306_start_scroll_hori(&dev, false, 0, 7, FRAME_25);
else
ssd1306_stop_scroll(&dev);
printf("Scrolling status: %s\n", (scrol)? "On" : "Off");
scrol=!scrol ;
}
void user_init(void) void user_init(void)
{ {
// Setup HW // Setup HW
@ -86,11 +103,16 @@ void user_init(void)
while (ssd1306_init(&dev) != 0) while (ssd1306_init(&dev) != 0)
{ {
printf("%s: failed to init SSD1306 lcd\n", __func__); printf("%s: failed to init SSD1306 lcd\n", __func__);
vTaskDelay(1000/portTICK_PERIOD_MS); vTaskDelay(SECOND);
} }
ssd1306_set_whole_display_lighting(&dev, true); ssd1306_set_whole_display_lighting(&dev, true);
vTaskDelay(1000/portTICK_PERIOD_MS); vTaskDelay(SECOND);
// Create user interface task // Create user interface task
xTaskCreate(ssd1306_task, "ssd1306_task", 256, NULL, 2, NULL); xTaskCreate(ssd1306_task, "ssd1306_task", 256, NULL, 2, NULL);
//Scrolling timer
scrol_timer_handle = xTimerCreate("fps_timer", 10*SECOND, pdTRUE, NULL, scrolling_timer);
xTimerStart(scrol_timer_handle, 0);
} }