@@ -247,7 +247,7 @@ def clearScreen(self):
247
247
:rtype: bool
248
248
249
249
"""
250
- return self ._i2c . writeByte ( self . address , SETTING_COMMAND , CLEAR_COMMAND )
250
+ return self .command ( CLEAR_COMMAND )
251
251
252
252
# ----------------------------------
253
253
# setCursor()
@@ -354,3 +354,103 @@ def setBacklight(self, r, g, b):
354
354
# send the complete bytes (address, settings command , contrast command, contrast value)
355
355
return self ._i2c .writeBlock (self .address , SETTING_COMMAND , block )
356
356
357
+ # ----------------------------------
358
+ # specialCommand()
359
+ #
360
+ # Send one (or multiples of) special command to the display.
361
+ # Used by other functions.
362
+ def specialCommand (self , command , count = 1 ):
363
+ """
364
+ Send one (or multiple) special commands to the display.
365
+ Used by other functions.
366
+
367
+ :param command: Command to send (a single byte)
368
+ :param count: Number of times to send the command (if ommited, then default is once)
369
+
370
+ :return: Returns true if the I2C write was successful, otherwise False.
371
+ :rtype: bool
372
+
373
+ """
374
+ for i in range (0 , count ):
375
+ # send the complete bytes (special command + command)
376
+ return self ._i2c .writeByte (self .address , SPECIAL_COMMAND , command )
377
+
378
+ # ----------------------------------
379
+ # command()
380
+ #
381
+ # Send one setting command to the display.
382
+ # Used by other functions.
383
+ def command (self , command ):
384
+ """
385
+ Send one setting command to the display.
386
+ Used by other functions.
387
+
388
+ :param command: Command to send (a single byte)
389
+
390
+ :return: Returns true if the I2C write was successful, otherwise False.
391
+ :rtype: bool
392
+
393
+ """
394
+ return self ._i2c .writeByte (self .address , SETTING_COMMAND , command )
395
+
396
+ # ----------------------------------
397
+ # moveCursorLeft()
398
+ #
399
+ # Move the cursor one or more characters to the left.
400
+ def moveCursorLeft (self , count = 1 ):
401
+ """
402
+ Move the cursor one or more characters to the left.
403
+
404
+ :param count: Number of character spaces you'd like to move
405
+
406
+ :return: Returns true if the I2C write was successful, otherwise False.
407
+ :rtype: bool
408
+
409
+ """
410
+ return self .specialCommand (LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVELEFT , count )
411
+
412
+ # ----------------------------------
413
+ # moveCursorRight()
414
+ #
415
+ # Move the cursor one or more characters to the right.
416
+ def moveCursorRight (self , count = 1 ):
417
+ """
418
+ Move the cursor one or more characters to the right.
419
+
420
+ :param count: Number of character spaces you'd like to move
421
+
422
+ :return: Returns true if the I2C write was successful, otherwise False.
423
+ :rtype: bool
424
+
425
+ """
426
+ return self .specialCommand (LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVERIGHT , count )
427
+
428
+ # ----------------------------------
429
+ # cursor()
430
+ #
431
+ # Turn the underline cursor on.
432
+ def cursor (self ):
433
+ """
434
+ Turn the underline cursor on.
435
+
436
+ :return: Returns true if the I2C write was successful, otherwise False.
437
+ :rtype: bool
438
+
439
+ """
440
+ self ._displayControl |= LCD_CURSORON
441
+ return self .specialCommand (LCD_DISPLAYCONTROL | self ._displayControl )
442
+
443
+ # ----------------------------------
444
+ # noCursor()
445
+ #
446
+ # Turn the underline cursor off.
447
+ def noCursor (self ):
448
+ """
449
+ Turn the underline cursor off.
450
+
451
+ :return: Returns true if the I2C write was successful, otherwise False.
452
+ :rtype: bool
453
+
454
+ """
455
+ self ._displayControl &= ~ LCD_CURSORON
456
+ return self .specialCommand (LCD_DISPLAYCONTROL | self ._displayControl )
0 commit comments