diff options
author | Cody Hiar <codyfh@gmail.com> | 2018-05-27 15:29:21 -0600 |
---|---|---|
committer | Cody Hiar <codyfh@gmail.com> | 2018-05-27 15:29:21 -0600 |
commit | ceec171c42bd79f1762b971569e20ead656f4fd0 (patch) | |
tree | 1880be0b1cef9786be5bc818cbd50095cd797a6d /lib/Adafruit_Python_CharLCD | |
parent | 611a8b7be4331e4f8416c4d10a0be47a109b47e4 (diff) |
Moving libs into separate own directory
Diffstat (limited to 'lib/Adafruit_Python_CharLCD')
-rw-r--r-- | lib/Adafruit_Python_CharLCD/.github/ISSUE_TEMPLATE.md | 47 | ||||
-rw-r--r-- | lib/Adafruit_Python_CharLCD/.github/PULL_REQUEST_TEMPLATE.md | 26 | ||||
-rw-r--r-- | lib/Adafruit_Python_CharLCD/.gitignore | 5 | ||||
-rwxr-xr-x | lib/Adafruit_Python_CharLCD/Adafruit_CharLCD/Adafruit_CharLCD.py | 477 | ||||
-rw-r--r-- | lib/Adafruit_Python_CharLCD/Adafruit_CharLCD/__init__.py | 1 | ||||
-rw-r--r-- | lib/Adafruit_Python_CharLCD/LICENSE | 21 | ||||
-rw-r--r-- | lib/Adafruit_Python_CharLCD/README.md | 39 | ||||
-rwxr-xr-x | lib/Adafruit_Python_CharLCD/examples/char_lcd.py | 84 | ||||
-rwxr-xr-x | lib/Adafruit_Python_CharLCD/examples/char_lcd_backpack.py | 63 | ||||
-rwxr-xr-x | lib/Adafruit_Python_CharLCD/examples/char_lcd_mcp.py | 85 | ||||
-rwxr-xr-x | lib/Adafruit_Python_CharLCD/examples/char_lcd_plate.py | 75 | ||||
-rwxr-xr-x | lib/Adafruit_Python_CharLCD/examples/char_lcd_rgb.py | 76 | ||||
-rwxr-xr-x | lib/Adafruit_Python_CharLCD/examples/char_lcd_rgb_pwm.py | 129 | ||||
-rw-r--r-- | lib/Adafruit_Python_CharLCD/ez_setup.py | 332 | ||||
-rw-r--r-- | lib/Adafruit_Python_CharLCD/setup.py | 30 |
15 files changed, 1490 insertions, 0 deletions
diff --git a/lib/Adafruit_Python_CharLCD/.github/ISSUE_TEMPLATE.md b/lib/Adafruit_Python_CharLCD/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..6344b2f --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,47 @@ +Thank you for opening an issue on an Adafruit Python library repository. To +improve the speed of resolution please review the following guidelines and +common troubleshooting steps below before creating the issue: + +- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use + the forums at http://forums.adafruit.com to ask questions and troubleshoot why + something isn't working as expected. In many cases the problem is a common issue + that you will more quickly receive help from the forum community. GitHub issues + are meant for known defects in the code. If you don't know if there is a defect + in the code then start with troubleshooting on the forum first. + +- **If following a tutorial or guide be sure you didn't miss a step.** Carefully + check all of the steps and commands to run have been followed. Consult the + forum if you're unsure or have questions about steps in a guide/tutorial. + +- **For Python/Raspberry Pi projects check these very common issues to ensure they don't apply**: + + - If you are receiving an **ImportError: No module named...** error then a + library the code depends on is not installed. Check the tutorial/guide or + README to ensure you have installed the necessary libraries. Usually the + missing library can be installed with the `pip` tool, but check the tutorial/guide + for the exact command. + + - **Be sure you are supplying adequate power to the board.** Check the specs of + your board and power in an external power supply. In many cases just + plugging a board into your computer is not enough to power it and other + peripherals. + + - **Double check all soldering joints and connections.** Flakey connections + cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. + +If you're sure this issue is a defect in the code and checked the steps above +please fill in the following fields to provide enough troubleshooting information. +You may delete the guideline and text above to just leave the following details: + +- Platform/operating system (i.e. Raspberry Pi with Raspbian operating system, + Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): **INSERT PLATFORM/OPERATING + SYSTEM HERE** + +- Python version (run `python -version` or `python3 -version`): **INSERT PYTHON + VERSION HERE** + +- Error message you are receiving, including any Python exception traces: **INSERT + ERROR MESAGE/EXCEPTION TRACES HERE*** + +- List the steps to reproduce the problem below (if possible attach code or commands + to run): **LIST REPRO STEPS BELOW** diff --git a/lib/Adafruit_Python_CharLCD/.github/PULL_REQUEST_TEMPLATE.md b/lib/Adafruit_Python_CharLCD/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..7b641eb --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,26 @@ +Thank you for creating a pull request to contribute to Adafruit's GitHub code! +Before you open the request please review the following guidelines and tips to +help it be more easily integrated: + +- **Describe the scope of your change--i.e. what the change does and what parts + of the code were modified.** This will help us understand any risks of integrating + the code. + +- **Describe any known limitations with your change.** For example if the change + doesn't apply to a supported platform of the library please mention it. + +- **Please run any tests or examples that can exercise your modified code.** We + strive to not break users of the code and running tests/examples helps with this + process. + +Thank you again for contributing! We will try to test and integrate the change +as soon as we can, but be aware we have many GitHub repositories to manage and +can't immediately respond to every request. There is no need to bump or check in +on a pull request (it will clutter the discussion of the request). + +Also don't be worried if the request is closed or not integrated--sometimes the +priorities of Adafruit's GitHub code (education, ease of use) might not match the +priorities of the pull request. Don't fret, the open source community thrives on +forks and GitHub makes it easy to keep your changes in a forked repo. + +After reviewing the guidelines above you can delete this text from the pull request. diff --git a/lib/Adafruit_Python_CharLCD/.gitignore b/lib/Adafruit_Python_CharLCD/.gitignore new file mode 100644 index 0000000..89336e6 --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/.gitignore @@ -0,0 +1,5 @@ +dist/ +build +*.egg-info +*.pyc +setuptools-* diff --git a/lib/Adafruit_Python_CharLCD/Adafruit_CharLCD/Adafruit_CharLCD.py b/lib/Adafruit_Python_CharLCD/Adafruit_CharLCD/Adafruit_CharLCD.py new file mode 100755 index 0000000..b900799 --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/Adafruit_CharLCD/Adafruit_CharLCD.py @@ -0,0 +1,477 @@ +# Copyright (c) 2014 Adafruit Industries +# Author: Tony DiCola +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +import time + +import Adafruit_GPIO as GPIO +import Adafruit_GPIO.I2C as I2C +import Adafruit_GPIO.MCP230xx as MCP +import Adafruit_GPIO.PWM as PWM + + +# Commands +LCD_CLEARDISPLAY = 0x01 +LCD_RETURNHOME = 0x02 +LCD_ENTRYMODESET = 0x04 +LCD_DISPLAYCONTROL = 0x08 +LCD_CURSORSHIFT = 0x10 +LCD_FUNCTIONSET = 0x20 +LCD_SETCGRAMADDR = 0x40 +LCD_SETDDRAMADDR = 0x80 + +# Entry flags +LCD_ENTRYRIGHT = 0x00 +LCD_ENTRYLEFT = 0x02 +LCD_ENTRYSHIFTINCREMENT = 0x01 +LCD_ENTRYSHIFTDECREMENT = 0x00 + +# Control flags +LCD_DISPLAYON = 0x04 +LCD_DISPLAYOFF = 0x00 +LCD_CURSORON = 0x02 +LCD_CURSOROFF = 0x00 +LCD_BLINKON = 0x01 +LCD_BLINKOFF = 0x00 + +# Move flags +LCD_DISPLAYMOVE = 0x08 +LCD_CURSORMOVE = 0x00 +LCD_MOVERIGHT = 0x04 +LCD_MOVELEFT = 0x00 + +# Function set flags +LCD_8BITMODE = 0x10 +LCD_4BITMODE = 0x00 +LCD_2LINE = 0x08 +LCD_1LINE = 0x00 +LCD_5x10DOTS = 0x04 +LCD_5x8DOTS = 0x00 + +# Offset for up to 4 rows. +LCD_ROW_OFFSETS = (0x00, 0x40, 0x14, 0x54) + +# Char LCD plate GPIO numbers. +LCD_PLATE_RS = 15 +LCD_PLATE_RW = 14 +LCD_PLATE_EN = 13 +LCD_PLATE_D4 = 12 +LCD_PLATE_D5 = 11 +LCD_PLATE_D6 = 10 +LCD_PLATE_D7 = 9 +LCD_PLATE_RED = 6 +LCD_PLATE_GREEN = 7 +LCD_PLATE_BLUE = 8 + +# Char LCD plate button names. +SELECT = 0 +RIGHT = 1 +DOWN = 2 +UP = 3 +LEFT = 4 + +# Char LCD backpack GPIO numbers. +LCD_BACKPACK_RS = 1 +LCD_BACKPACK_EN = 2 +LCD_BACKPACK_D4 = 3 +LCD_BACKPACK_D5 = 4 +LCD_BACKPACK_D6 = 5 +LCD_BACKPACK_D7 = 6 +LCD_BACKPACK_LITE = 7 + +class Adafruit_CharLCD(object): + """Class to represent and interact with an HD44780 character LCD display.""" + + def __init__(self, rs, en, d4, d5, d6, d7, cols, lines, backlight=None, + invert_polarity=True, + enable_pwm=False, + gpio=GPIO.get_platform_gpio(), + pwm=PWM.get_platform_pwm(), + initial_backlight=1.0): + """Initialize the LCD. RS, EN, and D4...D7 parameters should be the pins + connected to the LCD RS, clock enable, and data line 4 through 7 connections. + The LCD will be used in its 4-bit mode so these 6 lines are the only ones + required to use the LCD. You must also pass in the number of columns and + lines on the LCD. + + If you would like to control the backlight, pass in the pin connected to + the backlight with the backlight parameter. The invert_polarity boolean + controls if the backlight is one with a LOW signal or HIGH signal. The + default invert_polarity value is True, i.e. the backlight is on with a + LOW signal. + + You can enable PWM of the backlight pin to have finer control on the + brightness. To enable PWM make sure your hardware supports PWM on the + provided backlight pin and set enable_pwm to True (the default is False). + The appropriate PWM library will be used depending on the platform, but + you can provide an explicit one with the pwm parameter. + + The initial state of the backlight is ON, but you can set it to an + explicit initial state with the initial_backlight parameter (0 is off, + 1 is on/full bright). + + You can optionally pass in an explicit GPIO class, + for example if you want to use an MCP230xx GPIO extender. If you don't + pass in an GPIO instance, the default GPIO for the running platform will + be used. + """ + # Save column and line state. + self._cols = cols + self._lines = lines + # Save GPIO state and pin numbers. + self._gpio = gpio + self._rs = rs + self._en = en + self._d4 = d4 + self._d5 = d5 + self._d6 = d6 + self._d7 = d7 + # Save backlight state. + self._backlight = backlight + self._pwm_enabled = enable_pwm + self._pwm = pwm + self._blpol = not invert_polarity + # Setup all pins as outputs. + for pin in (rs, en, d4, d5, d6, d7): + gpio.setup(pin, GPIO.OUT) + # Setup backlight. + if backlight is not None: + if enable_pwm: + pwm.start(backlight, self._pwm_duty_cycle(initial_backlight)) + else: + gpio.setup(backlight, GPIO.OUT) + gpio.output(backlight, self._blpol if initial_backlight else not self._blpol) + # Initialize the display. + self.write8(0x33) + self.write8(0x32) + # Initialize display control, function, and mode registers. + self.displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF + self.displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_2LINE | LCD_5x8DOTS + self.displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT + # Write registers. + self.write8(LCD_DISPLAYCONTROL | self.displaycontrol) + self.write8(LCD_FUNCTIONSET | self.displayfunction) + self.write8(LCD_ENTRYMODESET | self.displaymode) # set the entry mode + self.clear() + + def home(self): + """Move the cursor back to its home (first line and first column).""" + self.write8(LCD_RETURNHOME) # set cursor position to zero + self._delay_microseconds(3000) # this command takes a long time! + + def clear(self): + """Clear the LCD.""" + self.write8(LCD_CLEARDISPLAY) # command to clear display + self._delay_microseconds(3000) # 3000 microsecond sleep, clearing the display takes a long time + + def set_cursor(self, col, row): + """Move the cursor to an explicit column and row position.""" + # Clamp row to the last row of the display. + if row > self._lines: + row = self._lines - 1 + # Set location. + self.write8(LCD_SETDDRAMADDR | (col + LCD_ROW_OFFSETS[row])) + + def enable_display(self, enable): + """Enable or disable the display. Set enable to True to enable.""" + if enable: + self.displaycontrol |= LCD_DISPLAYON + else: + self.displaycontrol &= ~LCD_DISPLAYON + self.write8(LCD_DISPLAYCONTROL | self.displaycontrol) + + def show_cursor(self, show): + """Show or hide the cursor. Cursor is shown if show is True.""" + if show: + self.displaycontrol |= LCD_CURSORON + else: + self.displaycontrol &= ~LCD_CURSORON + self.write8(LCD_DISPLAYCONTROL | self.displaycontrol) + + def blink(self, blink): + """Turn on or off cursor blinking. Set blink to True to enable blinking.""" + if blink: + self.displaycontrol |= LCD_BLINKON + else: + self.displaycontrol &= ~LCD_BLINKON + self.write8(LCD_DISPLAYCONTROL | self.displaycontrol) + + def move_left(self): + """Move display left one position.""" + self.write8(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT) + + def move_right(self): + """Move display right one position.""" + self.write8(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT) + + def set_left_to_right(self): + """Set text direction left to right.""" + self.displaymode |= LCD_ENTRYLEFT + self.write8(LCD_ENTRYMODESET | self.displaymode) + + def set_right_to_left(self): + """Set text direction right to left.""" + self.displaymode &= ~LCD_ENTRYLEFT + self.write8(LCD_ENTRYMODESET | self.displaymode) + + def autoscroll(self, autoscroll): + """Autoscroll will 'right justify' text from the cursor if set True, + otherwise it will 'left justify' the text. + """ + if autoscroll: + self.displaymode |= LCD_ENTRYSHIFTINCREMENT + else: + self.displaymode &= ~LCD_ENTRYSHIFTINCREMENT + self.write8(LCD_ENTRYMODESET | self.displaymode) + + def message(self, text): + """Write text to display. Note that text can include newlines.""" + line = 0 + # Iterate through each character. + for char in text: + # Advance to next line if character is a new line. + if char == '\n': + line += 1 + # Move to left or right side depending on text direction. + col = 0 if self.displaymode & LCD_ENTRYLEFT > 0 else self._cols-1 + self.set_cursor(col, line) + # Write the character to the display. + else: + self.write8(ord(char), True) + + def set_backlight(self, backlight): + """Enable or disable the backlight. If PWM is not enabled (default), a + non-zero backlight value will turn on the backlight and a zero value will + turn it off. If PWM is enabled, backlight can be any value from 0.0 to + 1.0, with 1.0 being full intensity backlight. + """ + if self._backlight is not None: + if self._pwm_enabled: + self._pwm.set_duty_cycle(self._backlight, self._pwm_duty_cycle(backlight)) + else: + self._gpio.output(self._backlight, self._blpol if backlight else not self._blpol) + + def write8(self, value, char_mode=False): + """Write 8-bit value in character or data mode. Value should be an int + value from 0-255, and char_mode is True if character data or False if + non-character data (default). + """ + # One millisecond delay to prevent writing too quickly. + self._delay_microseconds(1000) + # Set character / data bit. + self._gpio.output(self._rs, char_mode) + # Write upper 4 bits. + self._gpio.output_pins({ self._d4: ((value >> 4) & 1) > 0, + self._d5: ((value >> 5) & 1) > 0, + self._d6: ((value >> 6) & 1) > 0, + self._d7: ((value >> 7) & 1) > 0 }) + self._pulse_enable() + # Write lower 4 bits. + self._gpio.output_pins({ self._d4: (value & 1) > 0, + self._d5: ((value >> 1) & 1) > 0, + self._d6: ((value >> 2) & 1) > 0, + self._d7: ((value >> 3) & 1) > 0 }) + self._pulse_enable() + + def create_char(self, location, pattern): + """Fill one of the first 8 CGRAM locations with custom characters. + The location parameter should be between 0 and 7 and pattern should + provide an array of 8 bytes containing the pattern. E.g. you can easyly + design your custom character at http://www.quinapalus.com/hd44780udg.html + To show your custom character use eg. lcd.message('\x01') + """ + # only position 0..7 are allowed + location &= 0x7 + self.write8(LCD_SETCGRAMADDR | (location << 3)) + for i in range(8): + self.write8(pattern[i], char_mode=True) + + def _delay_microseconds(self, microseconds): + # Busy wait in loop because delays are generally very short (few microseconds). + end = time.time() + (microseconds/1000000.0) + while time.time() < end: + pass + + def _pulse_enable(self): + # Pulse the clock enable line off, on, off to send command. + self._gpio.output(self._en, False) + self._delay_microseconds(1) # 1 microsecond pause - enable pulse must be > 450ns + self._gpio.output(self._en, True) + self._delay_microseconds(1) # 1 microsecond pause - enable pulse must be > 450ns + self._gpio.output(self._en, False) + self._delay_microseconds(1) # commands need > 37us to settle + + def _pwm_duty_cycle(self, intensity): + # Convert intensity value of 0.0 to 1.0 to a duty cycle of 0.0 to 100.0 + intensity = 100.0*intensity + # Invert polarity if required. + if not self._blpol: + intensity = 100.0-intensity + return intensity + + +class Adafruit_RGBCharLCD(Adafruit_CharLCD): + """Class to represent and interact with an HD44780 character LCD display with + an RGB backlight.""" + + def __init__(self, rs, en, d4, d5, d6, d7, cols, lines, red, green, blue, + gpio=GPIO.get_platform_gpio(), + invert_polarity=True, + enable_pwm=False, + pwm=PWM.get_platform_pwm(), + initial_color=(1.0, 1.0, 1.0)): + """Initialize the LCD with RGB backlight. RS, EN, and D4...D7 parameters + should be the pins connected to the LCD RS, clock enable, and data line + 4 through 7 connections. The LCD will be used in its 4-bit mode so these + 6 lines are the only ones required to use the LCD. You must also pass in + the number of columns and lines on the LCD. + + The red, green, and blue parameters define the pins which are connected + to the appropriate backlight LEDs. The invert_polarity parameter is a + boolean that controls if the LEDs are on with a LOW or HIGH signal. By + default invert_polarity is True, i.e. the backlight LEDs are on with a + low signal. If you want to enable PWM on the backlight LEDs (for finer + control of colors) and the hardware supports PWM on the provided pins, + set enable_pwm to True. Finally you can set an explicit initial backlight + color with the initial_color parameter. The default initial color is + white (all LEDs lit). + + You can optionally pass in an explicit GPIO class, + for example if you want to use an MCP230xx GPIO extender. If you don't + pass in an GPIO instance, the default GPIO for the running platform will + be used. + """ + super(Adafruit_RGBCharLCD, self).__init__(rs, en, d4, d5, d6, d7, + cols, + lines, + enable_pwm=enable_pwm, + backlight=None, + invert_polarity=invert_polarity, + gpio=gpio, + pwm=pwm) + self._red = red + self._green = green + self._blue = blue + # Setup backlight pins. + if enable_pwm: + # Determine initial backlight duty cycles. + rdc, gdc, bdc = self._rgb_to_duty_cycle(initial_color) + pwm.start(red, rdc) + pwm.start(green, gdc) + pwm.start(blue, bdc) + else: + gpio.setup(red, GPIO.OUT) + gpio.setup(green, GPIO.OUT) + gpio.setup(blue, GPIO.OUT) + self._gpio.output_pins(self._rgb_to_pins(initial_color)) + + def _rgb_to_duty_cycle(self, rgb): + # Convert tuple of RGB 0-1 values to tuple of duty cycles (0-100). + red, green, blue = rgb + # Clamp colors between 0.0 and 1.0 + red = max(0.0, min(1.0, red)) + green = max(0.0, min(1.0, green)) + blue = max(0.0, min(1.0, blue)) + return (self._pwm_duty_cycle(red), + self._pwm_duty_cycle(green), + self._pwm_duty_cycle(blue)) + + def _rgb_to_pins(self, rgb): + # Convert tuple of RGB 0-1 values to dict of pin values. + red, green, blue = rgb + return { self._red: self._blpol if red else not self._blpol, + self._green: self._blpol if green else not self._blpol, + self._blue: self._blpol if blue else not self._blpol } + + def set_color(self, red, green, blue): + """Set backlight color to provided red, green, and blue values. If PWM + is enabled then color components can be values from 0.0 to 1.0, otherwise + components should be zero for off and non-zero for on. + """ + if self._pwm_enabled: + # Set duty cycle of PWM pins. + rdc, gdc, bdc = self._rgb_to_duty_cycle((red, green, blue)) + self._pwm.set_duty_cycle(self._red, rdc) + self._pwm.set_duty_cycle(self._green, gdc) + self._pwm.set_duty_cycle(self._blue, bdc) + else: + # Set appropriate backlight pins based on polarity and enabled colors. + self._gpio.output_pins({self._red: self._blpol if red else not self._blpol, + self._green: self._blpol if green else not self._blpol, + self._blue: self._blpol if blue else not self._blpol }) + + def set_backlight(self, backlight): + """Enable or disable the backlight. If PWM is not enabled (default), a + non-zero backlight value will turn on the backlight and a zero value will + turn it off. If PWM is enabled, backlight can be any value from 0.0 to + 1.0, with 1.0 being full intensity backlight. On an RGB display this + function will set the backlight to all white. + """ + self.set_color(backlight, backlight, backlight) + + + +class Adafruit_CharLCDPlate(Adafruit_RGBCharLCD): + """Class to represent and interact with an Adafruit Raspberry Pi character + LCD plate.""" + + def __init__(self, address=0x20, busnum=I2C.get_default_bus(), cols=16, lines=2): + """Initialize the character LCD plate. Can optionally specify a separate + I2C address or bus number, but the defaults should suffice for most needs. + Can also optionally specify the number of columns and lines on the LCD + (default is 16x2). + """ + # Configure MCP23017 device. + self._mcp = MCP.MCP23017(address=address, busnum=busnum) + # Set LCD R/W pin to low for writing only. + self._mcp.setup(LCD_PLATE_RW, GPIO.OUT) + self._mcp.output(LCD_PLATE_RW, GPIO.LOW) + # Set buttons as inputs with pull-ups enabled. + for button in (SELECT, RIGHT, DOWN, UP, LEFT): + self._mcp.setup(button, GPIO.IN) + self._mcp.pullup(button, True) + # Initialize LCD (with no PWM support). + super(Adafruit_CharLCDPlate, self).__init__(LCD_PLATE_RS, LCD_PLATE_EN, + LCD_PLATE_D4, LCD_PLATE_D5, LCD_PLATE_D6, LCD_PLATE_D7, cols, lines, + LCD_PLATE_RED, LCD_PLATE_GREEN, LCD_PLATE_BLUE, enable_pwm=False, + gpio=self._mcp) + + def is_pressed(self, button): + """Return True if the provided button is pressed, False otherwise.""" + if button not in set((SELECT, RIGHT, DOWN, UP, LEFT)): + raise ValueError('Unknown button, must be SELECT, RIGHT, DOWN, UP, or LEFT.') + return self._mcp.input(button) == GPIO.LOW + + +class Adafruit_CharLCDBackpack(Adafruit_CharLCD): + """Class to represent and interact with an Adafruit I2C / SPI + LCD backpack using I2C.""" + + def __init__(self, address=0x20, busnum=I2C.get_default_bus(), cols=16, lines=2): + """Initialize the character LCD plate. Can optionally specify a separate + I2C address or bus number, but the defaults should suffice for most needs. + Can also optionally specify the number of columns and lines on the LCD + (default is 16x2). + """ + # Configure the MCP23008 device. + self._mcp = MCP.MCP23008(address=address, busnum=busnum) + # Initialize LCD (with no PWM support). + super(Adafruit_CharLCDBackpack, self).__init__(LCD_BACKPACK_RS, LCD_BACKPACK_EN, + LCD_BACKPACK_D4, LCD_BACKPACK_D5, LCD_BACKPACK_D6, LCD_BACKPACK_D7, + cols, lines, LCD_BACKPACK_LITE, enable_pwm=False, gpio=self._mcp)
\ No newline at end of file diff --git a/lib/Adafruit_Python_CharLCD/Adafruit_CharLCD/__init__.py b/lib/Adafruit_Python_CharLCD/Adafruit_CharLCD/__init__.py new file mode 100644 index 0000000..4a69a24 --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/Adafruit_CharLCD/__init__.py @@ -0,0 +1 @@ +from .Adafruit_CharLCD import * diff --git a/lib/Adafruit_Python_CharLCD/LICENSE b/lib/Adafruit_Python_CharLCD/LICENSE new file mode 100644 index 0000000..35a35d3 --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Adafruit Industries + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.
\ No newline at end of file diff --git a/lib/Adafruit_Python_CharLCD/README.md b/lib/Adafruit_Python_CharLCD/README.md new file mode 100644 index 0000000..ab20c26 --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/README.md @@ -0,0 +1,39 @@ +Adafruit_Python_CharLCD +======================= + +Python library for accessing Adafruit character LCDs from a Raspberry Pi or BeagleBone Black. + +Designed specifically to work with the Adafruit character LCDs ----> https://learn.adafruit.com/character-lcds/overview + +For all platforms (Raspberry Pi and Beaglebone Black) make sure you have the following dependencies: + +```` +sudo apt-get update +sudo apt-get install build-essential python-dev python-smbus python-pip +```` + +For a Raspberry Pi make sure you have the RPi.GPIO library by executing: + +```` +sudo pip install RPi.GPIO +```` + +For a BeagleBone Black make sure you have the Adafruit_BBIO library by executing: + +```` +sudo pip install Adafruit_BBIO +```` + +Install the library by downloading with the download link on the right, unzipping the archive, navigating inside the library's directory and executing: + +```` +sudo python setup.py install +```` + +See example of usage in the examples folder. + +Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! + +Written by Tony DiCola for Adafruit Industries. + +MIT license, all text above must be included in any redistribution diff --git a/lib/Adafruit_Python_CharLCD/examples/char_lcd.py b/lib/Adafruit_Python_CharLCD/examples/char_lcd.py new file mode 100755 index 0000000..a7e017e --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/examples/char_lcd.py @@ -0,0 +1,84 @@ +#!/usr/bin/python +# Example using a character LCD connected to a Raspberry Pi or BeagleBone Black. +import time + +import Adafruit_CharLCD as LCD + + +# Raspberry Pi pin configuration: +lcd_rs = 27 # Note this might need to be changed to 21 for older revision Pi's. +lcd_en = 22 +lcd_d4 = 25 +lcd_d5 = 24 +lcd_d6 = 23 +lcd_d7 = 18 +lcd_backlight = 4 + +# BeagleBone Black configuration: +# lcd_rs = 'P8_8' +# lcd_en = 'P8_10' +# lcd_d4 = 'P8_18' +# lcd_d5 = 'P8_16' +# lcd_d6 = 'P8_14' +# lcd_d7 = 'P8_12' +# lcd_backlight = 'P8_7' + +# Define LCD column and row size for 16x2 LCD. +lcd_columns = 16 +lcd_rows = 2 + +# Alternatively specify a 20x4 LCD. +# lcd_columns = 20 +# lcd_rows = 4 + +# Initialize the LCD using the pins above. +lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, + lcd_columns, lcd_rows, lcd_backlight) + +# Print a two line message +lcd.message('Hello\nworld!') + +# Wait 5 seconds +time.sleep(5.0) + +# Demo showing the cursor. +lcd.clear() +lcd.show_cursor(True) +lcd.message('Show cursor') + +time.sleep(5.0) + +# Demo showing the blinking cursor. +lcd.clear() +lcd.blink(True) +lcd.message('Blink cursor') + +time.sleep(5.0) + +# Stop blinking and showing cursor. +lcd.show_cursor(False) +lcd.blink(False) + +# Demo scrolling message right/left. +lcd.clear() +message = 'Scroll' +lcd.message(message) +for i in range(lcd_columns-len(message)): + time.sleep(0.5) + lcd.move_right() +for i in range(lcd_columns-len(message)): + time.sleep(0.5) + lcd.move_left() + +# Demo turning backlight off and on. +lcd.clear() +lcd.message('Flash backlight\nin 5 seconds...') +time.sleep(5.0) +# Turn backlight off. +lcd.set_backlight(0) +time.sleep(2.0) +# Change message. +lcd.clear() +lcd.message('Goodbye!') +# Turn backlight on. +lcd.set_backlight(1) diff --git a/lib/Adafruit_Python_CharLCD/examples/char_lcd_backpack.py b/lib/Adafruit_Python_CharLCD/examples/char_lcd_backpack.py new file mode 100755 index 0000000..3c24949 --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/examples/char_lcd_backpack.py @@ -0,0 +1,63 @@ +#!/usr/bin/python +# Example using a character LCD backpack. +import time + +import Adafruit_CharLCD as LCD + +# Define LCD column and row size for 16x2 LCD. +lcd_columns = 16 +lcd_rows = 2 + +# Initialize the LCD using the pins +lcd = LCD.Adafruit_CharLCDBackpack() + +# Turn backlight on +lcd.set_backlight(0) + +# Print a two line message +lcd.message('Hello\nworld!') + +# Wait 5 seconds +time.sleep(5.0) + +# Demo showing the cursor. +lcd.clear() +lcd.show_cursor(True) +lcd.message('Show cursor') + +time.sleep(5.0) + +# Demo showing the blinking cursor. +lcd.clear() +lcd.blink(True) +lcd.message('Blink cursor') + +time.sleep(5.0) + +# Stop blinking and showing cursor. +lcd.show_cursor(False) +lcd.blink(False) + +# Demo scrolling message right/left. +lcd.clear() +message = 'Scroll' +lcd.message(message) +for i in range(lcd_columns-len(message)): + time.sleep(0.5) + lcd.move_right() +for i in range(lcd_columns-len(message)): + time.sleep(0.5) + lcd.move_left() + +# Demo turning backlight off and on. +lcd.clear() +lcd.message('Flash backlight\nin 5 seconds...') +time.sleep(5.0) +# Turn backlight off. +lcd.set_backlight(1) +time.sleep(2.0) +# Change message. +lcd.clear() +lcd.message('Goodbye!') +# Turn backlight on. +lcd.set_backlight(0)
\ No newline at end of file diff --git a/lib/Adafruit_Python_CharLCD/examples/char_lcd_mcp.py b/lib/Adafruit_Python_CharLCD/examples/char_lcd_mcp.py new file mode 100755 index 0000000..58b8d70 --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/examples/char_lcd_mcp.py @@ -0,0 +1,85 @@ +#!/usr/bin/python +# Example using an RGB character LCD connected to an MCP23017 GPIO extender. +import time + +import Adafruit_CharLCD as LCD +import Adafruit_GPIO.MCP230xx as MCP + + +# Define MCP pins connected to the LCD. +lcd_rs = 0 +lcd_en = 1 +lcd_d4 = 2 +lcd_d5 = 3 +lcd_d6 = 4 +lcd_d7 = 5 +lcd_red = 6 +lcd_green = 7 +lcd_blue = 8 + +# Define LCD column and row size for 16x2 LCD. +lcd_columns = 16 +lcd_rows = 2 + +# Alternatively specify a 20x4 LCD. +# lcd_columns = 20 +# lcd_rows = 4 + +# Initialize MCP23017 device using its default 0x20 I2C address. +gpio = MCP.MCP23017() + +# Alternatively you can initialize the MCP device on another I2C address or bus. +# gpio = MCP.MCP23017(0x24, busnum=1) + +# Initialize the LCD using the pins +lcd = LCD.Adafruit_RGBCharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, + lcd_columns, lcd_rows, lcd_red, lcd_green, lcd_blue, + gpio=gpio) + +# Print a two line message +lcd.message('Hello\nworld!') + +# Wait 5 seconds +time.sleep(5.0) + +# Demo showing the cursor. +lcd.clear() +lcd.show_cursor(True) +lcd.message('Show cursor') + +time.sleep(5.0) + +# Demo showing the blinking cursor. +lcd.clear() +lcd.blink(True) +lcd.message('Blink cursor') + +time.sleep(5.0) + +# Stop blinking and showing cursor. +lcd.show_cursor(False) +lcd.blink(False) + +# Demo scrolling message right/left. +lcd.clear() +message = 'Scroll' +lcd.message(message) +for i in range(lcd_columns-len(message)): + time.sleep(0.5) + lcd.move_right() +for i in range(lcd_columns-len(message)): + time.sleep(0.5) + lcd.move_left() + +# Demo turning backlight off and on. +lcd.clear() +lcd.message('Flash backlight\nin 5 seconds...') +time.sleep(5.0) +# Turn backlight off. +lcd.set_backlight(0) +time.sleep(2.0) +# Change message. +lcd.clear() +lcd.message('Goodbye!') +# Turn backlight on. +lcd.set_backlight(1) diff --git a/lib/Adafruit_Python_CharLCD/examples/char_lcd_plate.py b/lib/Adafruit_Python_CharLCD/examples/char_lcd_plate.py new file mode 100755 index 0000000..be7ccdd --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/examples/char_lcd_plate.py @@ -0,0 +1,75 @@ +#!/usr/bin/python +# Example using a character LCD plate. +import time + +import Adafruit_CharLCD as LCD + + +# Initialize the LCD using the pins +lcd = LCD.Adafruit_CharLCDPlate() + +# create some custom characters +lcd.create_char(1, [2, 3, 2, 2, 14, 30, 12, 0]) +lcd.create_char(2, [0, 1, 3, 22, 28, 8, 0, 0]) +lcd.create_char(3, [0, 14, 21, 23, 17, 14, 0, 0]) +lcd.create_char(4, [31, 17, 10, 4, 10, 17, 31, 0]) +lcd.create_char(5, [8, 12, 10, 9, 10, 12, 8, 0]) +lcd.create_char(6, [2, 6, 10, 18, 10, 6, 2, 0]) +lcd.create_char(7, [31, 17, 21, 21, 21, 21, 17, 31]) + +# Show some basic colors. +lcd.set_color(1.0, 0.0, 0.0) +lcd.clear() +lcd.message('RED \x01') +time.sleep(3.0) + +lcd.set_color(0.0, 1.0, 0.0) +lcd.clear() +lcd.message('GREEN \x02') +time.sleep(3.0) + +lcd.set_color(0.0, 0.0, 1.0) +lcd.clear() +lcd.message('BLUE \x03') +time.sleep(3.0) + +lcd.set_color(1.0, 1.0, 0.0) +lcd.clear() +lcd.message('YELLOW \x04') +time.sleep(3.0) + +lcd.set_color(0.0, 1.0, 1.0) +lcd.clear() +lcd.message('CYAN \x05') +time.sleep(3.0) + +lcd.set_color(1.0, 0.0, 1.0) +lcd.clear() +lcd.message('MAGENTA \x06') +time.sleep(3.0) + +lcd.set_color(1.0, 1.0, 1.0) +lcd.clear() +lcd.message('WHITE \x07') +time.sleep(3.0) + +# Show button state. +lcd.clear() +lcd.message('Press buttons...') + +# Make list of button value, text, and backlight color. +buttons = ( (LCD.SELECT, 'Select', (1,1,1)), + (LCD.LEFT, 'Left' , (1,0,0)), + (LCD.UP, 'Up' , (0,0,1)), + (LCD.DOWN, 'Down' , (0,1,0)), + (LCD.RIGHT, 'Right' , (1,0,1)) ) + +print('Press Ctrl-C to quit.') +while True: + # Loop through each button and check if it is pressed. + for button in buttons: + if lcd.is_pressed(button[0]): + # Button is pressed, change the message and backlight. + lcd.clear() + lcd.message(button[1]) + lcd.set_color(button[2][0], button[2][1], button[2][2]) diff --git a/lib/Adafruit_Python_CharLCD/examples/char_lcd_rgb.py b/lib/Adafruit_Python_CharLCD/examples/char_lcd_rgb.py new file mode 100755 index 0000000..312a9e4 --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/examples/char_lcd_rgb.py @@ -0,0 +1,76 @@ +#!/usr/bin/python +# Example using an RGB character LCD wired directly to Raspberry Pi or BeagleBone Black. +import time + +import Adafruit_CharLCD as LCD + + +# Raspberry Pi configuration: +lcd_rs = 27 # Change this to pin 21 on older revision Raspberry Pi's +lcd_en = 22 +lcd_d4 = 25 +lcd_d5 = 24 +lcd_d6 = 23 +lcd_d7 = 18 +lcd_red = 4 +lcd_green = 17 +lcd_blue = 7 # Pin 7 is CE1 + +# BeagleBone Black configuration: +# lcd_rs = 'P8_8' +# lcd_en = 'P8_10' +# lcd_d4 = 'P8_18' +# lcd_d5 = 'P8_16' +# lcd_d6 = 'P8_14' +# lcd_d7 = 'P8_12' +# lcd_red = 'P8_7' +# lcd_green = 'P8_9' +# lcd_blue = 'P8_11' + +# Define LCD column and row size for 16x2 LCD. +lcd_columns = 16 +lcd_rows = 2 + +# Alternatively specify a 20x4 LCD. +# lcd_columns = 20 +# lcd_rows = 4 + +# Initialize the LCD using the pins above. +lcd = LCD.Adafruit_RGBCharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, + lcd_columns, lcd_rows, lcd_red, lcd_green, lcd_blue) + +# Show some basic colors. +lcd.set_color(1.0, 0.0, 0.0) +lcd.clear() +lcd.message('RED') +time.sleep(3.0) + +lcd.set_color(0.0, 1.0, 0.0) +lcd.clear() +lcd.message('GREEN') +time.sleep(3.0) + +lcd.set_color(0.0, 0.0, 1.0) +lcd.clear() +lcd.message('BLUE') +time.sleep(3.0) + +lcd.set_color(1.0, 1.0, 0.0) +lcd.clear() +lcd.message('YELLOW') +time.sleep(3.0) + +lcd.set_color(0.0, 1.0, 1.0) +lcd.clear() +lcd.message('CYAN') +time.sleep(3.0) + +lcd.set_color(1.0, 0.0, 1.0) +lcd.clear() +lcd.message('MAGENTA') +time.sleep(3.0) + +lcd.set_color(1.0, 1.0, 1.0) +lcd.clear() +lcd.message('WHITE') +time.sleep(3.0) diff --git a/lib/Adafruit_Python_CharLCD/examples/char_lcd_rgb_pwm.py b/lib/Adafruit_Python_CharLCD/examples/char_lcd_rgb_pwm.py new file mode 100755 index 0000000..8f6fc2b --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/examples/char_lcd_rgb_pwm.py @@ -0,0 +1,129 @@ +#!/usr/bin/python +# Example using an RGB character LCD with PWM control of the backlight. +import math +import time + +import Adafruit_CharLCD as LCD + + +def hsv_to_rgb(hsv): + """Converts a tuple of hue, saturation, value to a tuple of red, green blue. + Hue should be an angle from 0.0 to 359.0. Saturation and value should be a + value from 0.0 to 1.0, where saturation controls the intensity of the hue and + value controls the brightness. + """ + # Algorithm adapted from http://www.cs.rit.edu/~ncs/color/t_convert.html + h, s, v = hsv + if s == 0: + return (v, v, v) + h /= 60.0 + i = math.floor(h) + f = h-i + p = v*(1.0-s) + q = v*(1.0-s*f) + t = v*(1.0-s*(1.0-f)) + if i == 0: + return (v, t, p) + elif i == 1: + return (q, v, p) + elif i == 2: + return (p, v, t) + elif i == 3: + return (p, q, v) + elif i == 4: + return (t, p, v) + else: + return (v, p, q) + +# Raspberry Pi configuration: +lcd_rs = 27 # Change this to pin 21 on older revision Raspberry Pi's +lcd_en = 22 +lcd_d4 = 25 +lcd_d5 = 24 +lcd_d6 = 23 +lcd_d7 = 18 +lcd_red = 4 +lcd_green = 17 +lcd_blue = 7 # Pin 7 is CE1 + +# BeagleBone Black configuration: +# lcd_rs = 'P8_8' +# lcd_en = 'P8_10' +# lcd_d4 = 'P8_18' +# lcd_d5 = 'P8_16' +# lcd_d6 = 'P8_14' +# lcd_d7 = 'P8_12' +# lcd_red = 'P9_16' +# lcd_green = 'P9_14' +# lcd_blue = 'P8_13' + +# Define LCD column and row size for 16x2 LCD. +lcd_columns = 16 +lcd_rows = 2 + +# Alternatively specify a 20x4 LCD. +# lcd_columns = 20 +# lcd_rows = 4 + +# Initialize the LCD using the pins +lcd = LCD.Adafruit_RGBCharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, + lcd_columns, lcd_rows, lcd_red, lcd_green, lcd_blue, + enable_pwm=True) + +# Show some basic colors. +lcd.set_color(1.0, 0.0, 0.0) +lcd.clear() +lcd.message('RED') +time.sleep(3.0) + +lcd.set_color(0.0, 1.0, 0.0) +lcd.clear() +lcd.message('GREEN') +time.sleep(3.0) + +lcd.set_color(0.0, 0.0, 1.0) +lcd.clear() +lcd.message('BLUE') +time.sleep(3.0) + +lcd.set_color(1.0, 1.0, 0.0) +lcd.clear() +lcd.message('YELLOW') +time.sleep(3.0) + +lcd.set_color(0.0, 1.0, 1.0) +lcd.clear() +lcd.message('CYAN') +time.sleep(3.0) + +lcd.set_color(1.0, 0.0, 1.0) +lcd.clear() +lcd.message('MAGENTA') +time.sleep(3.0) + +lcd.set_color(1.0, 1.0, 1.0) +lcd.clear() +lcd.message('WHITE') +time.sleep(3.0) + +# Use HSV color space so the hue can be adjusted to see a nice gradient of colors. +# Hue ranges from 0.0 to 359.0, saturation from 0.0 to 1.0, and value from 0.0 to 1.0. +hue = 0.0 +saturation = 1.0 +value = 1.0 + +# Loop through all RGB colors. +lcd.clear() +print('Press Ctrl-C to quit.') +while True: + # Convert HSV to RGB colors. + red, green, blue = hsv_to_rgb((hue, saturation, value)) + # Set backlight color. + lcd.set_color(red, green, blue) + # Print message with RGB values to display. + lcd.set_cursor(0, 0) + lcd.message('RED GREEN BLUE\n{0:0.2f} {1:0.2f} {2:0.2f}'.format(red, green, blue)) + # Increment hue (wrapping around at 360 degrees). + hue += 1.0 + if hue > 359.0: + hue = 0.0 diff --git a/lib/Adafruit_Python_CharLCD/ez_setup.py b/lib/Adafruit_Python_CharLCD/ez_setup.py new file mode 100644 index 0000000..23ea9a2 --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/ez_setup.py @@ -0,0 +1,332 @@ +#!/usr/bin/env python +"""Bootstrap setuptools installation + +To use setuptools in your package's setup.py, include this +file in the same directory and add this to the top of your setup.py:: + + from ez_setup import use_setuptools + use_setuptools() + +To require a specific version of setuptools, set a download +mirror, or use an alternate download directory, simply supply +the appropriate options to ``use_setuptools()``. + +This file can also be run as a script to install or upgrade setuptools. +""" +import os +import shutil +import sys +import tempfile +import zipfile +import optparse +import subprocess +import platform +import textwrap +import contextlib + +from distutils import log + +try: + from site import USER_SITE +except ImportError: + USER_SITE = None + +DEFAULT_VERSION = "3.5.1" +DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/" + +def _python_cmd(*args): + """ + Return True if the command succeeded. + """ + args = (sys.executable,) + args + return subprocess.call(args) == 0 + + +def _install(archive_filename, install_args=()): + with archive_context(archive_filename): + # installing + log.warn('Installing Setuptools') + if not _python_cmd('setup.py', 'install', *install_args): + log.warn('Something went wrong during the installation.') + log.warn('See the error message above.') + # exitcode will be 2 + return 2 + + +def _build_egg(egg, archive_filename, to_dir): + with archive_context(archive_filename): + # building an egg + log.warn('Building a Setuptools egg in %s', to_dir) + _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir) + # returning the result + log.warn(egg) + if not os.path.exists(egg): + raise IOError('Could not build the egg.') + + +def get_zip_class(): + """ + Supplement ZipFile class to support context manager for Python 2.6 + """ + class ContextualZipFile(zipfile.ZipFile): + def __enter__(self): + return self + def __exit__(self, type, value, traceback): + self.close + return zipfile.ZipFile if hasattr(zipfile.ZipFile, '__exit__') else \ + ContextualZipFile + + +@contextlib.contextmanager +def archive_context(filename): + # extracting the archive + tmpdir = tempfile.mkdtemp() + log.warn('Extracting in %s', tmpdir) + old_wd = os.getcwd() + try: + os.chdir(tmpdir) + with get_zip_class()(filename) as archive: + archive.extractall() + + # going in the directory + subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) + os.chdir(subdir) + log.warn('Now working in %s', subdir) + yield + + finally: + os.chdir(old_wd) + shutil.rmtree(tmpdir) + + +def _do_download(version, download_base, to_dir, download_delay): + egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg' + % (version, sys.version_info[0], sys.version_info[1])) + if not os.path.exists(egg): + archive = download_setuptools(version, download_base, + to_dir, download_delay) + _build_egg(egg, archive, to_dir) + sys.path.insert(0, egg) + + # Remove previously-imported pkg_resources if present (see + # https://bitbucket.org/pypa/setuptools/pull-request/7/ for details). + if 'pkg_resources' in sys.modules: + del sys.modules['pkg_resources'] + + import setuptools + setuptools.bootstrap_install_from = egg + + +def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, + to_dir=os.curdir, download_delay=15): + to_dir = os.path.abspath(to_dir) + rep_modules = 'pkg_resources', 'setuptools' + imported = set(sys.modules).intersection(rep_modules) + try: + import pkg_resources + except ImportError: + return _do_download(version, download_base, to_dir, download_delay) + try: + pkg_resources.require("setuptools>=" + version) + return + except pkg_resources.DistributionNotFound: + return _do_download(version, download_base, to_dir, download_delay) + except pkg_resources.VersionConflict as VC_err: + if imported: + msg = textwrap.dedent(""" + The required version of setuptools (>={version}) is not available, + and can't be installed while this script is running. Please + install a more recent version first, using + 'easy_install -U setuptools'. + + (Currently using {VC_err.args[0]!r}) + """).format(VC_err=VC_err, version=version) + sys.stderr.write(msg) + sys.exit(2) + + # otherwise, reload ok + del pkg_resources, sys.modules['pkg_resources'] + return _do_download(version, download_base, to_dir, download_delay) + +def _clean_check(cmd, target): + """ + Run the command to download target. If the command fails, clean up before + re-raising the error. + """ + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError: + if os.access(target, os.F_OK): + os.unlink(target) + raise + +def download_file_powershell(url, target): + """ + Download the file at url to target using Powershell (which will validate + trust). Raise an exception if the command cannot complete. + """ + target = os.path.abspath(target) + cmd = [ + 'powershell', + '-Command', + "(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)" % vars(), + ] + _clean_check(cmd, target) + +def has_powershell(): + if platform.system() != 'Windows': + return False + cmd = ['powershell', '-Command', 'echo test'] + devnull = open(os.path.devnull, 'wb') + try: + try: + subprocess.check_call(cmd, stdout=devnull, stderr=devnull) + except Exception: + return False + finally: + devnull.close() + return True + +download_file_powershell.viable = has_powershell + +def download_file_curl(url, target): + cmd = ['curl', url, '--silent', '--output', target] + _clean_check(cmd, target) + +def has_curl(): + cmd = ['curl', '--version'] + devnull = open(os.path.devnull, 'wb') + try: + try: + subprocess.check_call(cmd, stdout=devnull, stderr=devnull) + except Exception: + return False + finally: + devnull.close() + return True + +download_file_curl.viable = has_curl + +def download_file_wget(url, target): + cmd = ['wget', url, '--quiet', '--output-document', target] + _clean_check(cmd, target) + +def has_wget(): + cmd = ['wget', '--version'] + devnull = open(os.path.devnull, 'wb') + try: + try: + subprocess.check_call(cmd, stdout=devnull, stderr=devnull) + except Exception: + return False + finally: + devnull.close() + return True + +download_file_wget.viable = has_wget + +def download_file_insecure(url, target): + """ + Use Python to download the file, even though it cannot authenticate the + connection. + """ + try: + from urllib.request import urlopen + except ImportError: + from urllib2 import urlopen + src = dst = None + try: + src = urlopen(url) + # Read/write all in one block, so we don't create a corrupt file + # if the download is interrupted. + data = src.read() + dst = open(target, "wb") + dst.write(data) + finally: + if src: + src.close() + if dst: + dst.close() + +download_file_insecure.viable = lambda: True + +def get_best_downloader(): + downloaders = [ + download_file_powershell, + download_file_curl, + download_file_wget, + download_file_insecure, + ] + + for dl in downloaders: + if dl.viable(): + return dl + +def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, + to_dir=os.curdir, delay=15, downloader_factory=get_best_downloader): + """ + Download setuptools from a specified location and return its filename + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end + with a '/'). `to_dir` is the directory where the egg will be downloaded. + `delay` is the number of seconds to pause before an actual download + attempt. + + ``downloader_factory`` should be a function taking no arguments and + returning a function for downloading a URL to a target. + """ + # making sure we use the absolute path + to_dir = os.path.abspath(to_dir) + zip_name = "setuptools-%s.zip" % version + url = download_base + zip_name + saveto = os.path.join(to_dir, zip_name) + if not os.path.exists(saveto): # Avoid repeated downloads + log.warn("Downloading %s", url) + downloader = downloader_factory() + downloader(url, saveto) + return os.path.realpath(saveto) + +def _build_install_args(options): + """ + Build the arguments to 'python setup.py install' on the setuptools package + """ + return ['--user'] if options.user_install else [] + +def _parse_args(): + """ + Parse the command line for options + """ + parser = optparse.OptionParser() + parser.add_option( + '--user', dest='user_install', action='store_true', default=False, + help='install in user site package (requires Python 2.6 or later)') + parser.add_option( + '--download-base', dest='download_base', metavar="URL", + default=DEFAULT_URL, + help='alternative URL from where to download the setuptools package') + parser.add_option( + '--insecure', dest='downloader_factory', action='store_const', + const=lambda: download_file_insecure, default=get_best_downloader, + help='Use internal, non-validating downloader' + ) + parser.add_option( + '--version', help="Specify which version to download", + default=DEFAULT_VERSION, + ) + options, args = parser.parse_args() + # positional arguments are ignored + return options + +def main(): + """Install or upgrade setuptools and EasyInstall""" + options = _parse_args() + archive = download_setuptools( + version=options.version, + download_base=options.download_base, + downloader_factory=options.downloader_factory, + ) + return _install(archive, _build_install_args(options)) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/lib/Adafruit_Python_CharLCD/setup.py b/lib/Adafruit_Python_CharLCD/setup.py new file mode 100644 index 0000000..5c82f48 --- /dev/null +++ b/lib/Adafruit_Python_CharLCD/setup.py @@ -0,0 +1,30 @@ +try: + # Try using ez_setup to install setuptools if not already installed. + from ez_setup import use_setuptools + use_setuptools() +except ImportError: + # Ignore import error and assume Python 3 which already has setuptools. + pass + +from setuptools import setup, find_packages + +classifiers = ['Development Status :: 4 - Beta', + 'Operating System :: POSIX :: Linux', + 'License :: OSI Approved :: MIT License', + 'Intended Audience :: Developers', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Topic :: Software Development', + 'Topic :: System :: Hardware'] + +setup(name = 'Adafruit_CharLCD', + version = '1.1.1', + author = 'Tony DiCola', + author_email = 'tdicola@adafruit.com', + description = 'Library to drive character LCD display and plate.', + license = 'MIT', + classifiers = classifiers, + url = 'https://github.com/adafruit/Adafruit_Python_CharLCD/', + dependency_links = ['https://github.com/adafruit/Adafruit_Python_GPIO/tarball/master#egg=Adafruit-GPIO-0.4.0'], + install_requires = ['Adafruit-GPIO>=0.4.0'], + packages = find_packages()) |