|
| 1 | +Console |
| 2 | +======= |
| 3 | + |
| 4 | +.. autoclass:: ev3dev2.console.Console |
| 5 | + :members: |
| 6 | + |
| 7 | +Examples: |
| 8 | + |
| 9 | +.. code-block:: py |
| 10 | +
|
| 11 | + #!/usr/bin/env micropython |
| 12 | + from ev3dev2.console import Console |
| 13 | +
|
| 14 | + # create a Console instance, which uses the default font |
| 15 | + console = Console() |
| 16 | +
|
| 17 | + # reset the console to clear it, home the cursor at 1,1, and then turn off the cursor |
| 18 | + console.reset_console() |
| 19 | +
|
| 20 | + # display 'Hello World!' at row 5, column 1 in inverse, but reset the EV3 LCD console first |
| 21 | + console.text_at('Hello World!', column=1, row=5, reset_console=True, inverse=True) |
| 22 | +
|
| 23 | +.. code-block:: py |
| 24 | +
|
| 25 | + #!/usr/bin/env micropython |
| 26 | + from time import sleep |
| 27 | + from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3 |
| 28 | + from ev3dev2.console import Console |
| 29 | + from ev3dev2.sensor.lego import GyroSensor, ColorSensor |
| 30 | +
|
| 31 | + console = Console() |
| 32 | + gyro = GyroSensor(INPUT_1) |
| 33 | + gyro.mode = GyroSensor.MODE_GYRO_ANG |
| 34 | + color_sensor_left = ColorSensor(INPUT_2) |
| 35 | + color_sensor_right = ColorSensor(INPUT_3) |
| 36 | +
|
| 37 | + # show the gyro angle and reflected light intensity for both of our color sensors |
| 38 | + while True: |
| 39 | + angle = gyro.angle |
| 40 | + left = color_sensor_left.reflected_light_intensity |
| 41 | + right = color_sensor_right.reflected_light_intensity |
| 42 | +
|
| 43 | + # show angle; in inverse color when pointing at 0 |
| 44 | + console.text_at("G: %03d" % (angle), column=5, row=1, reset_console=True, inverse=(angle == 0)) |
| 45 | +
|
| 46 | + # show light intensity values; in inverse when 'dark' |
| 47 | + console.text_at("L: %02d" % (left), column=0, row=3, reset_console=False, inverse=(left < 10)) |
| 48 | + console.text_at("R: %02d" % (right), column=10, row=3, reset_console=False, inverse=(right < 10)) |
| 49 | +
|
| 50 | + sleep(0.5) |
| 51 | +
|
| 52 | +Console fonts |
| 53 | +------------- |
| 54 | + |
| 55 | +The :py:class:`ev3dev2.console.Console` class displays text on the LCD console |
| 56 | +using ANSI codes in various system console fonts. The system console fonts are |
| 57 | +located in `/usr/share/consolefonts`. |
| 58 | + |
| 59 | +Font filenames consist of the codeset, font face and font size. The codeset |
| 60 | +specifies the characters supported. The font face determines the look of the |
| 61 | +font. Each font face is available in multiple sizes. |
| 62 | + |
| 63 | +For Codeset information, see |
| 64 | +`<https://www.systutorials.com/docs/linux/man/5-console-setup/#lbAP>`. |
| 65 | + |
| 66 | +Note: `Terminus` fonts are "thinner"; `TerminusBold` and `VGA` offer more |
| 67 | +contrast on the LCD console and are thus more readable; the `TomThumb` font is |
| 68 | +too small to read! |
| 69 | + |
| 70 | +Depending on the font used, the EV3 LCD console will support various maximum |
| 71 | +rows and columns, as follows for the `Lat15` fonts. See |
| 72 | +`utils/console_fonts.py` to discover fonts and their resulting rows/columns. |
| 73 | +These fonts are listed in larger-to-smaller size order: |
| 74 | + |
| 75 | ++----------+------------+--------------------------------+ |
| 76 | +| LCD Rows | LCD Columns| Font | |
| 77 | ++==========+============+================================+ |
| 78 | +| 4 | 11 | Lat15-Terminus32x16.psf.gz | |
| 79 | ++----------+------------+--------------------------------+ |
| 80 | +| 4 | 11 | Lat15-TerminusBold32x16.psf.gz | |
| 81 | ++----------+------------+--------------------------------+ |
| 82 | +| 4 | 11 | Lat15-VGA28x16.psf.gz | |
| 83 | ++----------+------------+--------------------------------+ |
| 84 | +| 4 | 11 | Lat15-VGA32x16.psf.gz | |
| 85 | ++----------+------------+--------------------------------+ |
| 86 | +| 4 | 12 | Lat15-Terminus28x14.psf.gz | |
| 87 | ++----------+------------+--------------------------------+ |
| 88 | +| 4 | 12 | Lat15-TerminusBold28x14.psf.gz | |
| 89 | ++----------+------------+--------------------------------+ |
| 90 | +| 5 | 14 | Lat15-Terminus24x12.psf.gz | |
| 91 | ++----------+------------+--------------------------------+ |
| 92 | +| 5 | 14 | Lat15-TerminusBold24x12.psf.gz | |
| 93 | ++----------+------------+--------------------------------+ |
| 94 | +| 5 | 16 | Lat15-Terminus22x11.psf.gz | |
| 95 | ++----------+------------+--------------------------------+ |
| 96 | +| 5 | 16 | Lat15-TerminusBold22x11.psf.gz | |
| 97 | ++----------+------------+--------------------------------+ |
| 98 | +| 6 | 17 | Lat15-Terminus20x10.psf.gz | |
| 99 | ++----------+------------+--------------------------------+ |
| 100 | +| 6 | 17 | Lat15-TerminusBold20x10.psf.gz | |
| 101 | ++----------+------------+--------------------------------+ |
| 102 | +| 7 | 22 | Lat15-Fixed18.psf.gz | |
| 103 | ++----------+------------+--------------------------------+ |
| 104 | +| 8 | 22 | Lat15-Fixed15.psf.gz | |
| 105 | ++----------+------------+--------------------------------+ |
| 106 | +| 8 | 22 | Lat15-Fixed16.psf.gz | |
| 107 | ++----------+------------+--------------------------------+ |
| 108 | +| 8 | 22 | Lat15-Terminus16.psf.gz | |
| 109 | ++----------+------------+--------------------------------+ |
| 110 | +| 8 | 22 | Lat15-TerminusBold16.psf.gz | |
| 111 | ++----------+------------+--------------------------------+ |
| 112 | +| 8 | 22 | Lat15-TerminusBoldVGA16.psf.gz | |
| 113 | ++----------+------------+--------------------------------+ |
| 114 | +| 8 | 22 | Lat15-VGA16.psf.gz | |
| 115 | ++----------+------------+--------------------------------+ |
| 116 | +| 9 | 22 | Lat15-Fixed13.psf.gz | |
| 117 | ++----------+------------+--------------------------------+ |
| 118 | +| 9 | 22 | Lat15-Fixed14.psf.gz | |
| 119 | ++----------+------------+--------------------------------+ |
| 120 | +| 9 | 22 | Lat15-Terminus14.psf.gz | |
| 121 | ++----------+------------+--------------------------------+ |
| 122 | +| 9 | 22 | Lat15-TerminusBold14.psf.gz | |
| 123 | ++----------+------------+--------------------------------+ |
| 124 | +| 9 | 22 | Lat15-TerminusBoldVGA14.psf.gz | |
| 125 | ++----------+------------+--------------------------------+ |
| 126 | +| 9 | 22 | Lat15-VGA14.psf.gz | |
| 127 | ++----------+------------+--------------------------------+ |
| 128 | +| 10 | 29 | Lat15-Terminus12x6.psf.gz | |
| 129 | ++----------+------------+--------------------------------+ |
| 130 | +| 16 | 22 | Lat15-VGA8.psf.gz | |
| 131 | ++----------+------------+--------------------------------+ |
| 132 | +| 21 | 44 | Lat15-TomThumb4x6.psf.gz | |
| 133 | ++----------+------------+--------------------------------+ |
| 134 | + |
| 135 | +Example: |
| 136 | + |
| 137 | +.. code-block:: py |
| 138 | +
|
| 139 | + #!/usr/bin/env micropython |
| 140 | + from ev3dev2.console import Console |
| 141 | +
|
| 142 | + # create a Console instance, which uses the default font |
| 143 | + console = Console() |
| 144 | +
|
| 145 | + # change the console font and reset the console to clear it and turn off the cursor |
| 146 | + console.set_font('Lat15-TerminusBold16.psf.gz', True) |
| 147 | +
|
| 148 | + # display 'Hello World!' at column 1, row 5 |
| 149 | + console.text_at('Hello World!', column=1, row=5) |
0 commit comments