Skip to content

Commit eb209ba

Browse files
committed
Using new optimized driver
with drawFastXLine functions and Dial now uses fillCircle with drawFastHLine
1 parent e8ae764 commit eb209ba

5 files changed

Lines changed: 78 additions & 68 deletions

File tree

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
},
7979
"windows": {
8080
"command": "loadp2.exe",
81-
"args": ["-b230400", "${config:topLevel}.binary", "-t", "-pCOM3"]
81+
"args": ["-b230400", "${config:topLevel}.binary", "-t", "-pCOM9"]
8282
},
8383
"linux": {
8484
"command": "/opt/flexprop/bin/loadp2",

Dial.spin2

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ CON
1414
VAR
1515
'Attributes
1616
long id 'Unique ID - (window index << 4)|(button index)
17-
long bg_color 'background color
18-
long fg_color 'foreground color
19-
long ol_color 'outline = border
17+
word bg_color 'background color
18+
word fg_color 'foreground color
19+
word ol_color 'outline = border
2020
word xtop 'Top Left X (Pixel)
2121
word ytop 'Top Left Y (Pixel)
2222
word xbot 'Bottom Right X (Pixel)
@@ -82,8 +82,8 @@ PUB draw()| b, c, d, ticks , i
8282
''This method draws the graphical representation of this widget type
8383
if enabled
8484
'FILL
85-
graphics.fill_rectangle(xtop+border_width,ytop+border_width,xbot-border_width,ybot-border_width,bg_color)
86-
'graphics.fill_circle(xc,yc,radius,bg_color)
85+
'graphics.fill_rectangle(xtop+border_width,ytop+border_width,xbot-border_width,ybot-border_width,bg_color)
86+
graphics.fill_circle(xc,yc,radius,bg_color)
8787

8888
'BORDER
8989
repeat b from 0 to border_width-1
@@ -228,6 +228,7 @@ PUB configure(i, x, y, r, bg, fg, ol)
228228
range_limit := RANGE_ANGLE - 90 'phasing 90 degrees left so 0 is at the top center
229229

230230
configured := true
231+
enabled := true
231232
last_time := getms()
232233

233234
PUB is_configured():conf

GUI.spin2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CON
3131
'Drawing Methods Constants (for mapping driver methods to graphics methods)
3232
#0, CLEAR_SCREEN, SET_FOREGROUND_COLOR, SET_BACKGROUND_COLOR, SET_WINDOW, FILL_WINDOW, SET_COL_ROW
3333
#6, DRAW_CHAR, DRAW_STRING, DRAW_ICON, DRAW_PIXEL, DRAW_LINE
34-
#11, DRAW_CIRCLE, DRAW_RECTANGLE, FILL_RECTANGLE, SELECT_FONT_SIZE, FILL_CIRCLE, MAX_METHODS
34+
#11, DRAW_CIRCLE, DRAW_RECTANGLE, FILL_RECTANGLE, SELECT_FONT_SIZE, FILL_CIRCLE, DRAW_FAST_HLINE, DRAW_FAST_VLINE, MAX_METHODS
3535

3636
MAX_WIDGETS = 10
3737

@@ -110,6 +110,8 @@ PUB init(bg, fg, ol, o, cal) | i
110110
graphics.set_pointer(FILL_RECTANGLE, @display.fillRectangle)
111111
graphics.set_pointer(SELECT_FONT_SIZE, @display.SelectFontSize)
112112
graphics.set_pointer(FILL_CIRCLE, @display.fillCircle)
113+
graphics.set_pointer(DRAW_FAST_HLINE, @display.drawFastHLine)
114+
graphics.set_pointer(DRAW_FAST_VLINE, @display.drawFastVLine)
113115

114116
'set all areas colors to match canvas
115117
repeat i from 0 to 8

LCD_Graphics_Driver.spin2

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ PUB drawChar(char) | xs, ys
410410

411411
PUB drawStr(str)
412412
repeat while byte[str] <> 0
413-
DrawChar(byte[str++])
413+
drawChar(byte[str++])
414414

415415
PUB drawString(col,row,str)
416416
' Draw a 0 terminated string at col,row
@@ -432,18 +432,38 @@ PUB drawPixel(x, y, rgb) | i
432432
setWindow(x, y, x, y) ' 1 pixel
433433
fillWindow(rgb)
434434

435+
PUB drawFastHLine(x,y,l,rgb)
436+
setWindow(x,y,x+l,y)
437+
fillWindow(rgb)
438+
439+
PUB drawFastVLine(x,y,l,rgb)
440+
setWindow(x,y,x,y+l)
441+
fillWindow(rgb)
442+
435443
PUB drawLine(xs, ys, xe, ye, rgb) | i, x, y, dx, dy
436444
' Draw Line - start co-ords, end co-ords, color
437445
dx:= xe - xs
438446
dy:= ye - ys
439-
if ABS(dx) > ABS(dy) 'plot incrementing x axis
440-
repeat i from 0 to dx
441-
y := (dy*i + dx/2)/dx
442-
drawPixel(xs+i, ys+y, rgb)
443-
else 'plot incrementing y axis
444-
repeat i from 0 to dy
445-
x := (dx*i + dy/2)/dy
446-
drawPixel(xs+x, ys+i, rgb)
447+
448+
if dx == 0
449+
if ys < ye
450+
drawFastVLine(xs,ys,dy,rgb)
451+
else
452+
drawFastVLine(xs,ye,ABS(dy),rgb)
453+
elseif dy == 0
454+
if xs < xe
455+
drawFastHLine(xs,ys,dx,rgb)
456+
else
457+
drawFastHLine(xe,ys,ABS(dx),rgb)
458+
else
459+
if ABS(dx) > ABS(dy) 'plot incrementing x axis
460+
repeat i from 0 to dx
461+
y := (dy*i + dx/2)/dx
462+
drawPixel(xs+i, ys+y, rgb)
463+
else 'plot incrementing y axis
464+
repeat i from 0 to dy
465+
x := (dx*i + dy/2)/dy
466+
drawPixel(xs+x, ys+i, rgb)
447467

448468
PUB drawCircle(xc, yc, r, rgb) | x, y
449469
' Draw Circle d^2 = x^2 + y^2; y = SQRT(d^2 - x^2) (Pythagoras theorum)
@@ -462,38 +482,17 @@ PUB drawCircle(xc, yc, r, rgb) | x, y
462482
drawPixel(xc+y, yc-x, rgb)
463483
drawPixel(xc-y, yc-x, rgb)
464484

465-
{
466-
PUB fillCircle(xc, yc, r, rgb)|x,y,xr,yr,d,a
467-
' Draws a filled circle using ROTXY
468-
d := $80000000 / 180 'degrees unit in 32 bits
469-
x := 0
470-
y := r
471-
a := 0
472-
473-
repeat a from 0 to 45 step 2
474-
xr,yr := ROTXY(x,y,a*d)
475-
476-
'Window requires start column < end column and start row < end row
477-
setWindow(xc-yr,yc-xr,xc+yr,yc+xr)
478-
fillWindow(rgb)
479-
480-
'Window requires start column < end column and start row < end row
481-
setWindow(xc-xr,yc-yr,xc+xr,yc+yr)
482-
fillWindow(rgb)
483-
}
484-
485485
PUB fillCircle(xc, yc, r, rgb)|x,y,xr,yr,d
486-
'Faster than above approach
487486
'The most efficient algorithm for creating a filled circle is
488487
'the Midpoint Circle Algorithm, also known as Bresenham's Circle Algorithm.
489488
x := 0
490489
y := r
491490
d := 1 - r
492491
repeat while x <= y
493-
drawLine(xc-x, yc+y, xc+x, yc+y, rgb) 'last
494-
drawLine(xc-x, yc-y, xc+x, yc-y, rgb) 'top
495-
drawLine(xc-y, yc+x, xc+y, yc+x, rgb) 'third
496-
drawLine(xc-y, yc-x, xc+y, yc-x, rgb) 'second
492+
drawFastHLine(xc-x, yc+y, 2*x, rgb) 'last
493+
drawFastHLine(xc-x, yc-y, 2*x, rgb) 'top
494+
drawFastHLine(xc-y, yc+x, 2*y, rgb) 'third
495+
drawFastHLine(xc-y, yc-x, 2*y, rgb) 'second
497496

498497
x++
499498
if d < 0
@@ -583,8 +582,8 @@ PUB buttonIsHit (x, y): n
583582
PUB waitForButton (): n
584583
' wait uintil a button is hit and returns its number
585584
repeat
586-
wait_for_touch ()
587-
wait_for_untouch ()
585+
Wait_for_touch ()
586+
Wait_for_untouch ()
588587
n:= buttonIsHit (Get_TS_XY ())
589588
until n > 0
590589

@@ -598,23 +597,23 @@ PUB calibrateTouch() | xstr, ystr, tx,ty,tx_topx,ty_topy,tx_botx,ty_boty,spotx,s
598597

599598
clearScreen()
600599
clearButtons()
601-
drawstring(xstr, ystr, string("CALIBRATE TOP LEFT"))
602-
SetColRow(cal_topx, cal_topy)
603-
DrawChar("x") ' draw top left calibration X
600+
drawString(xstr, ystr, string("CALIBRATE TOP LEFT"))
601+
setColRow(cal_topx, cal_topy)
602+
drawChar("x") ' draw top left calibration X
604603
int := 1
605604

606605
Wait_for_touch() ' wait for touch
607606
tx_topx,ty_topy:= Get_TS_XY_raw() ' calibration point top left
608607

609608
' term.fstr3(string("X %d Y %d int %d %s\r\n"),tx_topx,ty_topy,int)
610-
clearscreen()
611-
drawstring(xstr, ystr, string("CALIBRATE BOTTOM RIGHT"))
612-
SetColRow(cal_botx, cal_boty)
609+
clearScreen()
610+
drawString(xstr, ystr, string("CALIBRATE BOTTOM RIGHT"))
611+
setColRow(cal_botx, cal_boty)
613612

614-
DrawChar("x") ' draw bottom right calibration X
613+
drawChar("x") ' draw bottom right calibration X
615614

616-
wait_for_untouch() ' wait until not touched
617-
wait_for_touch() ' wait until touched
615+
Wait_for_untouch() ' wait until not touched
616+
Wait_for_touch() ' wait until touched
618617

619618
tx_botx,ty_boty:= Get_TS_XY_raw() ' calibration point bottom right
620619
' term.fstr3(string("X %d Y %d int %d %s\r\n"),tx_botx,ty_boty,spotx)
@@ -628,9 +627,9 @@ PUB calibrateTouch() | xstr, ystr, tx,ty,tx_topx,ty_topy,tx_botx,ty_boty,spotx,s
628627

629628
calibrated:= true
630629

631-
clearscreen()
632-
wait_for_untouch()
633-
drawstring(xstr, ystr, string("TOUCH DISPLAY TO MAKE X"))
630+
clearScreen()
631+
Wait_for_untouch()
632+
drawString(xstr, ystr, string("TOUCH DISPLAY TO MAKE X"))
634633
spotx:= cal_botx-(cal_edge/2)
635634
spoty:= cal_edge/2
636635
setWindow(spotx, spoty, spotx+cal_edge, spoty+cal_edge)
@@ -639,22 +638,22 @@ PUB calibrateTouch() | xstr, ystr, tx,ty,tx_topx,ty_topy,tx_botx,ty_boty,spotx,s
639638

640639
setBGcolor(white)
641640
setFGcolor(black)
642-
drawstring(spotx, cal_edge, string("DONE"))
641+
drawString(spotx, cal_edge, string("DONE"))
643642
setFGcolor(green)
644643
setBGcolor(black)
645644

646645
repeat
647-
wait_for_untouch() ' wait until not touched
648-
wait_for_touch() ' wait until touched
646+
Wait_for_untouch() ' wait until not touched
647+
Wait_for_touch() ' wait until touched
649648

650649
spotx,spoty:= Get_TS_XY()
651650

652651
if buttonIsHit (spotx, spoty)
653652
quit ' cal_done
654-
SetColRow(spotx,spoty)
655-
DrawChar("x")
653+
setColRow(spotx,spoty)
654+
drawChar("x")
656655
clearButtons()
657-
clearscreen()
656+
clearScreen()
658657

659658
' term.fstr3(string("X %d Y %d int %d %s\r\n"),spotx,spoty,spotx)
660659
'----------------------------------------------------------
@@ -724,7 +723,7 @@ CON
724723
PUB detects_valid_touch(): valid_touch_detected | pos_x, pos_y
725724
valid_touch_detected := false
726725
if Touched() AND (getms()-last_time >= DEBOUNCE_TIMER)
727-
pos_x, pos_y := GET_TS_XY()
726+
pos_x, pos_y := Get_TS_XY()
728727
if (pos_x > 0 AND pos_x <= cal_offx) AND (pos_y > 0 AND pos_y <= cal_offy)
729728
valid_touch_detected := true
730729
last_x := pos_x
@@ -804,7 +803,7 @@ entry ' PTRA contains the poin
804803
fltl PIN_SDA '|
805804
drvh PIN_CLK '|
806805
drvh PIN_LED '/
807-
wrpin modeLClk,PIN_CLK ' smart pin transition mode
806+
wrpin modeLCLK,PIN_CLK ' smart pin transition mode
808807
wrpin modeLTXD,PIN_SDA ' smart pin synchronous serial transmit
809808
wxpin divCLK,PIN_CLK ' clock transition every 50ns
810809
wypin #2,PIN_CLK ' dummy pulse to force IN=1 (ready flag)
@@ -1100,7 +1099,7 @@ selectLCD
11001099
if_nz jmp #.waitRdy ' wait until last CLK sequence finished
11011100
fltl PIN_SDA
11021101
drvc PIN_DC ' cmd=0 / data=1
1103-
wrpin modeLClk,PIN_CLK ' smart pin transition mode
1102+
wrpin modeLCLK,PIN_CLK ' smart pin transition mode
11041103
wrpin modeLTXD,PIN_SDA ' smart pin synchronous serial transmit
11051104
wxpin divCLK,PIN_CLK ' clock transition every 50ns
11061105
_ret_ drvl PIN_CE ' CS=0
@@ -1136,14 +1135,14 @@ write16data shl data, #16 ' prep word to write (ms
11361135
''+-----------------------------------------------------+
11371136
pollTouchXY
11381137
mov data,#$91
1139-
call #get_ts_adc
1138+
call #Get_ts_adc
11401139
mov data,#$91
1141-
call #get_ts_adc
1140+
call #Get_ts_adc
11421141
mov ts_xy,data
11431142
mov data,#$D1
1144-
call #get_ts_adc
1143+
call #Get_ts_adc
11451144
mov data,#$D0
1146-
call #get_ts_adc
1145+
call #Get_ts_adc
11471146
shl data,#16
11481147
or ts_xy,data
11491148
wrlong ts_xy,ptra[6]

graphics.spin2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ _draw_rectangle long 0
3939
_fill_rectangle long 0
4040
_select_font_size long 0
4141
_fill_circle long 0
42+
_draw_fast_hline long 0
43+
_draw_fast_vline long 0
4244

4345

4446
PUB set_pointer(index, ptr)|addr
@@ -97,3 +99,9 @@ PUB select_font_size(s)
9799

98100
PUB fill_circle(xc,yc,r,rgb)
99101
_fill_circle(xc,yc,r,rgb)
102+
103+
PUB draw_fast_hline(x,y,l,rgb)
104+
_draw_fast_hline(x,y,l,rgb)
105+
106+
PUB draw_fast_vline(x,y,l,rgb)
107+
_draw_fast_vline(x,y,l,rgb)

0 commit comments

Comments
 (0)