Skip to content

Commit 14994a3

Browse files
aykevldeadprogram
authored andcommitted
epd2in13: unify rotation configuration with other displays
This commit updates rotation behavior to match other displays. For more information, see: #550 This changes the signature of `SetRotation` but I don't think any existing code will be affected by this change.
1 parent 47dfeb9 commit 14994a3

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

waveshare-epd/epd2in13/epd2in13.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
type Config struct {
1616
Width int16 // Width is the display resolution
1717
Height int16
18-
LogicalWidth int16 // LogicalWidth must be a multiple of 8 and same size or bigger than Width
19-
Rotation Rotation // Rotation is clock-wise
18+
LogicalWidth int16 // LogicalWidth must be a multiple of 8 and same size or bigger than Width
19+
Rotation drivers.Rotation
2020
}
2121

2222
type Device struct {
@@ -30,10 +30,11 @@ type Device struct {
3030
height int16
3131
buffer []uint8
3232
bufferLength uint32
33-
rotation Rotation
33+
rotation drivers.Rotation
3434
}
3535

36-
type Rotation uint8
36+
// Deprecated: use drivers.Rotation instead.
37+
type Rotation = drivers.Rotation
3738

3839
// Look up table for full updates
3940
var lutFullUpdate = [30]uint8{
@@ -209,13 +210,13 @@ func (d *Device) DisplayRect(x int16, y int16, width int16, height int16) error
209210
if x < 0 || y < 0 || x >= d.logicalWidth || y >= d.height || width < 0 || height < 0 {
210211
return errors.New("wrong rectangle")
211212
}
212-
if d.rotation == ROTATION_90 {
213+
if d.rotation == drivers.Rotation90 {
213214
width, height = height, width
214215
x -= width
215-
} else if d.rotation == ROTATION_180 {
216+
} else if d.rotation == drivers.Rotation180 {
216217
x -= width - 1
217218
y -= height - 1
218-
} else if d.rotation == ROTATION_270 {
219+
} else if d.rotation == drivers.Rotation270 {
219220
width, height = height, width
220221
y -= height
221222
}
@@ -301,27 +302,33 @@ func (d *Device) ClearBuffer() {
301302

302303
// Size returns the current size of the display.
303304
func (d *Device) Size() (w, h int16) {
304-
if d.rotation == ROTATION_90 || d.rotation == ROTATION_270 {
305+
if d.rotation == drivers.Rotation90 || d.rotation == drivers.Rotation270 {
305306
return d.height, d.logicalWidth
306307
}
307308
return d.logicalWidth, d.height
308309
}
309310

310-
// SetRotation changes the rotation (clock-wise) of the device
311-
func (d *Device) SetRotation(rotation Rotation) {
311+
// Rotation returns the current rotation of the device.
312+
func (d *Device) Rotation() drivers.Rotation {
313+
return d.rotation
314+
}
315+
316+
// SetRotation changes the rotation of the device.
317+
func (d *Device) SetRotation(rotation drivers.Rotation) error {
312318
d.rotation = rotation
319+
return nil
313320
}
314321

315322
// xy chages the coordinates according to the rotation
316323
func (d *Device) xy(x, y int16) (int16, int16) {
317324
switch d.rotation {
318-
case NO_ROTATION:
325+
case drivers.Rotation0:
319326
return x, y
320-
case ROTATION_90:
327+
case drivers.Rotation90:
321328
return d.width - y - 1, x
322-
case ROTATION_180:
329+
case drivers.Rotation180:
323330
return d.width - x - 1, d.height - y - 1
324-
case ROTATION_270:
331+
case drivers.Rotation270:
325332
return y, d.height - x - 1
326333
}
327334
return x, y

waveshare-epd/epd2in13/registers.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package epd2in13
22

3+
import "tinygo.org/x/drivers"
4+
35
// Registers
46
const (
57
DRIVER_OUTPUT_CONTROL = 0x01
@@ -24,8 +26,8 @@ const (
2426
SET_RAM_Y_ADDRESS_COUNTER = 0x4F
2527
TERMINATE_FRAME_READ_WRITE = 0xFF
2628

27-
NO_ROTATION Rotation = 0
28-
ROTATION_90 Rotation = 1 // 90 degrees clock-wise rotation
29-
ROTATION_180 Rotation = 2
30-
ROTATION_270 Rotation = 3
29+
NO_ROTATION = drivers.Rotation0
30+
ROTATION_90 = drivers.Rotation90 // 90 degrees clock-wise rotation
31+
ROTATION_180 = drivers.Rotation180
32+
ROTATION_270 = drivers.Rotation270
3133
)

0 commit comments

Comments
 (0)