diff --git a/demo_fonts_rotated.py b/demo_fonts_rotated.py new file mode 100644 index 0000000..0c38faf --- /dev/null +++ b/demo_fonts_rotated.py @@ -0,0 +1,192 @@ +"""ILI9341 demo (fonts rotated).""" +from time import sleep +from ili9341 import Display, color565 +from machine import Pin, SPI +from xglcd_font import XglcdFont + + +def test(): + """Test code.""" + # Baud rate of 40000000 seems about the max + spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13)) + display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17)) + + print('Loading fonts...') + print('Loading arcadepix') + arcadepix = XglcdFont('fonts/ArcadePix9x11.c', 9, 11) + print('loading espressodolce') + espressodolce = XglcdFont('fonts/EspressoDolce18x24.c', 18, 24) + print('Loading neato') + neato = XglcdFont('fonts/Neato5x7.c', 5, 7, letter_count=223) + print('Loading robotron') + robotron = XglcdFont('fonts/Robotron13x21.c', 13, 21) + print('Loading unispace') + unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24) + + # ArcadePix + font_height = arcadepix.height + display.draw_text(0, 0, + 'Portrait', arcadepix, + color565(255, 255, 0), + landscape=False, rotate_180=False) + text_width = arcadepix.measure_text('Landscape') + display.draw_text(0, display.height - 1, + 'Landscape', arcadepix, + color565(255, 0, 0), + landscape=True, rotate_180=False) + text_width = arcadepix.measure_text('Portrait, Rotate 180') + display.draw_text(display.width - text_width - 1, + display.height - font_height, + 'Portrait, Rotate 180', arcadepix, + color565(255, 0, 255), + landscape=False, rotate_180=True) + text_width = arcadepix.measure_text('Landscape, Rotate 180') + display.draw_text(display.width - font_height - 1 , text_width, + 'Landscape, Rotate 180', arcadepix, + color565(0, 0, 255), + landscape=True, rotate_180=True) + sleep(5) + + # Espresso Dolce + display.clear() + font_height = espressodolce.height + display.draw_text(0, 0, + 'PORTRAIT', espressodolce, + color565(255, 255, 0), + landscape=False, rotate_180=False) + text_width = espressodolce.measure_text('LANDSCAPE') + display.draw_text(0, display.height - 1, + 'LANDSCAPE', espressodolce, + color565(255, 0, 0), + landscape=True, rotate_180=False) + text_width = espressodolce.measure_text('PORTRAIT,') + display.draw_text(display.width - text_width - 1, + display.height - font_height, + 'PORTRAIT,', espressodolce, + color565(255, 0, 255), + landscape=False, rotate_180=True) + text_width = espressodolce.measure_text('ROTATE 180') + display.draw_text(display.width - text_width - 1, + display.height - font_height * 2, + 'ROTATE 180', espressodolce, + color565(255, 0, 255), + landscape=False, rotate_180=True) + text_width = espressodolce.measure_text('LANDSCAPE,') + display.draw_text(display.width - font_height - 1 , text_width, + 'LANDSCAPE,', espressodolce, + color565(0, 0, 255), + landscape=True, rotate_180=True) + text_width = espressodolce.measure_text('ROTATE 180') + display.draw_text(display.width - font_height * 2 - 1 , text_width, + 'ROTATE 180', espressodolce, + color565(0, 0, 255), + landscape=True, rotate_180=True) + sleep(5) + + # Neato + display.clear() + font_height = neato.height + display.draw_text(0, 0, + 'Portrait', neato, + color565(255, 255, 0), + landscape=False, rotate_180=False) + text_width = neato.measure_text('Landscape') + display.draw_text(0, display.height - 1, + 'Landscape', neato, + color565(255, 0, 0), + landscape=True, rotate_180=False) + text_width = neato.measure_text('Portrait, Rotate 180') + display.draw_text(display.width - text_width - 1, + display.height - font_height, + 'Portrait, Rotate 180', neato, + color565(255, 0, 255), + landscape=False, rotate_180=True) + text_width = neato.measure_text('Landscape, Rotate 180') + display.draw_text(display.width - font_height - 1 , text_width, + 'Landscape, Rotate 180', neato, + color565(0, 0, 255), + landscape=True, rotate_180=True) + sleep(5) + + # Robotron + display.clear() + font_height = robotron.height + display.draw_text(0, 0, + 'PORTRAIT', robotron, + color565(255, 255, 0), + landscape=False, rotate_180=False) + text_width = robotron.measure_text('LANDSCAPE') + display.draw_text(0, display.height - 1, + 'LANDSCAPE', robotron, + color565(255, 0, 0), + landscape=True, rotate_180=False) + text_width = robotron.measure_text('PORTRAIT,') + display.draw_text(display.width - text_width - 1, + display.height - font_height, + 'PORTRAIT,', robotron, + color565(255, 0, 255), + landscape=False, rotate_180=True) + text_width = robotron.measure_text('ROTATE 180') + display.draw_text(display.width - text_width - 1, + display.height - font_height * 2, + 'ROTATE 180', robotron, + color565(255, 0, 255), + landscape=False, rotate_180=True) + text_width = robotron.measure_text('LANDSCAPE,') + display.draw_text(display.width - font_height - 1 , text_width, + 'LANDSCAPE,', robotron, + color565(0, 0, 255), + landscape=True, rotate_180=True) + text_width = robotron.measure_text('ROTATE 180') + display.draw_text(display.width - font_height * 2 - 1 , text_width, + 'ROTATE 180', robotron, + color565(0, 0, 255), + landscape=True, rotate_180=True) + sleep(5) + + # Unispace + display.clear() + font_height = unispace.height + display.draw_text(0, 0, + 'PORTRAIT', unispace, + color565(255, 255, 0), + background=color565(255, 0, 0), + landscape=False, rotate_180=False) + text_width = unispace.measure_text('LANDSCAPE') + display.draw_text(0, display.height - 1, + 'LANDSCAPE', unispace, + color565(255, 0, 0), + background=color565(255, 255, 0), + landscape=True, rotate_180=False) + text_width = unispace.measure_text('PORTRAIT,') + display.draw_text(display.width - text_width - 1, + display.height - font_height, + 'PORTRAIT,', unispace, + color565(255, 0, 255), + background=color565(0, 255, 0), + landscape=False, rotate_180=True) + text_width = unispace.measure_text('ROTATE 180') + display.draw_text(display.width - text_width - 1, + display.height - font_height * 2, + 'ROTATE 180', unispace, + color565(255, 0, 255), + background=color565(0, 255, 0), + landscape=False, rotate_180=True) + text_width = unispace.measure_text('LANDSCAPE,') + display.draw_text(display.width - font_height - 1 , text_width, + 'LANDSCAPE,', unispace, + color565(0, 0, 255), + background=color565(255, 255, 0), + landscape=True, rotate_180=True) + text_width = unispace.measure_text('ROTATE 180') + display.draw_text(display.width - font_height * 2 - 1 , text_width, + 'ROTATE 180', unispace, + color565(0, 0, 255), + background=color565(255, 255, 0), + landscape=True, rotate_180=True) + + sleep(10) + display.cleanup() + + +test() diff --git a/fonts/Neato5x7.c b/fonts/Neato5x7.c index 3b3a06d..e6aac5d 100644 --- a/fonts/Neato5x7.c +++ b/fonts/Neato5x7.c @@ -9,15 +9,15 @@ static const unsigned char font[] PROGMEM = { 0x05,0x24,0x2A,0x7F,0x2A,0x12, //36 $ 0x05,0x23,0x13,0x08,0x64,0x62, //37 % 0x05,0x36,0x49,0x56,0x20,0x50, //38 & -0x05,0x00,0x08,0x07,0x03,0x00, //39 ‘ +0x05,0x00,0x08,0x07,0x03,0x00, //39 ' 0x05,0x00,0x1C,0x22,0x41,0x00, //40 ( 0x05,0x00,0x41,0x22,0x1C,0x00, //41 ) 0x05,0x2A,0x1C,0x7F,0x1C,0x2A, //42 * 0x05,0x08,0x08,0x3E,0x08,0x08, //43 + -0x05,0x00,0x80,0x70,0x30,0x00, //44 +0x05,0x00,0x80,0x70,0x30,0x00, //44 , 0x05,0x08,0x08,0x08,0x08,0x08, //45 - 0x05,0x00,0x00,0x60,0x60,0x00, //46 . -0x05,0x20,0x10,0x08,0x04,0x02, //47/ +0x05,0x20,0x10,0x08,0x04,0x02, //47 / 0x05,0x3E,0x51,0x49,0x45,0x3E, //48 0 0x05,0x00,0x42,0x7F,0x40,0x00, //49 1 0x05,0x72,0x49,0x49,0x49,0x46, //50 2 @@ -98,131 +98,131 @@ static const unsigned char font[] PROGMEM = { 0x05,0x00,0x41,0x36,0x08,0x00, //125 } 0x05,0x02,0x01,0x02,0x04,0x02, //126 ~ 0x05,0x3C,0x26,0x23,0x26,0x3C, //127 (delete) -0x05,0x1E,0xA1,0xA1,0x61,0x12, //128 € +0x05,0x1E,0xA1,0xA1,0x61,0x12, //128 � 0x05,0x3A,0x40,0x40,0x20,0x7A, //129 -0x05,0x38,0x54,0x54,0x55,0x59, //130 ‚ -0x05,0x21,0x55,0x55,0x79,0x41, //131 ƒ -0x05,0x21,0x54,0x54,0x78,0x41, //132 „ -0x05,0x21,0x55,0x54,0x78,0x40, //133 … -0x05,0x20,0x54,0x55,0x79,0x40, //134 † -0x05,0x0C,0x1E,0x52,0x72,0x12, //135 ‡ -0x05,0x39,0x55,0x55,0x55,0x59, //136 ˆ -0x05,0x39,0x54,0x54,0x54,0x59, //137 ‰ -0x05,0x39,0x55,0x54,0x54,0x58, //138 Š -0x05,0x00,0x00,0x45,0x7C,0x41, //139 ‹ -0x05,0x00,0x02,0x45,0x7D,0x42, //140 Œ +0x05,0x38,0x54,0x54,0x55,0x59, //130 � +0x05,0x21,0x55,0x55,0x79,0x41, //131 � +0x05,0x21,0x54,0x54,0x78,0x41, //132 � +0x05,0x21,0x55,0x54,0x78,0x40, //133 � +0x05,0x20,0x54,0x55,0x79,0x40, //134 � +0x05,0x0C,0x1E,0x52,0x72,0x12, //135 � +0x05,0x39,0x55,0x55,0x55,0x59, //136 � +0x05,0x39,0x54,0x54,0x54,0x59, //137 � +0x05,0x39,0x55,0x54,0x54,0x58, //138 � +0x05,0x00,0x00,0x45,0x7C,0x41, //139 � +0x05,0x00,0x02,0x45,0x7D,0x42, //140 � 0x05,0x00,0x01,0x45,0x7C,0x40, //141 -0x05,0xF0,0x29,0x24,0x29,0xF0, //142 Ž +0x05,0xF0,0x29,0x24,0x29,0xF0, //142 � 0x05,0xF0,0x28,0x25,0x28,0xF0, //143 0x05,0x7C,0x54,0x55,0x45,0x00, //144 -0x05,0x20,0x54,0x54,0x7C,0x54, //145 ‘ -0x05,0x7C,0x0A,0x09,0x7F,0x49, //146 ’ -0x05,0x32,0x49,0x49,0x49,0x32, //147 “ -0x05,0x32,0x48,0x48,0x48,0x32, //148 ” -0x05,0x32,0x4A,0x48,0x48,0x30, //149 • -0x05,0x3A,0x41,0x41,0x21,0x7A, //150 – -0x05,0x3A,0x42,0x40,0x20,0x78, //151 — -0x05,0x00,0x9D,0xA0,0xA0,0x7D, //152 ˜ -0x05,0x39,0x44,0x44,0x44,0x39, //153 ™ -0x05,0x3D,0x40,0x40,0x40,0x3D, //154 š -0x05,0x3C,0x24,0xFF,0x24,0x24, //155 › -0x05,0x48,0x7E,0x49,0x43,0x66, //156 œ +0x05,0x20,0x54,0x54,0x7C,0x54, //145 � +0x05,0x7C,0x0A,0x09,0x7F,0x49, //146 � +0x05,0x32,0x49,0x49,0x49,0x32, //147 � +0x05,0x32,0x48,0x48,0x48,0x32, //148 � +0x05,0x32,0x4A,0x48,0x48,0x30, //149 � +0x05,0x3A,0x41,0x41,0x21,0x7A, //150 � +0x05,0x3A,0x42,0x40,0x20,0x78, //151 � +0x05,0x00,0x9D,0xA0,0xA0,0x7D, //152 � +0x05,0x39,0x44,0x44,0x44,0x39, //153 � +0x05,0x3D,0x40,0x40,0x40,0x3D, //154 � +0x05,0x3C,0x24,0xFF,0x24,0x24, //155 � +0x05,0x48,0x7E,0x49,0x43,0x66, //156 � 0x05,0x2B,0x2F,0xFC,0x2F,0x2B, //157 -0x05,0xFF,0x09,0x29,0xF6,0x20, //158 ž -0x05,0xC0,0x88,0x7E,0x09,0x03, //159 Ÿ +0x05,0xFF,0x09,0x29,0xF6,0x20, //158 � +0x05,0xC0,0x88,0x7E,0x09,0x03, //159 � 0x05,0x20,0x54,0x54,0x79,0x41, //160 -0x05,0x00,0x00,0x44,0x7D,0x41, //161 ¡ -0x05,0x30,0x48,0x48,0x4A,0x32, //162 ¢ -0x05,0x38,0x40,0x40,0x22,0x7A, //163 £ -0x05,0x00,0x7A,0x0A,0x0A,0x72, //164 ¤ -0x05,0x7D,0x0D,0x19,0x31,0x7D, //165 ¥ -0x05,0x26,0x29,0x29,0x2F,0x28, //166 ¦ -0x05,0x26,0x29,0x29,0x29,0x26, //167 § -0x05,0x30,0x48,0x4D,0x40,0x20, //168 ¨ -0x05,0x38,0x08,0x08,0x08,0x08, //169 © -0x05,0x08,0x08,0x08,0x08,0x38, //170 ª -0x05,0x2F,0x10,0xC8,0xAC,0xBA, //171 « -0x05,0x2F,0x10,0x28,0x34,0xFA, //172 ¬ +0x05,0x00,0x00,0x44,0x7D,0x41, //161 � +0x05,0x30,0x48,0x48,0x4A,0x32, //162 � +0x05,0x38,0x40,0x40,0x22,0x7A, //163 � +0x05,0x00,0x7A,0x0A,0x0A,0x72, //164 � +0x05,0x7D,0x0D,0x19,0x31,0x7D, //165 � +0x05,0x26,0x29,0x29,0x2F,0x28, //166 � +0x05,0x26,0x29,0x29,0x29,0x26, //167 � +0x05,0x30,0x48,0x4D,0x40,0x20, //168 � +0x05,0x38,0x08,0x08,0x08,0x08, //169 � +0x05,0x08,0x08,0x08,0x08,0x38, //170 � +0x05,0x2F,0x10,0xC8,0xAC,0xBA, //171 � +0x05,0x2F,0x10,0x28,0x34,0xFA, //172 � 0x05,0x00,0x00,0x7B,0x00,0x00, //173 -0x05,0x08,0x14,0x2A,0x14,0x22, //174 ® -0x05,0x22,0x14,0x2A,0x14,0x08, //175 ¯ -0x05,0xAA,0x00,0x55,0x00,0xAA, //176 ° -0x05,0xAA,0x55,0xAA,0x55,0xAA, //177 ± -0x05,0x00,0x00,0x00,0xFF,0x00, //178 ² -0x05,0x10,0x10,0x10,0xFF,0x00, //179 ³ -0x05,0x14,0x14,0x14,0xFF,0x00, //180 ´ -0x05,0x10,0x10,0xFF,0x00,0xFF, //181 µ -0x05,0x10,0x10,0xF0,0x10,0xF0, //182 ¶ -0x05,0x14,0x14,0x14,0xFC,0x00, //183 · -0x05,0x14,0x14,0xF7,0x00,0xFF, //184 ¸ -0x05,0x00,0x00,0xFF,0x00,0xFF, //185 ¹ -0x05,0x14,0x14,0xF4,0x04,0xFC, //186 º -0x05,0x14,0x14,0x17,0x10,0x1F, //187 » -0x05,0x10,0x10,0x1F,0x10,0x1F, //188 ¼ -0x05,0x14,0x14,0x14,0x1F,0x00, //189 ½ -0x05,0x10,0x10,0x10,0xF0,0x00, //190 ¾ -0x05,0x00,0x00,0x00,0x1F,0x10, //191 ¿ -0x05,0x10,0x10,0x10,0x1F,0x10, //192 À -0x05,0x10,0x10,0x10,0xF0,0x10, //193 Á -0x05,0x00,0x00,0x00,0xFF,0x10, //194  -0x05,0x10,0x10,0x10,0x10,0x10, //195 à -0x05,0x10,0x10,0x10,0xFF,0x10, //196 Ä -0x05,0x00,0x00,0x00,0xFF,0x14, //197 Å -0x05,0x00,0x00,0xFF,0x00,0xFF, //198 Æ -0x05,0x00,0x00,0x1F,0x10,0x17, //199 Ç -0x05,0x00,0x00,0xFC,0x04,0xF4, //200 È -0x05,0x14,0x14,0x17,0x10,0x17, //201 É -0x05,0x14,0x14,0xF4,0x04,0xF4, //202 Ê -0x05,0x00,0x00,0xFF,0x00,0xF7, //203 Ë -0x05,0x14,0x14,0x14,0x14,0x14, //204 Ì -0x05,0x14,0x14,0xF7,0x00,0xF7, //205 Í -0x05,0x14,0x14,0x14,0x17,0x14, //206 Î -0x05,0x10,0x10,0x1F,0x10,0x1F, //207 Ï -0x05,0x14,0x14,0x14,0xF4,0x14, //208 Ð -0x05,0x10,0x10,0xF0,0x10,0xF0, //219 Ñ -0x05,0x00,0x00,0x1F,0x10,0x1F, //210 Ò -0x05,0x00,0x00,0x00,0x1F,0x14, //211 Ó -0x05,0x00,0x00,0x00,0xFC,0x14, //212 Ô -0x05,0x00,0x00,0xF0,0x10,0xF0, //213 Õ -0x05,0x10,0x10,0xFF,0x10,0xFF, //214 Ö -0x05,0x14,0x14,0x14,0xFF,0x14, //215 × -0x05,0x10,0x10,0x10,0x1F,0x00, //216 Ø -0x05,0x00,0x00,0x00,0xF0,0x10, //217 Ù -0x05,0xFF,0xFF,0xFF,0xFF,0xFF, //218 Ú -0x05,0xF0,0xF0,0xF0,0xF0,0xF0, //219 Û -0x05,0xFF,0xFF,0xFF,0x00,0x00, //220 Ü -0x05,0x00,0x00,0x00,0xFF,0xFF, //221 Ý -0x05,0x0F,0x0F,0x0F,0x0F,0x0F, //222 Þ -0x05,0x38,0x44,0x44,0x38,0x44, //223 ß -0x05,0x7C,0x2A,0x2A,0x3E,0x14, //224 à -0x05,0x7E,0x02,0x02,0x06,0x06, //225 á -0x05,0x02,0x7E,0x02,0x7E,0x02, //226 â -0x05,0x63,0x55,0x49,0x41,0x63, //227 ã -0x05,0x38,0x44,0x44,0x3C,0x04, //228 ä -0x05,0x40,0x7E,0x20,0x1E,0x20, //239 å -0x05,0x06,0x02,0x7E,0x02,0x02, //230 æ -0x05,0x99,0xA5,0xE7,0xA5,0x99, //231 ç -0x05,0x1C,0x2A,0x49,0x2A,0x1C, //232 è -0x05,0x4C,0x72,0x01,0x72,0x4C, //233 é -0x05,0x30,0x4A,0x4D,0x4D,0x30, //234 ê -0x05,0x30,0x48,0x78,0x48,0x30, //235 ë -0x05,0xBC,0x62,0x5A,0x46,0x3D, //236 ì -0x05,0x3E,0x49,0x49,0x49,0x00, //237 í -0x05,0x7E,0x01,0x01,0x01,0x7E, //238 î -0x05,0x2A,0x2A,0x2A,0x2A,0x2A, //239 ï -0x05,0x44,0x44,0x5F,0x44,0x44, //240 ð -0x05,0x40,0x51,0x4A,0x44,0x40, //241 ñ -0x05,0x40,0x44,0x4A,0x51,0x40, //242 ò -0x05,0x00,0x00,0xFF,0x01,0x03, //243 ó -0x05,0xE0,0x80,0xFF,0x00,0x00, //244 ô -0x05,0x08,0x08,0x6B,0x6B,0x08, //245 õ -0x05,0x36,0x12,0x36,0x24,0x36, //246 ö -0x05,0x06,0x0F,0x09,0x0F,0x06, //247 ÷ -0x05,0x00,0x00,0x18,0x18,0x00, //248 ø -0x05,0x00,0x00,0x10,0x10,0x00, //249 ù -0x05,0x30,0x40,0xFF,0x01,0x01, //250 ú -0x05,0x00,0x1F,0x01,0x01,0x1E, //251 û -0x05,0x00,0x19,0x1D,0x17,0x12, //252 ü -0x05,0x00,0x3C,0x3C,0x3C,0x3C, //253 ý -0x05,0x00,0x00,0x00,0x00,0x00, //254 þ +0x05,0x08,0x14,0x2A,0x14,0x22, //174 � +0x05,0x22,0x14,0x2A,0x14,0x08, //175 � +0x05,0xAA,0x00,0x55,0x00,0xAA, //176 � +0x05,0xAA,0x55,0xAA,0x55,0xAA, //177 � +0x05,0x00,0x00,0x00,0xFF,0x00, //178 � +0x05,0x10,0x10,0x10,0xFF,0x00, //179 � +0x05,0x14,0x14,0x14,0xFF,0x00, //180 � +0x05,0x10,0x10,0xFF,0x00,0xFF, //181 � +0x05,0x10,0x10,0xF0,0x10,0xF0, //182 � +0x05,0x14,0x14,0x14,0xFC,0x00, //183 � +0x05,0x14,0x14,0xF7,0x00,0xFF, //184 � +0x05,0x00,0x00,0xFF,0x00,0xFF, //185 � +0x05,0x14,0x14,0xF4,0x04,0xFC, //186 � +0x05,0x14,0x14,0x17,0x10,0x1F, //187 � +0x05,0x10,0x10,0x1F,0x10,0x1F, //188 � +0x05,0x14,0x14,0x14,0x1F,0x00, //189 � +0x05,0x10,0x10,0x10,0xF0,0x00, //190 � +0x05,0x00,0x00,0x00,0x1F,0x10, //191 � +0x05,0x10,0x10,0x10,0x1F,0x10, //192 � +0x05,0x10,0x10,0x10,0xF0,0x10, //193 � +0x05,0x00,0x00,0x00,0xFF,0x10, //194 � +0x05,0x10,0x10,0x10,0x10,0x10, //195 � +0x05,0x10,0x10,0x10,0xFF,0x10, //196 � +0x05,0x00,0x00,0x00,0xFF,0x14, //197 � +0x05,0x00,0x00,0xFF,0x00,0xFF, //198 � +0x05,0x00,0x00,0x1F,0x10,0x17, //199 � +0x05,0x00,0x00,0xFC,0x04,0xF4, //200 � +0x05,0x14,0x14,0x17,0x10,0x17, //201 � +0x05,0x14,0x14,0xF4,0x04,0xF4, //202 � +0x05,0x00,0x00,0xFF,0x00,0xF7, //203 � +0x05,0x14,0x14,0x14,0x14,0x14, //204 � +0x05,0x14,0x14,0xF7,0x00,0xF7, //205 � +0x05,0x14,0x14,0x14,0x17,0x14, //206 � +0x05,0x10,0x10,0x1F,0x10,0x1F, //207 � +0x05,0x14,0x14,0x14,0xF4,0x14, //208 � +0x05,0x10,0x10,0xF0,0x10,0xF0, //219 � +0x05,0x00,0x00,0x1F,0x10,0x1F, //210 � +0x05,0x00,0x00,0x00,0x1F,0x14, //211 � +0x05,0x00,0x00,0x00,0xFC,0x14, //212 � +0x05,0x00,0x00,0xF0,0x10,0xF0, //213 � +0x05,0x10,0x10,0xFF,0x10,0xFF, //214 � +0x05,0x14,0x14,0x14,0xFF,0x14, //215 � +0x05,0x10,0x10,0x10,0x1F,0x00, //216 � +0x05,0x00,0x00,0x00,0xF0,0x10, //217 � +0x05,0xFF,0xFF,0xFF,0xFF,0xFF, //218 � +0x05,0xF0,0xF0,0xF0,0xF0,0xF0, //219 � +0x05,0xFF,0xFF,0xFF,0x00,0x00, //220 � +0x05,0x00,0x00,0x00,0xFF,0xFF, //221 � +0x05,0x0F,0x0F,0x0F,0x0F,0x0F, //222 � +0x05,0x38,0x44,0x44,0x38,0x44, //223 � +0x05,0x7C,0x2A,0x2A,0x3E,0x14, //224 � +0x05,0x7E,0x02,0x02,0x06,0x06, //225 � +0x05,0x02,0x7E,0x02,0x7E,0x02, //226 � +0x05,0x63,0x55,0x49,0x41,0x63, //227 � +0x05,0x38,0x44,0x44,0x3C,0x04, //228 � +0x05,0x40,0x7E,0x20,0x1E,0x20, //239 � +0x05,0x06,0x02,0x7E,0x02,0x02, //230 � +0x05,0x99,0xA5,0xE7,0xA5,0x99, //231 � +0x05,0x1C,0x2A,0x49,0x2A,0x1C, //232 � +0x05,0x4C,0x72,0x01,0x72,0x4C, //233 � +0x05,0x30,0x4A,0x4D,0x4D,0x30, //234 � +0x05,0x30,0x48,0x78,0x48,0x30, //235 � +0x05,0xBC,0x62,0x5A,0x46,0x3D, //236 � +0x05,0x3E,0x49,0x49,0x49,0x00, //237 � +0x05,0x7E,0x01,0x01,0x01,0x7E, //238 � +0x05,0x2A,0x2A,0x2A,0x2A,0x2A, //239 � +0x05,0x44,0x44,0x5F,0x44,0x44, //240 � +0x05,0x40,0x51,0x4A,0x44,0x40, //241 � +0x05,0x40,0x44,0x4A,0x51,0x40, //242 � +0x05,0x00,0x00,0xFF,0x01,0x03, //243 � +0x05,0xE0,0x80,0xFF,0x00,0x00, //244 � +0x05,0x08,0x08,0x6B,0x6B,0x08, //245 � +0x05,0x36,0x12,0x36,0x24,0x36, //246 � +0x05,0x06,0x0F,0x09,0x0F,0x06, //247 � +0x05,0x00,0x00,0x18,0x18,0x00, //248 � +0x05,0x00,0x00,0x10,0x10,0x00, //249 � +0x05,0x30,0x40,0xFF,0x01,0x01, //250 � +0x05,0x00,0x1F,0x01,0x01,0x1E, //251 � +0x05,0x00,0x19,0x1D,0x17,0x12, //252 � +0x05,0x00,0x3C,0x3C,0x3C,0x3C, //253 � +0x05,0x00,0x00,0x00,0x00,0x00, //254 � }; \ No newline at end of file diff --git a/fonts/NeatoReduced5x7.c b/fonts/NeatoReduced5x7.c index 68c5261..36f9268 100644 --- a/fonts/NeatoReduced5x7.c +++ b/fonts/NeatoReduced5x7.c @@ -9,7 +9,7 @@ static const unsigned char font[] PROGMEM = { 0x05,0x24,0x2A,0x7F,0x2A,0x12, //36 $ 0x05,0x23,0x13,0x08,0x64,0x62, //37 % 0x05,0x36,0x49,0x56,0x20,0x50, //38 & -0x05,0x00,0x08,0x07,0x03,0x00, //39 ‘ +0x05,0x00,0x08,0x07,0x03,0x00, //39 ' 0x05,0x00,0x1C,0x22,0x41,0x00, //40 ( 0x05,0x00,0x41,0x22,0x1C,0x00, //41 ) 0x05,0x2A,0x1C,0x7F,0x1C,0x2A, //42 * diff --git a/ili9341.py b/ili9341.py index b81dd37..dd87f74 100644 --- a/ili9341.py +++ b/ili9341.py @@ -357,7 +357,7 @@ class Display(object): buf) def draw_letter(self, x, y, letter, font, color, background=0, - landscape=False): + landscape=False, rotate_180=False): """Draw a letter. Args: @@ -366,10 +366,25 @@ class Display(object): letter (string): Letter to draw. font (XglcdFont object): Font. color (int): RGB565 color value. - background (int): RGB565 background color (default: black). + background (int): RGB565 background color (default: black) landscape (bool): Orientation (default: False = portrait) + rotate_180 (bool): Rotate text by 180 degrees """ buf, w, h = font.get_letter(letter, color, background, landscape) + if rotate_180: + # Manually rotate the buffer by 180 degrees + # ensure bytes pairs for each pixel retain color565 + new_buf = bytearray(len(buf)) + num_pixels = len(buf) // 2 + for i in range(num_pixels): + # The index for the new buffer's byte pair + new_idx = (num_pixels - 1 - i) * 2 + # The index for the original buffer's byte pair + old_idx = i * 2 + # Swap the pixels + new_buf[new_idx], new_buf[new_idx + 1] = buf[old_idx], buf[old_idx + 1] + buf = new_buf + # Check for errors (Font could be missing specified letter) if w == 0: return w, h @@ -529,23 +544,25 @@ class Display(object): self.block(x, y, x2, y2, buf) def draw_text(self, x, y, text, font, color, background=0, - landscape=False, spacing=1): + landscape=False, rotate_180=False, spacing=1): """Draw text. Args: - x (int): Starting X position. - y (int): Starting Y position. - text (string): Text to draw. - font (XglcdFont object): Font. - color (int): RGB565 color value. - background (int): RGB565 background color (default: black). + x (int): Starting X position + y (int): Starting Y position + text (string): Text to draw + font (XglcdFont object): Font + color (int): RGB565 color value + background (int): RGB565 background color (default: black) landscape (bool): Orientation (default: False = portrait) + rotate_180 (bool): Rotate text by 180 degrees spacing (int): Pixels between letters (default: 1) """ - for letter in text: + iterable_text = reversed(text) if rotate_180 else text + for letter in iterable_text: # Get letter array and letter dimensions w, h = self.draw_letter(x, y, letter, font, color, background, - landscape) + landscape, rotate_180) # Stop on error if w == 0 or h == 0: print('Invalid width {0} or height {1}'.format(w, h)) diff --git a/xglcd_font.py b/xglcd_font.py index 615492e..5d28853 100644 --- a/xglcd_font.py +++ b/xglcd_font.py @@ -34,7 +34,7 @@ class XglcdFont(object): letter_count (int): Total number of letters. Default is 96. """ self.width = width - self.height = height + self.height = max(height, 8) self.start_letter = start_letter self.letter_count = letter_count self.bytes_per_letter = (floor(