|
| 1 | +"""Generic cross-platform module for typical hub devices like displays, speakers, and batteries.""" |
| 2 | + |
| 3 | +from parameters import Align |
| 4 | + |
| 5 | + |
| 6 | +class Display(): |
| 7 | + """Show images or text on a display.""" |
| 8 | + |
| 9 | + def __init__(self, device_type): |
| 10 | + """Device-specific display initialization.""" |
| 11 | + pass |
| 12 | + |
| 13 | + def clear(self): |
| 14 | + """Clear everything on the display.""" |
| 15 | + pass |
| 16 | + |
| 17 | + def text(self, text, coordinate=None): |
| 18 | + """Display text. |
| 19 | +
|
| 20 | + Parameters: |
| 21 | + text (str): The text to display. |
| 22 | + coordinate (tuple): ``(x, y)`` coordinate tuple. It is the top-left corner of the first character. If no coordinate is specified, it is printed on the next line. |
| 23 | +
|
| 24 | + Example:: |
| 25 | +
|
| 26 | + # Clear the display |
| 27 | + brick.display.clear() |
| 28 | +
|
| 29 | + # Print ``Hello`` near the middle of the screen |
| 30 | + brick.display.text("Hello", (60, 50)) |
| 31 | +
|
| 32 | + # Print ``World`` directly underneath it |
| 33 | + brick.display.text("World") |
| 34 | +
|
| 35 | + """ |
| 36 | + pass |
| 37 | + |
| 38 | + def image(self, file_name, alignment=Align.CENTER, coordinate=None, clear=True): |
| 39 | + """image(file_name, alignment=Align.CENTER, coordinate=None, clear=True) |
| 40 | +
|
| 41 | + Show an image file. |
| 42 | +
|
| 43 | + You can specify its placement either using ``alignment`` or by specifying a ``coordinate``, but not both. |
| 44 | +
|
| 45 | + Arguments: |
| 46 | + file_name (str): Path to the image file. Paths may be absolute or relative from the project folder. |
| 47 | + alignment (Align): Where to place the image (*Default*: Align.CENTER). |
| 48 | + coordinate (tuple): ``(x, y)`` coordinate tuple. It is the top-left corner of the image (*Default*: None). |
| 49 | + clear (bool): Whether to clear the screen before showing the image (*Default*: ``True``). |
| 50 | +
|
| 51 | + Example:: |
| 52 | +
|
| 53 | + # Show a built-in image of two eyes looking upward |
| 54 | + brick.display.image(ImageFile.UP) |
| 55 | +
|
| 56 | + # Display a custom image from your project folder |
| 57 | + brick.display.image('pybricks.png') |
| 58 | +
|
| 59 | + # Display a custom image at the top right of the screen, without clearing |
| 60 | + # the screen first |
| 61 | + brick.display.image('arrow.png', Align.TOP_RIGHT, clear=False) |
| 62 | + """ |
| 63 | + pass |
| 64 | + |
| 65 | + |
| 66 | +class Speaker(): |
| 67 | + """Play beeps and sound files using a speaker.""" |
| 68 | + |
| 69 | + def __init__(self, device_type): |
| 70 | + """Device specific speaker initialization.""" |
| 71 | + pass |
| 72 | + |
| 73 | + def beep(self, frequency=500, duration=100, volume=30): |
| 74 | + """Play a beep/tone. |
| 75 | +
|
| 76 | + Arguments: |
| 77 | + frequency (:ref:`frequency`): Frequency of the beep (*Default*: 500). |
| 78 | + duration (:ref:`time`): Duration of the beep (*Default*: 100). |
| 79 | + volume (:ref:`percentage`): Volume of the beep (*Default*: 30). |
| 80 | +
|
| 81 | + Example:: |
| 82 | +
|
| 83 | + # A simple beep |
| 84 | + brick.sound.beep() |
| 85 | +
|
| 86 | + # A high pitch (1500 Hz) for one second (1000 ms) at 50% volume |
| 87 | + brick.sound.beep(1500, 1000, 50) |
| 88 | + """ |
| 89 | + pass |
| 90 | + |
| 91 | + def beeps(self, number): |
| 92 | + """Play a number of default beeps with a brief pause in between. |
| 93 | +
|
| 94 | + Arguments: |
| 95 | + number (int): Number of beeps. |
| 96 | +
|
| 97 | + Example:: |
| 98 | +
|
| 99 | + # Make 5 simple beeps |
| 100 | + brick.sound.beeps(5) |
| 101 | + """ |
| 102 | + pass |
| 103 | + |
| 104 | + def file(self, file_name, volume=100): |
| 105 | + """Play a sound file. |
| 106 | +
|
| 107 | + Arguments: |
| 108 | + file_name (str): Path to the sound file, including extension. |
| 109 | + volume (:ref:`percentage`): Volume of the sound (*Default*: 100). |
| 110 | +
|
| 111 | + Example:: |
| 112 | +
|
| 113 | + # Play one of the built-in sounds |
| 114 | + brick.sound.file(SoundFile.HELLO) |
| 115 | +
|
| 116 | + # Play a sound file from your project folder |
| 117 | + brick.sound.file('mysound.wav') |
| 118 | +
|
| 119 | + """ |
| 120 | + |
| 121 | + pass |
| 122 | + |
| 123 | + |
| 124 | +class Battery(): |
| 125 | + """Get the status of a battery.""" |
| 126 | + |
| 127 | + def __init__(self, device_type): |
| 128 | + """Battery-specific initialization.""" |
| 129 | + pass |
| 130 | + |
| 131 | + def voltage(self): |
| 132 | + """Get the voltage of the battery. |
| 133 | +
|
| 134 | + Returns: |
| 135 | + :ref:`voltage`: Battery voltage. |
| 136 | +
|
| 137 | + Examples:: |
| 138 | +
|
| 139 | + # Play a warning sound when the battery voltage |
| 140 | + # is below 7 Volt (7000 mV = 7V) |
| 141 | + if brick.battery.voltage() < 7000: |
| 142 | + brick.sound.beep() |
| 143 | +
|
| 144 | + """ |
| 145 | + pass |
| 146 | + |
| 147 | + def current(self): |
| 148 | + """Get the current supplied by the battery. |
| 149 | +
|
| 150 | + Returns: |
| 151 | + :ref:`current`: Battery current. |
| 152 | +
|
| 153 | + """ |
| 154 | + pass |
0 commit comments