Skip to content

Commit

Permalink
Merge pull request #702 from pimoroni/docs/inky73
Browse files Browse the repository at this point in the history
Inky 7.3 tweaks & docs
  • Loading branch information
Gadgetoid authored Mar 8, 2023
2 parents 789e63b + a448043 commit faf4efa
Show file tree
Hide file tree
Showing 16 changed files with 578 additions and 79 deletions.
4 changes: 2 additions & 2 deletions drivers/pcf85063a/pcf85063a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace pimoroni {
}

datetime_t PCF85063A::get_datetime() {
static uint8_t result[7] = {0};
uint8_t result[7] = {0};

i2c->read_bytes(address, Registers::SECONDS, result, 7);

Expand All @@ -72,7 +72,7 @@ namespace pimoroni {
}

void PCF85063A::set_datetime(datetime_t *t) {
static uint8_t data[7] = {
uint8_t data[7] = {
bcd_encode((uint)t->sec),
bcd_encode((uint)t->min),
bcd_encode((uint)t->hour),
Expand Down
29 changes: 25 additions & 4 deletions libraries/pico_graphics/pico_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ namespace pimoroni {
}
}

void PicoGraphics::set_thickness(uint t) {
thickness = t;
}

void PicoGraphics::set_clip(const Rect &r) {
clip = bounds.intersection(r);
}
Expand Down Expand Up @@ -284,6 +288,25 @@ namespace pimoroni {
}

void PicoGraphics::thick_line(Point p1, Point p2, uint thickness) {
int32_t ht = thickness / 2;
int32_t t = (int32_t)thickness;

// fast horizontal line
if(p1.y == p2.y) {
int32_t start = std::min(p1.x, p2.x);
int32_t end = std::max(p1.x, p2.x);
rectangle(Rect(start, p1.y - ht, end - start, t));
return;
}

// fast vertical line
if(p1.x == p2.x) {
int32_t start = std::min(p1.y, p2.y);
int32_t length = std::max(p1.y, p2.y) - start;
rectangle(Rect(p1.x - ht, start, t, length));
return;
}

// general purpose line
// lines are either "shallow" or "steep" based on whether the x delta
// is greater than the y delta
Expand All @@ -298,8 +321,7 @@ namespace pimoroni {
int32_t x = p1.x;
int32_t y = p1.y << 16;
while(s--) {
int32_t ht = thickness / 2;
rectangle({x - ht, (y >> 16) - ht, ht * 2, ht * 2});
rectangle({x - ht, (y >> 16) - ht, t, t});
y += sy;
x += sx;
}
Expand All @@ -311,8 +333,7 @@ namespace pimoroni {
int32_t y = p1.y;
int32_t x = p1.x << 16;
while(s--) {
int32_t ht = thickness / 2;
rectangle({(x >> 16) - ht, y - ht, ht * 2, ht * 2});
rectangle({(x >> 16) - ht, y - ht, t, t});
y += sy;
x += sx;
}
Expand Down
11 changes: 1 addition & 10 deletions libraries/pico_graphics/pico_graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ namespace pimoroni {
virtual void set_pen(uint8_t r, uint8_t g, uint8_t b) = 0;
virtual void set_pixel(const Point &p) = 0;
virtual void set_pixel_span(const Point &p, uint l) = 0;
virtual void set_thickness(uint t) = 0;
void set_thickness(uint t);

virtual int get_palette_size();
virtual RGB* get_palette();
Expand Down Expand Up @@ -304,7 +304,6 @@ namespace pimoroni {
PicoGraphics_Pen1Bit(uint16_t width, uint16_t height, void *frame_buffer);
void set_pen(uint c) override;
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override;

void set_pixel(const Point &p) override;
void set_pixel_span(const Point &p, uint l) override;
Expand All @@ -321,7 +320,6 @@ namespace pimoroni {
PicoGraphics_Pen1BitY(uint16_t width, uint16_t height, void *frame_buffer);
void set_pen(uint c) override;
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override;

void set_pixel(const Point &p) override;
void set_pixel_span(const Point &p, uint l) override;
Expand Down Expand Up @@ -364,7 +362,6 @@ namespace pimoroni {

void set_pen(uint c) override;
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override {};
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
int create_pen_hsv(float h, float s, float v) override;

Expand Down Expand Up @@ -397,7 +394,6 @@ namespace pimoroni {
PicoGraphics_PenP4(uint16_t width, uint16_t height, void *frame_buffer);
void set_pen(uint c) override;
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override {};
int update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b) override;
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
int create_pen_hsv(float h, float s, float v) override;
Expand Down Expand Up @@ -431,7 +427,6 @@ namespace pimoroni {
PicoGraphics_PenP8(uint16_t width, uint16_t height, void *frame_buffer);
void set_pen(uint c) override;
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override {};
int update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b) override;
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
int create_pen_hsv(float h, float s, float v) override;
Expand All @@ -457,7 +452,6 @@ namespace pimoroni {
PicoGraphics_PenRGB332(uint16_t width, uint16_t height, void *frame_buffer);
void set_pen(uint c) override;
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override {};
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
int create_pen_hsv(float h, float s, float v) override;
void set_pixel(const Point &p) override;
Expand All @@ -480,7 +474,6 @@ namespace pimoroni {
PicoGraphics_PenRGB565(uint16_t width, uint16_t height, void *frame_buffer);
void set_pen(uint c) override;
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override {};
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
int create_pen_hsv(float h, float s, float v) override;
void set_pixel(const Point &p) override;
Expand All @@ -497,7 +490,6 @@ namespace pimoroni {
PicoGraphics_PenRGB888(uint16_t width, uint16_t height, void *frame_buffer);
void set_pen(uint c) override;
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override {};
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
int create_pen_hsv(float h, float s, float v) override;
void set_pixel(const Point &p) override;
Expand Down Expand Up @@ -570,7 +562,6 @@ namespace pimoroni {
PicoGraphics_PenInky7(uint16_t width, uint16_t height, IDirectDisplayDriver<uint8_t> &direct_display_driver);
void set_pen(uint c) override;
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
void set_thickness(uint t) override {};
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
int create_pen_hsv(float h, float s, float v) override;
void set_pixel(const Point &p) override;
Expand Down
4 changes: 0 additions & 4 deletions libraries/pico_graphics/pico_graphics_pen_1bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ namespace pimoroni {
color = std::max(r, std::max(g, b)) >> 4;
}

void PicoGraphics_Pen1Bit::set_thickness(uint t) {
thickness = t;
}

void PicoGraphics_Pen1Bit::set_pixel(const Point &p) {
// pointer to byte in framebuffer that contains this pixel
uint8_t *buf = (uint8_t *)frame_buffer;
Expand Down
4 changes: 0 additions & 4 deletions libraries/pico_graphics/pico_graphics_pen_1bitY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ namespace pimoroni {
color = std::max(r, std::max(g, b));
}

void PicoGraphics_Pen1BitY::set_thickness(uint t) {
thickness = t;
}

void PicoGraphics_Pen1BitY::set_pixel(const Point &p) {
// pointer to byte in framebuffer that contains this pixel
uint8_t *buf = (uint8_t *)frame_buffer;
Expand Down
6 changes: 6 additions & 0 deletions micropython/examples/inky_frame/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [Random Joke](#random-joke)
- [SD Card Test](#sd-card-test)
- [XKCD Daily](#xkcd-daily)
- [Dithering](#dithering)

## PicoGraphics

Expand Down Expand Up @@ -91,3 +92,8 @@ The webcomic is rendered "offline" by our feed2image service since xkcd.com requ

For bugs/contributions see: https://github.com/pimoroni/feed2image

### Dithering
[inky_frame_dithering.py](inky_frame_dithering.py)

A basic example showing automatic dithering in action, as PicoGraphics tries to use Inky Frame's limited colour palette to match arbitrary colours.

35 changes: 20 additions & 15 deletions micropython/examples/inky_frame/image_gallery/image_gallery.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# An offline image gallery that switches between five jpg images
# Copy them into your Pico's flash using Thonny.
# If you want to use your own images they must be 600 x 448 pixels or smaller
# and saved as *non-progressive* jpgs
# Copy them into the root of your Pico's flash using Thonny.

from pimoroni import ShiftRegister
from picographics import PicoGraphics, DISPLAY_INKY_FRAME
# If you want to use your own images they must be the screen dimensions (or smaller)
# and saved as *non-progressive* jpgs.

# Make sure to uncomment the correct size for your display!

from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
from machine import Pin
import jpegdec
from pimoroni import ShiftRegister

# you can change your file names here
IMAGE_A = "jwst1.jpg"
Expand All @@ -16,7 +21,7 @@
IMAGE_E = "jwst5.jpg"

# set up the display
display = PicoGraphics(display=DISPLAY_INKY_FRAME)
graphics = PicoGraphics(DISPLAY)

# Inky Frame uses a shift register to read the buttons
SR_CLOCK = 8
Expand All @@ -42,14 +47,7 @@
hold_vsys_en_pin.value(True)

# Create a new JPEG decoder for our PicoGraphics
j = jpegdec.JPEG(display)

# setup
activity_led.on()
# update the image on Inky every time it's powered up
# comment these lines out if running on battery power
# button_a_led.on()
# display_image(IMAGE_A)
j = jpegdec.JPEG(graphics)


def display_image(filename):
Expand All @@ -61,8 +59,15 @@ def display_image(filename):
j.decode(0, 0, jpegdec.JPEG_SCALE_FULL)

# Display the result
display.update()
graphics.update()


# setup
activity_led.on()
# update the image on Inky every time it's powered up
# comment these lines out if running on battery power
# button_a_led.on()
# display_image(IMAGE_A)

while True:
button_a_led.off()
Expand Down
30 changes: 18 additions & 12 deletions micropython/examples/inky_frame/image_gallery/image_gallery_sd.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# An offline image gallery that switches between five jpg images
# on your SD card (copy them across by plugging your SD into a computer).
# If you want to use your own images they must be 600 x 448 pixels or smaller

# If you want to use your own images they must be the screen dimensions (or smaller)
# and saved as *non-progressive* jpgs

# Make sure to uncomment the correct size for your display!

from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
from pimoroni import ShiftRegister
from picographics import PicoGraphics, DISPLAY_INKY_FRAME
from machine import Pin, SPI
import jpegdec
import sdcard
import uos


# you can change your file names here
IMAGE_A = "sd/jwst1.jpg"
IMAGE_B = "sd/jwst2.jpg"
Expand All @@ -18,7 +24,7 @@
IMAGE_E = "sd/jwst5.jpg"

# set up the display
display = PicoGraphics(display=DISPLAY_INKY_FRAME)
graphics = PicoGraphics(DISPLAY)

# Inky Frame uses a shift register to read the buttons
SR_CLOCK = 8
Expand Down Expand Up @@ -49,14 +55,7 @@
hold_vsys_en_pin.value(True)

# Create a new JPEG decoder for our PicoGraphics
j = jpegdec.JPEG(display)

# setup
activity_led.on()
# update the image on Inky every time it's powered up
# comment these lines out if running on battery power
# button_a_led.on()
# display_image(IMAGE_A)
j = jpegdec.JPEG(graphics)


def display_image(filename):
Expand All @@ -68,8 +67,15 @@ def display_image(filename):
j.decode(0, 0, jpegdec.JPEG_SCALE_FULL)

# Display the result
display.update()
graphics.update()


# setup
activity_led.on()
# update the image on Inky every time it's powered up
# comment these lines out if running on battery power
# button_a_led.on()
# display_image(IMAGE_A)

while True:
button_a_led.off()
Expand Down
68 changes: 68 additions & 0 deletions micropython/examples/inky_frame/inky_frame_dithering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"

graphics = PicoGraphics(DISPLAY)

WIDTH, HEIGHT = graphics.get_bounds()

graphics.set_pen(1)
graphics.clear()

w = int(WIDTH / 8)

# Solid Colours

for p in range(8):
graphics.set_pen(p)
graphics.rectangle(w * p, 0, w, 50)

# "Greydient"

for x in range(WIDTH):
g = int(x / float(WIDTH) * 255)
graphics.set_pen(graphics.create_pen(g, g, g))
for y in range(30):
graphics.pixel(x, 60 + y)

# Rainbow Gradient

for x in range(WIDTH):
h = x / float(WIDTH)
graphics.set_pen(graphics.create_pen_hsv(h, 1.0, 1.0))
for y in range(100):
graphics.pixel(x, 100 + y)

# Block Colours & Text

graphics.set_pen(graphics.create_pen(128, 128, 0))
graphics.rectangle(0, 210, 200, 100)
graphics.set_pen(graphics.create_pen(200, 200, 200))
graphics.text("Hello", 10, 220)
graphics.text("Hello", 10, 240, scale=4.0)

graphics.set_pen(graphics.create_pen(0, 128, 128))
graphics.rectangle(200, 210, 200, 100)
graphics.set_pen(graphics.create_pen(200, 200, 200))
graphics.text("Hello", 210, 220)
graphics.text("Hello", 210, 240, scale=4.0)

graphics.set_pen(graphics.create_pen(128, 0, 128))
graphics.rectangle(400, 210, 200, 100)
graphics.set_pen(graphics.create_pen(200, 200, 200))
graphics.text("Hello", 410, 220)
graphics.text("Hello", 410, 240, scale=4.0)

# Red, Green and Blue gradients

for x in range(WIDTH):
g = int(x / float(WIDTH) * 255)
for y in range(20):
graphics.set_pen(graphics.create_pen(g, 0, 0))
graphics.pixel(x, 320 + y)
graphics.set_pen(graphics.create_pen(0, g, 0))
graphics.pixel(x, 350 + y)
graphics.set_pen(graphics.create_pen(0, 0, g))
graphics.pixel(x, 380 + y)

graphics.update()
Loading

0 comments on commit faf4efa

Please sign in to comment.