Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
lcd.cpython-313.pyc169 linesDownload Raw Back to __pycache__
1�

2��j�D���SSKJr SSKrSSKrSSKrSSKJr \R(aSSKJ	r	J3r4 SSKJr SSK
Jr "SS	\\R5r"S5S\\R5r"SS
5r"SS\5rg)�)�annotationsN�)�6BaseScreen)�Iterable�Sequence)�Literal)�Canvasc�X�\rSrSr%SrS\S'SSSjjrSrSrS	r	S7r8g)
�	LCDScreen�%z!Base class for LCD-based screens.�tuple[int, int]�DISPLAY_SIZENc��g�N�)�self�colors�bright_is_bold�
has_underlines    �WD:\code\apps\devtools\python\user_packages\Python313\site-packages\urwid/display/lcd.py�set_terminal_properties�!LCDScreen.set_terminal_properties*s��	
�c��grr�r�argss  r�set_input_timeouts�LCDScreen.set_input_timeouts2���rc��grrrs  r�reset_default_terminal_palette�(LCDScreen.reset_default_terminal_palette5rrc��UR$r)r�rs r�
get_cols_rows�LCDScreen.get_cols_rows8s��� � � rr)NNN)rz(Literal[1, 16, 88, 256, 16777216] | Noner�bool | Nonerr'�return�None)�__name__�9__module__�__qualname__�__firstlineno__�__doc__�__annotations__rrr!r%�__static_attributes__rrrrr%sQ��+�!�!�<@�&*�%)�	
�8�
�$�
�#�	
�1011�
�
�
�!rrc��^�\rSrSr%Sr/SQrS\S'SrSrSr	S	r12S13rSrSr
S
rSrSrSrSrSrSrSrSrSrSrSrSrS!U4Sjjr\S"Sj5rS#SjrS$Sjr"SS\ 5r!"SS\ 5r"\S%Sj5r#S r$U=r%$)&�CFLCDScreen�<z/14Common methods for Crystal Fonts LCD displays15)N�up_press�16down_press�17left_press�right_press�enter_press�18exit_press�19up_release�down_release�left_release�
right_release�
enter_release�exit_release�ul_press�ur_press�ll_press�lr_press�20ul_release�21ur_release�22ll_release�23lr_releasez!typing.ClassVar[list[str | None]]�KEYSrr��	���
���"��@����Fc�p>�[TU]5 XlSSKJn U"XSS9Ul[
5Ulg)z524device_path -- eg. '/dev/ttyUSB0'25baud -- baud rate26r)�Serial)�timeoutN)�super�__init__�device_path�serialrX�_device�	bytearray�_unprocessed)rr\�baudrX�	__class__s    �rr[�CFLCDScreen.__init__rs1���27	����&��!��k��;���%�K��rc��SnUH=n[S5H+nUS-nUSU--(aUS-nUS-(dM&US-nM- M? [S5HnUS-nUS-(dMUS-nM U)S-	S-RS	S285$)Ni!��ri�rQi��i��rS�little)�range�to_bytes)�cls�buf�new_crc�byte�	bit_count�29_bit_counts      r�get_crc�CFLCDScreen.get_crc~s������D�#�1�X�	��A�
���4�9�,�-��z�)�G��Z�'�'��z�)�G�&��  ��)�J���M�G���#�#��:�%��$��(�q��F�*�4�4�Q��A�Arc���[U[U5/5nURU5 URURU55 URRU5 g)z}30low-level packet sending.31Following the protocol requires waiting for ack packet between32sending each packet to the device.33N)r_�len�extendrpr^�write)r�command�datarks    r�_send_packet�CFLCDScreen._send_packet�sJ����#�d�)�,�-���34�35�4���36�37�4�<�<��$�%������3�rc�(�U=RURR5-
slURUR5upnX0lX4$!URa gUR38a URSSUlOf=fMe)z�39low-level packet reading.40returns (command/report code, data) or None41 42This method stored data read and tries to resync when bad data43is received.44Nr)r`r^�read�_parse_data�MoreDataRequired�
InvalidPacket)rrvrw�unprocesseds    r�_read_packet�CFLCDScreen._read_packet�s���	
���T�\�\�.�.�0�0���	
%�-1�-=�-=�d�>O�>O�-P�*��{�$/�!��}�$��
�(�(�
���%�%�
:�$(�$5�$5�a�b�$9��!�
:��
s�$A�B�)#B�Bc��\rSrSrSrg)�CFLCDScreen.InvalidPacket��rN�r*r+r,r-r0rrrr~r�����rr~c��\rSrSrSrg)�CFLCDScreen.MoreDataRequired��rNr�rrrr}r��r�rr}c�^�[U5S:aUReUSnUSnX0R:�aURS5e[U5US-:aUReSU-nUR	USU5=oQXDS-=n:waURSU<SU<S	35eX!SUXS-S4$)45z�46Try to read a packet from the start of data, returning47(command/report code, packet_data, remaining_data)48or raising InvalidPacket or MoreDataRequired49rSrrzlength value too largerUNzCRC doesn't match (crc=z
, packet_crc=�))rsr}�MAX_PACKET_DATA_LENGTHr~rp)rjrwrv�50packet_len�data_end�crc�51packet_crcs       rr|�CFLCDScreen._parse_data�s����t�9�q�=��&�&�&��A�w���q�'�52��2�2�2��#�#�$<�=�=��t�9�z�A�~�%��&�&�&��z�>���;�;�t�I�X��/�/�C��^_�S_�C`�5`�Z�a��#�#�&>�#��~�*��a�$P�Q�Q��Q�x�(�$�!�|�~�*>�>�>r)r^r`r\)r\�strra�intr(r))rkz
Iterable[int]r(�bytes)rvr�rwr�r(r))r(ztuple[int, bytearray] | None)rwr_r(z tuple[int, bytearray, bytearray])&r*r+r,r-r.rHr/�CMD_PING�CMD_VERSION�	CMD_CLEAR�	CMD_CGRAM�CMD_CURSOR_POSITION�CMD_CURSOR_STYLE�CMD_LCD_CONTRAST�
CMD_BACKLIGHT�CMD_LCD_DATA�CMD_GPO�CMD_KEY_ACTIVITY�CMD_ACK�CURSOR_NONE�CURSOR_BLINKING_BLOCK�CURSOR_UNDERSCORE� CURSOR_BLINKING_BLOCK_UNDERSCORE�CURSOR_INVERTING_BLINKING_BLOCKr�rrr[�classmethodrprxr��	Exceptionr~r}r|r0�
__classcell__�rbs@rr2r2<s�����/�D�53+��.�H��K��I��I��������M��L��G����G��K�����'(�$�&'�#���
�F��M�54(��!B��!B�F	 �%�,
�	�
�
�9�
��?��?rr2c�J�\rSrSrSrS55SjrSSjrSSjrSSjrS
Sjr	Sr56g	)�KeyRepeatSimulator��z�57Provide simulated repeat key events when given press and58release events.59 60If two or more keys are pressed, disable repeating until all61keys are released.62c�8�XlX l0UlSUlg)zn63repeat_delay -- seconds to wait before starting to repeat keys64repeat_next -- time between each repeated key65FN)�repeat_delay�repeat_next�pressed�multiple_pressed)rr�r�s   rr[�KeyRepeatSimulator.__init__�s��66)��&��)+��� %��rc�x�UR(aSUl[R"5URU'g)NT)r�r��time�r�keys  r�press�KeyRepeatSimulator.press�s%���<�<�$(�D�!� �I�I�K����S�rc�p�XR;agURU	UR(dSUlgg)NF)r�r�r�s  r�release�KeyRepeatSimulator.release�s/���l�l�"���L�L����|�|�$)�D�!�rc��[UR5S:wdUR(agURR5H5up[	SX R67-[R"5-685U4s $ g)z�69Return (remaining, key) where remaining is the number of seconds70(float) until the key repeat event should be sent, or None if no71events are pending.72rNg)rsr�r��items�maxr�r�)rr��vals   r�73next_event�KeyRepeatSimulator.next_eventsb���t�|�|���!�T�%:�%:�����*�*�,�H�C��s�C�"3�"3�3�d�i�i�k�A�B�C�G�G�-�rc���[UR5S:wagURH?n[R"5UR-74UR-URU' g g)zf75Cakk this method when you have sent a key repeat event so the76timer will be reset for the next event77rN)rsr�r�r�r�r�s  r�78sent_event�KeyRepeatSimulator.sent_eventsS��79�t�|�|���!���<�<�C� $�	�	��d�.?�.?� ?�$�BR�BR� R�D�L�L���� r)r�r�r�r�N)r��floatr�r�r(r))r�r�r(r))r(ztuple[float, str] | None�r(r))r*r+r,r-r.r[r�r�r�r�r0rrrr�r��s ���&�(�80*�81�	rr�c��^�\rSrSrSrSrSr\Rr	SSU4Sjjjr82SSjrSSjrSSjr
SS	jrSS83jrSSjrSSjrSS
jrSSjrSSjrSrU=r$)�CF635Screenia84Crystal Fontz 635 display85 8620x4 character display + cursor87no foreground/background colors or settings supported88 89see CGROM for a list of close Unicode matches to characters available90 916 button input92up, down, left, right, enter (check mark), exit (cross)93)�rUu�①②③④⑤⑥⑦⑧①②③④⑤⑥⑦⑧►◄⇑⇓«»↖↗↙↘▲▼↲^ˇ█ !"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà⁰¹²³⁴⁵⁶⁷⁸⁹½¼±≥≤μ♪♫⑴♥♦⑵⌜⌟“”()αɛδ∞@£$¥èéùìòÇᴾØøʳÅå⌂¢ΦτλΩπΨΣθΞ♈ÆæßÉΓΛΠϒ_ÈÊêçğŞşİι~◊▇▆▄▃▁ƒ▉▋▌▍▏⑶◽▪↑→↓←ÁÍÓÚÝáíóúýÔôŮůČĔŘŠŽčĕřšž[\]{|}c��>�[TU]X5 X0lX@l[	X45Ul[
U5UlSUlSUl	/Ul94SUlSUlSUl
g)z�95device_path -- eg. '/dev/ttyUSB0'96baud -- baud rate97repeat_delay -- seconds to wait before starting to repeat keys98repeat_next -- time between each repeated key99key_map -- the keys to send for this device's buttons100NrF)rZr[r�r�r��101key_repeat�tuple�key_map�
_last_command�_last_command_time�_command_queue�_screen_buf�_previous_canvas�_update_cursor)rr\rar�r�r�rbs      �rr[�CF635Screen.__init__Fse���	����+�(��&��,�\�G����W�~���!���"#���;=������ $���#��rc�0�URR/$)zN102return the fd from our serial device so we get called103on input and responses104)r^�fdr$s r�get_input_descriptors�!CF635Screen.get_input_descriptorscs��105����� � rc���/n/nSnUR5nU(a�UupVXPR:Xa�U(a�USnSUs=::aS::a�O O�US:�nXxS--106S-107n	URU	n108U(aURR	U1095 O,URU1105 URR
U1115 URU5 O,US-S:Xa#US-UR:XaUR5 UR5nU(aM�URR5=n(a8Uup:U(d-URU1125 URR5 SnX1U4$)	a�113Return a (next_input_timeout, keys_pressed, raw_keycodes)114tuple.115 116The protocol for our device requires waiting for acks between117each command, so this method responds to those as well as key118press and release events.119 120Key repeat events are simulated here as the device doesn't send121any for us.122 123raw_keycodes are the bytes of messages we received, which might124not seem to have any correspondence to keys_pressed.125NrrrLrI��rR�?)r�r�r�r�r��appendr�r��_send_next_commandr�r�)r�126data_input�raw_data_inputrY�packetrvrw�d0r��keycoder��next_repeats            r�get_input_nonblocking�!CF635Screen.get_input_nonblockingjsI��!#�127�$&�����"�"�$���"�M�G��/�/�/�D��!�W����=�b�=� �1�f�G� �a�K�0�1�4�G��,�,�w�/�C�����/�/��4�"�)�)�#�.����-�-�c�2�"�)�)�"�-���4��4�'�G�d�N�d�>P�>P�,P��'�'�)��&�&�(�F�'�f�*�/�/�4�4�6�6�;�6�&�L�G���!�!�#�&����*�*�,����N�2�2rc���UR(dSUlgURRS5upURX5 Xl[R"5Ulg)z(128send out the next command in the queue129Nr)r�r��poprxr�r��rrvrws   rr��CF635Screen._send_next_command�sR���"�"�!%�D����+�+�/�/��2�
�����'�(�$��"&�)�)�+��rc�x�URRX45 URcUR5 ggr)r�r�r�r�r�s   r�
queue_command�CF635Screen.queue_command�s5�����"�"�G�?�3����%��#�#�%�&rc	���XR:wa[U5eUR(a
URnO/n/n[UR	55H�upVUVVV	s/sHupxo�PM	 n130nnn	U(aX5U131:waC[SU/5nU132HnUR
U5 M URURU5 URU1335 M� UR(aGURRUR:Xa#UR(aUR(dO�URc1URUR[UR/55 OdURup�URUR[X�/55 URUR[UR /55 SUlX@lX l134gs sn	nnf)NrF)r�135ValueErrorr��	enumerate�contentr_rtr�r�r�r��cursorr�r�r�r��cursor_style)r�size�canvas�osb�sb�y�row�_a�_cs�run�textrw�elem�xs              r�draw_screen�CF635Screen.draw_screen�s���$�$�$��T�"�"�����"�"�C��C�
������ 0�1�F�A�,/�0�C�L�B�S�C�C�D�0��#�&�D�.� �!�Q��(�� �D��K�K��%�!��"�"�4�#4�#4�d�;��I�I�d�O�2�
�!�!��%�%�,�,��
�
�=��(�(��
�
��
�]�]�
"����t�4�4�i��AQ�AQ�@R�6S�T��=�=�D�A����t�7�7��A�6�9J�K����t�4�4�i��AR�AR�@S�6T�U�#����� &���11s�!G(136c���SUs=::aS::d
O [U5e[U5S:wa[U5eURUR[	U/5[	U5-5 g)a137Program character data.138 139Characters available as chr(0) through chr(7), and repeated as chr(8) through chr(15).140 141index -- 0 to 7 index of character to program142 143data -- list of 8, 6-bit integer values top to bottom with MSB on the left side of the character.144r�reN)r�rsr�r�r_)r�indexrws   r�
program_cgram�CF635Screen.program_cgram�sT���E��Q���U�#�#��t�9��>��T�"�"����4�>�>�9�e�W�+=�	�$��+O�Prc�R�SUs=::aS::d
O [U5eXlSUlg)z�145style -- CURSOR_BLINKING_BLOCK, CURSOR_UNDERSCORE,146    CURSOR_BLINKING_BLOCK_UNDERSCORE or147    CURSOR_INVERTING_BLINKING_BLOCK148rrUTN)r�r�r�)r�styles  r�set_cursor_style�CF635Screen.set_cursor_style�s(���E��Q���U�#�#�!��"��rc��SUs=::aS::d
O [U5eURUR[U/55 g)z-149Set backlight brightness150 151value -- 0 to 100152r�dN)r�r�r�r_�r�values  r�
set_backlight�CF635Screen.set_backlight�s9���E� �S� ��U�#�#����4�-�-�y�%��/A�Brc��SUs=::aS::d
O [U5eURUR[U/55 g)z153value -- 0 to 255154r��N)r�r�r�r_rs  r�set_lcd_contrast�CF635Screen.set_lcd_contrast�s9���E� �S� ��U�#�#����4�0�0�)�U�G�2D�Erc���SUs=::aS::d
O [U5eUS;a[U5eSUs=::aS::d
O [U5eURUR[SSU--155U-156U/55 g)z>157led -- 0 to 3158rg -- 0 for red, 1 for green159value -- 0 to 100160rrT>rrrrLrSN)r�r�r�r_)r�led�rgr
s    r�set_led_pin�CF635Screen.set_led_pinsn���C�}�1�}��S�/�!�
�V���R�.� ��E� �S� ��U�#�#����4�<�<��B��S��L�2�4E�u�3M�)N�Or)r�r�r�r�r�r�r�r�r�r�r�)i�g�?g�?)�up�down�left�right�enter�esc)161r\r�rar�r�r�r�r�r�z
Iterable[str])r(z	list[int])r(z!tuple[None, list[str], list[int]]r�)rvr�rwr_r(r))r�r
r�r	r(r))rr�rwz
Sequence[int]r(r))rzLiteral[1, 2, 3, 4]r(r))r
r�r(r))rzLiteral[0, 1, 2, 3]rz
Literal[0, 1]r
r�r(r))r*r+r,r-r.r�CGROMr2r�r�r[r�r�r�r�r�rrrrrr0r�r�s@rr�r�s����162��L�	&�163�&�>�>�L�164�!�"�!P�
$��$��$��	$�165�$��
$�$�:!�03�d166.�&�#'�JQ� 	#�C�F�P�Prr�)�167__future__r�abcr��typing�commonr�
TYPE_CHECKING�collections.abcrr�typing_extensionsr�urwidr	�ABCrr2r�r�rrr�<module>r)sj��*#�168��
��	���2�)��!�169�C�G�G�!�.d?�)�S�W�W�d?�N4�4�nrP�+�rPr
codekingpro/portable-devtools · Team Ai