# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['piku', 'piku.commands', 'piku.core', 'piku.template.project']

package_data = \
{'': ['*'], 'piku': ['template/*']}

install_requires = \
['Jinja2>=3.0.3,<4.0.0',
 'appdirs>=1.4.4,<2.0.0',
 'pyserial>=3.5,<4.0',
 'requests>=2.27.1,<3.0.0',
 'toml>=0.10.2,<0.11.0']

entry_points = \
{'console_scripts': ['piku = piku.main:main']}

setup_kwargs = {
    'name': 'piku',
    'version': '0.1.6',
    'description': '',
    'long_description': '# Piku\nPiku is small command line utility for managing CircuitPython projects\n\nThe purpose of this project is to make creating a CircuitPython project, installing packages, deploying, and connecting to a CircuitPython device easy to do from the command line.\n\n\n# Warning\nThis tool is in very early development and needs testing! Please be careful when deploying and make sure you are only deploying your CircuitPython device!  Use at your own risk.\n\n\n# Getting Started\n\n### Installation\nPiku has been lightly tested on Linux and Windows it may also work on macOS.  I don\'t have an Apple computer so contributions welcome! After installation you can learn about Piku or any command line arguments or flags type `piku -h` or `piku <command> -h` or the documentation here.\n\n##### Windows\nTo install Piku in Windows please install Python 3.8 or greater from the windows store or the official python website.  Then install using pip:\n\n```\npip install piku\n```\n\nAfter Piku is installed you should be able to run Piku from the command line.  You can test this by typing `piku version`.\n\n##### Linux\nTo install Piku in Linux, make sure you have Python 3.8 or greater and install using pip3.\n\n```\npip install --user piku\n```\n\nAfter Piku is installed you should be able to run Piku from the command line.  You can test this by typing `piku version`.\n\nSome linux computers do not have the default pip user bin directory included in the PATH.  You may add this directory to your PATH or install without the `--user` argument.\nhttps://unix.stackexchange.com/questions/612779/warning-not-on-path-when-i-tried-to-install-python-extensions-im-new-to-linu\n\n\nAfter installation if your user does not have permissions to use the serial port, you may need to add your user to the `dialout` group.\nhttps://askubuntu.com/questions/58119/changing-permissions-on-serial-port#answer-58122\n\n\n#### MacOS\n\nHelp wanted!  The process should be similar to Linux.\n\n\n### Preparing your Device\n\nBefore creating a project you must have CircuitPython installed on your device, and have your device serial and USB drivers installed.  Please check the CircuitPython website for instructions or the documentation of the board you have purchased.  When your done you should be able to see your drive mounted as a USB drive named `CIRCUITPY`.\n\nhttps://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython\n\n\n### Creating a Project\n\nTo create a new Piku project from the command line type:\n\n```\npiku create example\n```\n\nThis will create a new directory with the name of your project and a few folders and files inside. After you have created a project to use Piku, enter the directory of the project you just created to use Piku:\n\n```\ncd example\n```\n\n\n### Deploying your Project\nAfter you have created a project and modified the main `code.py` file you can deploy your project to a connected CircuitPython device.  To deploy your project find the path of your `CIRCUITPY` UDB drive.  Then type:\n\n```\npiku deploy -d <path of your device>\n```\n\n***WARNING!!***  \nDeploying will remove other files from your device.  Piku attempts to check that the device is actually a CircuitPython device, and backup your old files, but you still need to be very careful.\n\nYou can also let Piku find your device by running deploy with no device argument:\n\n```\npiku deploy\n```\n\nAfter you have confirmed multiple times that you are deploying to the correct device you can also live on the wild side and skip the confirmation dialog using the `-y` command line argument.  Please be careful.\n\nIf changes have been made in your project code, the CircuitPython device should automatically detect and change files and reload.\n\n\n### Connecting to your Device\n\nYou can also connect to your CircuitPython device\'s serial port using Piku.  To do this just user the serial command from your Piku project directory:\n\n```\npiku serial\n```\n\nIf you are unable to connect, please confirm that you have the serial drivers for your device installed and you have permission to use the serial port (see installation instructions).  If you know the serial port, or Piku is connecting to the wront port you can also try specifying it directly via the `-s` command line flag.\n\nOnce connected you can exit by typing `ctrl-x`, enter the CircuitPython REPL by hitting `ctrl-c` and `ctrl-d` to exit the CircuitPython REPL.\n\n\n### Managing CircuitPython Modules/Libraries\n\nYou can easily download and add CircuitPython modules from the official Bundle or Community bundle using the command.  For example to download and add the `neopixel` module you would type:\n\n```\npiku add neopixel\n```\n\nThe specified module will be downloaded and added to your `lib` folder and your `pyproject.toml` file. You can also remove this module by typing:\n\n```\npiku remove neopixel\n```\n\nYou can also install modules you can manually downloaded, please check cli help for more information `piku add -h`.\n\nCurrently Piku just works for the Bundle 7, which was the most recent bundle when the tool was built.  But hopefully a full semver module index and supporting older versions and CircuitPython is something that can be done in the future.\n\n\n### A Complete Example with Adafruit Feather Sense\n\n##### Creating the Example Project\nAssuming you have successfully installed Piku, here is a complete example on how to create and deploy a Piku project to the [Adafruit Feather Sense](https://www.adafruit.com/product/4516) board using a Linux computer.\n\nFirst setup the board to user CircuitPython following the instructions found here:  \nhttps://learn.adafruit.com/adafruit-feather-sense/circuitpython-on-feather-sense\n\nAfter your board is setup and mounts as a `CIRCUITPY` USB drive create a new Piku project and enter the project directory.\n```\npiku create example\ncd example\n```\n\n##### Adding Main Example Program\nAfter you have created a project you will need to edit `project/code.py` which is the main file for your project (this is a CircuitPython convention). Open `project/code.py` and paste the following [Demo Code from AdaFruit](https://learn.adafruit.com/adafruit-feather-sense/circuitpython-sense-demo).\n\n```py\n# SPDX-FileCopyrightText: 2020 Kattni Rembor for Adafruit Industries\n#\n# SPDX-License-Identifier: MIT\n#\n"""Sensor demo for Adafruit Feather Sense. Prints data from each of the sensors."""\nimport time\nimport array\nimport math\nimport board\nimport audiobusio\nimport adafruit_apds9960.apds9960\nimport adafruit_bmp280\nimport adafruit_lis3mdl\nimport adafruit_lsm6ds.lsm6ds33\nimport adafruit_sht31d\n\ni2c = board.I2C()\n\napds9960 = adafruit_apds9960.apds9960.APDS9960(i2c)\nbmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)\nlis3mdl = adafruit_lis3mdl.LIS3MDL(i2c)\nlsm6ds33 = adafruit_lsm6ds.lsm6ds33.LSM6DS33(i2c)\nsht31d = adafruit_sht31d.SHT31D(i2c)\nmicrophone = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,\n                              sample_rate=16000, bit_depth=16)\n\ndef normalized_rms(values):\n    minbuf = int(sum(values) / len(values))\n    return int(math.sqrt(sum(float(sample - minbuf) *\n                             (sample - minbuf) for sample in values) / len(values)))\n\napds9960.enable_proximity = True\napds9960.enable_color = True\n\n# Set this to sea level pressure in hectoPascals at your location for accurate altitude reading.\nbmp280.sea_level_pressure = 1013.25\n\nwhile True:\n    samples = array.array(\'H\', [0] * 160)\n    microphone.record(samples, len(samples))\n\n    print("\\nFeather Sense Sensor Demo")\n    print("---------------------------------------------")\n    print("Proximity:", apds9960.proximity)\n    print("Red: {}, Green: {}, Blue: {}, Clear: {}".format(*apds9960.color_data))\n    print("Temperature: {:.1f} C".format(bmp280.temperature))\n    print("Barometric pressure:", bmp280.pressure)\n    print("Altitude: {:.1f} m".format(bmp280.altitude))\n    print("Magnetic: {:.3f} {:.3f} {:.3f} uTesla".format(*lis3mdl.magnetic))\n    print("Acceleration: {:.2f} {:.2f} {:.2f} m/s^2".format(*lsm6ds33.acceleration))\n    print("Gyro: {:.2f} {:.2f} {:.2f} dps".format(*lsm6ds33.gyro))\n    print("Humidity: {:.1f} %".format(sht31d.relative_humidity))\n    print("Sound level:", normalized_rms(samples))\n    time.sleep(0.3)\n```\n\n##### Installing Dependencies\nNext install the required libraries for the AdaFruit Feather Sense example:\n```\npiku add adafruit_apds9960\npiku add adafruit_bmp280\npiku add adafruit_bus_device\npiku add adafruit_lis3mdl\npiku add adafruit_lsm6ds\npiku add adafruit_register\npiku add adafruit_sht31d\npiku add neopixel\n```\n\nThese modules should now found to your project `lib` folder, and your `pyproject.toml` file.  Confirm this by listing the files in your `lib` directory using `ls project/lib`. The ls command should return something the following if all modules were installed properly:\n```\nadafruit_apds9960  adafruit_bmp280.mpy  adafruit_bus_device  adafruit_lis3mdl.mpy  adafruit_lsm6ds  adafruit_register  adafruit_sht31d.mpy  neopixel.mpy\n```\n\nYour pyproject.toml file should now look something like this:\n```\n[tool.piku]\nproject = "example"\npiku = "0.1.1"\ncircuitpython = "7"\n\n[tool.piku.dependencies]\nadafruit_apds9960 = "~7"\nadafruit_bmp280 = "~7"\nadafruit_bus_device = "~7"\nadafruit_lis3mdl = "~7"\nadafruit_lsm6ds = "~7"\nadafruit_register = "~7"\nadafruit_sht31d = "~7"\nneopixel = "~7"\n```\n\n##### Deploying to the Device\nNow make sure your device is mounted as a USB drive and find the device\'s mount point.  This should be something like `/media/username/CIRCUITPY/` or a drive letter on windows. ***Make note of this!***\n\nAfter your device is connected and mounted, you can deploy your code using the deploy command:\n```\npiku deploy -d <your device path here>\n```\n\nNext before deploying confirm that the device selected is the correct device. When Piku deploys it first attempts to validate its a CircuitPython device and then tries to backup the contents of the device in a temporary location. After validation and backup it loads your files onto the device and removes almost all other files\n\nYou can also forego the `-d <your device path here>` argument and let Piku attempt to find your device, but please confirm that you are deploying to the correct device so you don\'t lost any data.\n\n##### Connecting to the Serial Port\nAfter your code is deployed you can connect to the serial port to see your code in action. It make take a minute for the device to reload. To connect to the serial port run:\n\n```\npiku serial\n```\n\nPiku will attempt to connect to the first available serial port and reach your device, if you have more than one serial port you may need to specify which port via the command like arguments.  Hit `ctrl-x` to exit or `ctrl-c`/`ctrl-d` to enter/exit the CircuitPython REPL.\n\nThanks it! Happy hacking!\n\n\n# Contributing\n\nContributions are very welcome, my time to work on the project is limited.  Please post issues and pull requests on Github if you would like to help forward the project.\n\n### Future Work\n\nIt would be great to support older versions of CircuitPython and properly detect and download modules using semver.\n\nMacOS support and testing. I don\'t own a Mac so there are some missing elements for MacOS support.\n\nLoading board specific examples when using create.  It would be neat to index or support examples for boards, so when you create a project the dependencies and `code.py` file are already filled in with starter code.\n',
    'author': 'Mark Raleson',
    'author_email': 'markraleson@outlook.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/mraleson/piku.git',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'entry_points': entry_points,
    'python_requires': '>=3.8,<4.0',
}


setup(**setup_kwargs)
