Update example. out of range err add

This commit is contained in:
lilian 2016-12-13 08:14:49 +01:00
parent e5223d6e84
commit ce9452afff
3 changed files with 27 additions and 21 deletions

View file

@ -8,14 +8,14 @@
#include <ssd1306/ssd1306.h> #include <ssd1306/ssd1306.h>
#define LOAD_ICON_X 54 #define LOAD_ICON_X 54
#define LOAD_ICON_Y 32 #define LOAD_ICON_Y 42
#define LOAD_ICON_SIZE 20 #define LOAD_ICON_SIZE 20
#define CIRCLE_COUNT_ICON_X 94 #define CIRCLE_COUNT_ICON_X 100
#define CIRCLE_COUNT_ICON_Y 42 #define CIRCLE_COUNT_ICON_Y 52
/* Remove this line if your display connected by SPI */ /* Remove this line if your display connected by SPI */
//#define I2C_CONNECTION #define I2C_CONNECTION
#ifdef I2C_CONNECTION #ifdef I2C_CONNECTION
#include <i2c/i2c.h> #include <i2c/i2c.h>
@ -29,8 +29,8 @@
#ifdef I2C_CONNECTION #ifdef I2C_CONNECTION
#define PROTOCOL SSD1306_PROTO_I2C #define PROTOCOL SSD1306_PROTO_I2C
#define ADDR SSD1306_I2C_ADDR_0 #define ADDR SSD1306_I2C_ADDR_0
#define SCL_PIN 14 #define SCL_PIN 5
#define SDA_PIN 13 #define SDA_PIN 4
#else #else
#define PROTOCOL SSD1306_PROTO_SPI4 #define PROTOCOL SSD1306_PROTO_SPI4
#define CS_PIN 5 #define CS_PIN 5
@ -82,9 +82,10 @@ static void ssd1306_task(void *pvParameters)
while (1) { while (1) {
ssd1306_fill_rectangle(&dev, buffer, 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT/2, OLED_COLOR_BLACK);
ssd1306_draw_string(&dev, buffer, font, 0, 0, "Hello, esp-open-rtos!", OLED_COLOR_WHITE, OLED_COLOR_BLACK); ssd1306_draw_string(&dev, buffer, font, 0, 0, "Hello, esp-open-rtos!", OLED_COLOR_WHITE, OLED_COLOR_BLACK);
sprintf(text, "FPS: %u ", fps); sprintf(text, "FPS: %u ", fps);
ssd1306_draw_string(&dev, buffer, font_builtin_fonts[DEFAULT_FONT], 0, 40, text, OLED_COLOR_WHITE, OLED_COLOR_BLACK); ssd1306_draw_string(&dev, buffer, font_builtin_fonts[DEFAULT_FONT], 0, 45, text, OLED_COLOR_WHITE, OLED_COLOR_BLACK);
// generate loading icon // generate loading icon
ssd1306_draw_line(&dev, buffer, x0, y0, x1, y1, OLED_COLOR_BLACK); ssd1306_draw_line(&dev, buffer, x0, y0, x1, y1, OLED_COLOR_BLACK);

View file

@ -879,13 +879,14 @@ int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0,
return 0; return 0;
} }
uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, int ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb,
const font_info_t *font, uint8_t x, uint8_t y, char c, const font_info_t *font, uint8_t x, uint8_t y, char c,
ssd1306_color_t foreground, ssd1306_color_t background) ssd1306_color_t foreground, ssd1306_color_t background)
{ {
uint8_t i, j; uint8_t i, j;
const uint8_t *bitmap; const uint8_t *bitmap;
uint8_t line = 0; uint8_t line = 0;
int err;
if (font == NULL) if (font == NULL)
return 0; return 0;
@ -901,7 +902,7 @@ uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb,
line = bitmap[(d->width + 7) / 8 * j + i / 8]; // line data line = bitmap[(d->width + 7) / 8 * j + i / 8]; // line data
} }
if (line & 0x80) { if (line & 0x80) {
ssd1306_draw_pixel(dev, fb, x + i, y + j, foreground); err = ssd1306_draw_pixel(dev, fb, x + i, y + j, foreground);
} }
else { else {
switch (background) switch (background)
@ -911,31 +912,35 @@ uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb,
break; break;
case OLED_COLOR_WHITE: case OLED_COLOR_WHITE:
case OLED_COLOR_BLACK: case OLED_COLOR_BLACK:
ssd1306_draw_pixel(dev, fb, x + i, y + j, background); err = ssd1306_draw_pixel(dev, fb, x + i, y + j, background);
break; break;
case OLED_COLOR_INVERT: case OLED_COLOR_INVERT:
// I don't know why I need invert background // I don't know why I need invert background
break; break;
} }
} }
if (err) return -ERANGE ;
line = line << 1; line = line << 1;
} }
} }
return d->width; return d->width;
} }
uint8_t ssd1306_draw_string(const ssd1306_t *dev, uint8_t *fb, int ssd1306_draw_string(const ssd1306_t *dev, uint8_t *fb,
const font_info_t *font, uint8_t x, uint8_t y, char *str, const font_info_t *font, uint8_t x, uint8_t y, char *str,
ssd1306_color_t foreground, ssd1306_color_t background) ssd1306_color_t foreground, ssd1306_color_t background)
{ {
uint8_t t = x; uint8_t t = x;
int err;
if (font == NULL || str == NULL) if (font == NULL || str == NULL)
return 0; return 0;
while (*str) while (*str)
{ {
x += ssd1306_draw_char(dev, fb, font, x, y, *str, foreground, background); if ((err = ssd1306_draw_char(dev, fb, font, x, y, *str, foreground, background)) < 0 )
return err;
x += err;
++str; ++str;
if (*str) if (*str)
x += font->c; x += font->c;
@ -974,7 +979,7 @@ int ssd1306_start_scroll_hori(const ssd1306_t *dev, bool way, uint8_t start, uin
return -EIO; return -EIO;
} }
int ssd1306_set_scroll_hori_vert(const ssd1306_t *dev, bool way, uint8_t start, uint8_t stop, uint8_t dy, ssd1306_scroll_t frame) int ssd1306_start_scroll_hori_vert(const ssd1306_t *dev, bool way, uint8_t start, uint8_t stop, uint8_t dy, ssd1306_scroll_t frame)
{ {
//this function dont work well if no vertical setting. //this function dont work well if no vertical setting.
if ((!dy) || (dy > 63)) if ((!dy) || (dy > 63))

View file

@ -442,9 +442,9 @@ int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t
* @param c The character to draw * @param c The character to draw
* @param foreground Character color * @param foreground Character color
* @param background Background color * @param background Background color
* @return Width of the character * @return Width of the character or negative value if error occured
*/ */
uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, const font_info_t *font, uint8_t x, uint8_t y, char c, ssd1306_color_t foreground, ssd1306_color_t background); int ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, const font_info_t *font, uint8_t x, uint8_t y, char c, ssd1306_color_t foreground, ssd1306_color_t background);
/** /**
* Draw one character using currently selected font * Draw one character using currently selected font
@ -456,9 +456,9 @@ uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, const font_info_t *
* @param str The string to draw * @param str The string to draw
* @param foreground Character color * @param foreground Character color
* @param background Background color * @param background Background color
* @return Width of the string (out-of-display pixels also included) * @return Width of the string (out-of-display pixels also included) or negative value if error occured
*/ */
uint8_t ssd1306_draw_string(const ssd1306_t *dev, uint8_t *fb, const font_info_t *font, uint8_t x, uint8_t y, char *str, ssd1306_color_t foreground, ssd1306_color_t background); int ssd1306_draw_string(const ssd1306_t *dev, uint8_t *fb, const font_info_t *font, uint8_t x, uint8_t y, char *str, ssd1306_color_t foreground, ssd1306_color_t background);
/** /**
* Stop scrolling (the ram data needs to be rewritten) * Stop scrolling (the ram data needs to be rewritten)
@ -488,7 +488,7 @@ int ssd1306_start_scroll_hori(const ssd1306_t *dev, bool way, uint8_t start, uin
* @param frame Time interval between each scroll * @param frame Time interval between each scroll
* @return Non-zero if error occured * @return Non-zero if error occured
*/ */
int ssd1306_set_scroll_hori_vert(const ssd1306_t *dev, bool way, uint8_t start, uint8_t stop, uint8_t dy, ssd1306_scroll_t frame); int ssd1306_start_scroll_hori_vert(const ssd1306_t *dev, bool way, uint8_t start, uint8_t stop, uint8_t dy, ssd1306_scroll_t frame);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"