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';
33
44export type ICursorType = 'off' | 'blink' | 'underline' ;
55
6+ const ROWS = 2 ;
7+ const COLS = 16 ;
8+
69const charXSpacing = 3.55 ;
710const charYSpacing = 5.95 ;
811
@@ -50,8 +53,8 @@ export class LCD1602Element extends LitElement {
5053 const ySpacing = 0.7 ;
5154 const result = [ ] ;
5255 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 ;
5558
5659 for ( let py = 0 ; py < 8 ; py ++ ) {
5760 const row = this . font [ characters [ i ] * 8 + py ] ;
@@ -70,6 +73,10 @@ export class LCD1602Element extends LitElement {
7073 renderCursor ( ) {
7174 const xOffset = 12.45 + this . cursorX * charXSpacing ;
7275 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+
7380 switch ( this . cursor ) {
7481 case 'blink' :
7582 return svg `
You can’t perform that action at this time.
0 commit comments