File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/sensehat.cpython-310.pyc
Back
o ;jF � @ s� d Z ddlZz ddlmZ dZW n eefy dadZY nw e�e �Z dd� Zdd � Zd d� Z dd � Zdd� Zd%dd�Z d&dd�Zd'dd�Zdd� Zd(dd�Zdd� Zdd� Zdd � Zd!d"� Zd#d$� ZdS ))a Module for controlling the LED matrix or reading environment data on the SenseHat of a Raspberry Pi. .. versionadded:: 2017.7.0 :maintainer: Benedikt Werner <1benediktwerner@gmail.com>, Joachim Werner <joe@suse.com> :maturity: new :depends: sense_hat Python module The rotation of the Pi can be specified in a pillar. This is useful if the Pi is used upside down or sideways to correct the orientation of the image being shown. Example: .. code-block:: yaml sensehat: rotation: 90 � N)�SenseHatTFc C s^ t r-zt� aW n ty Y dS w td dd�} | dv r%t�| d� dS t�d| � dS d S ) z7 Only load the module if SenseHat is available )Fz?This module can only be used on a Raspberry Pi with a SenseHat.z pillar.getzsensehat:rotationr )r �Z � i Fz3%s is not a valid rotation. Using default rotation.T)FzWThe SenseHat execution module cannot be loaded: 'sense_hat' python library unavailable.)� has_sense_hatr � _sensehat�OSErrorZ__salt__Zset_rotation�log�error)Zrotation� r �I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/sensehat.py�__virtual__# s ��r c C s t �| � d| iS )z� Sets the entire LED matrix based on a list of 64 pixel values pixels A list of 64 ``[R, G, B]`` color values. �pixels)r � set_pixels)r r r r r ? s r c C � t �� S )a� Returns a list of 64 smaller lists of ``[R, G, B]`` pixels representing the the currently displayed image on the LED matrix. .. note:: When using ``set_pixels`` the pixel values can sometimes change when you read them again using ``get_pixels``. This is because we specify each pixel element as 8 bit numbers (0 to 255) but when they're passed into the Linux frame buffer for the LED matrix the numbers are bit shifted down to fit into RGB 565. 5 bits for red, 6 bits for green and 5 bits for blue. The loss of binary precision when performing this conversion (3 bits lost for red, 2 for green and 3 for blue) accounts for the discrepancies you see. The ``get_pixels`` method provides an accurate representation of how the pixels end up in frame buffer memory after you have called ``set_pixels``. )r � get_pixelsr r r r r J s r c C s t �| ||� d|iS )a� Sets a single pixel on the LED matrix to a specified color. x The x coordinate of the pixel. Ranges from 0 on the left to 7 on the right. y The y coordinate of the pixel. Ranges from 0 at the top to 7 at the bottom. color The new color of the pixel as a list of ``[R, G, B]`` values. CLI Example: .. code-block:: bash salt 'raspberry' sensehat.set_pixel 0 0 '[255, 0, 0]' �color)r � set_pixel)�x�yr r r r r _ s r c C s t �| |�S )a4 Returns the color of a single pixel on the LED matrix. x The x coordinate of the pixel. Ranges from 0 on the left to 7 on the right. y The y coordinate of the pixel. Ranges from 0 at the top to 7 at the bottom. .. note:: Please read the note for ``get_pixels`` )r � get_pixel)r r r r r r t s r c C s | t _d| iS )z� Sets the LED matrix to low light mode. Useful in a dark environment. CLI Example: .. code-block:: bash salt 'raspberry' sensehat.low_light salt 'raspberry' sensehat.low_light False � low_light)r r )r r r r r � s r 皙�����?c C s^ |pg d�}|pg d�}g d�g d�g d�g d�d�}||v r#|| }t �| |||� d| iS ) ad Displays a message on the LED matrix. message The message to display msg_type The type of the message. Changes the appearance of the message. Available types are:: error: red text warning: orange text success: green text info: blue text scroll_speed The speed at which the message moves over the LED matrix. This value represents the time paused for between shifting the text to the left by one column of pixels. Defaults to '0.1'. text_color The color in which the message is shown. Defaults to '[255, 255, 255]' (white). back_color The background color of the display. Defaults to '[0, 0, 0]' (black). CLI Example: .. code-block:: bash salt 'raspberry' sensehat.show_message 'Status ok' salt 'raspberry' sensehat.show_message 'Something went wrong' error salt 'raspberry' sensehat.show_message 'Red' text_color='[255, 0, 0]' salt 'raspberry' sensehat.show_message 'Hello world' None '[0, 0, 255]' '[255, 255, 0]' 0.2 �� r r �r r r )r r r )r �d r )r r r )r r r )r �warning�success�info�message)r �show_message)r �msg_type� text_color� back_colorZscroll_speedZ color_by_typer r r r � s $�r c C s. |pg d�}|pg d�}t �| ||� d| iS )a Displays a single letter on the LED matrix. letter The letter to display text_color The color in which the letter is shown. Defaults to '[255, 255, 255]' (white). back_color The background color of the display. Defaults to '[0, 0, 0]' (black). CLI Example: .. code-block:: bash salt 'raspberry' sensehat.show_letter O salt 'raspberry' sensehat.show_letter X '[255, 0, 0]' salt 'raspberry' sensehat.show_letter B '[0, 0, 255]' '[255, 255, 0]' r r �letter)r �show_letter)r$ r"