File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ import { fontA00 } from './lcd1602-font-a00';
3
3
4
4
export type ICursorType = 'off' | 'blink' | 'underline' ;
5
5
6
+ const ROWS = 2 ;
7
+ const COLS = 16 ;
8
+
6
9
const charXSpacing = 3.55 ;
7
10
const charYSpacing = 5.95 ;
8
11
@@ -50,8 +53,8 @@ export class LCD1602Element extends LitElement {
50
53
const ySpacing = 0.7 ;
51
54
const result = [ ] ;
52
55
for ( let i = 0 ; i < characters . length ; i ++ ) {
53
- const charX = ( i % 16 ) * charXSpacing ;
54
- const charY = Math . floor ( i / 16 ) * charYSpacing ;
56
+ const charX = ( i % COLS ) * charXSpacing ;
57
+ const charY = Math . floor ( i / COLS ) * charYSpacing ;
55
58
56
59
for ( let py = 0 ; py < 8 ; py ++ ) {
57
60
const row = this . font [ characters [ i ] * 8 + py ] ;
@@ -70,6 +73,10 @@ export class LCD1602Element extends LitElement {
70
73
renderCursor ( ) {
71
74
const xOffset = 12.45 + this . cursorX * charXSpacing ;
72
75
const yOffset = 12.55 + this . cursorY * charYSpacing ;
76
+ if ( this . cursorX < 0 || this . cursorX >= COLS || this . cursorY < 0 || this . cursorY >= ROWS ) {
77
+ return null ;
78
+ }
79
+
73
80
switch ( this . cursor ) {
74
81
case 'blink' :
75
82
return svg `
You can’t perform that action at this time.
0 commit comments