diff --git a/.flake8 b/.flake8 index 732c12e..8f58749 100644 --- a/.flake8 +++ b/.flake8 @@ -1,7 +1,7 @@ [flake8] docstring_style=sphinx max-line-length = 127 -ignore = D400, Q000, S311, PLW, PLC, PLR +ignore = D400, Q000, S311, W503, PLW, PLC, PLR per-file-ignores = buildhat/__init__.py:F401 exclude = docs/conf.py, docs/sphinxcontrib/cmtinc-buildhat.py, docs/sphinx_selective_exclude/*.py diff --git a/buildhat/data/firmware.bin b/buildhat/data/firmware.bin index 64358ee..f6dcde3 100644 Binary files a/buildhat/data/firmware.bin and b/buildhat/data/firmware.bin differ diff --git a/buildhat/data/signature.bin b/buildhat/data/signature.bin index 27ef00d..8f495fa 100644 --- a/buildhat/data/signature.bin +++ b/buildhat/data/signature.bin @@ -1 +1 @@ -Q#E]]-.T~駶e[yEV}A5L}A$I!u9Nzw`l@eK;{E \ No newline at end of file +N.2wSmQ/IӍm )io\~IAz4ĘɅPw>\w LV \ No newline at end of file diff --git a/buildhat/data/version b/buildhat/data/version index e9bf96c..1f3109b 100644 --- a/buildhat/data/version +++ b/buildhat/data/version @@ -1 +1 @@ -1674818421 +1737564117 diff --git a/buildhat/devices.py b/buildhat/devices.py index 0db16b1..80dec80 100644 --- a/buildhat/devices.py +++ b/buildhat/devices.py @@ -72,7 +72,15 @@ def __init__(self, port): def _setup(**kwargs): if Device._instance: return - data = os.path.join(os.path.dirname(sys.modules["buildhat"].__file__), "data/") + if ( + os.path.isdir(os.path.join(os.getcwd(), "data/")) + and os.path.isfile(os.path.join(os.getcwd(), "data", "firmware.bin")) + and os.path.isfile(os.path.join(os.getcwd(), "data", "signature.bin")) + and os.path.isfile(os.path.join(os.getcwd(), "data", "version")) + ): + data = os.path.join(os.getcwd(), "data/") + else: + data = os.path.join(os.path.dirname(sys.modules["buildhat"].__file__), "data/") firm = os.path.join(data, "firmware.bin") sig = os.path.join(data, "signature.bin") ver = os.path.join(data, "version") diff --git a/buildhat/serinterface.py b/buildhat/serinterface.py index 77ee53e..89c9c92 100644 --- a/buildhat/serinterface.py +++ b/buildhat/serinterface.py @@ -378,7 +378,7 @@ def loop(self, cond, uselist, q, listevt): def runit(): with cond: cond.notify() - t = Timer(8.0, runit) + t = Timer(11.0, runit) t.start() if line[0] == "P" and (line[2] == "C" or line[2] == "M"): diff --git a/docs/buildhat/index.rst b/docs/buildhat/index.rst index 91b48b0..f4f7fc4 100644 --- a/docs/buildhat/index.rst +++ b/docs/buildhat/index.rst @@ -28,10 +28,51 @@ power supply. For best results, use the `official Raspberry Pi Build HAT power s .. _official Raspberry Pi Build HAT power supply: http://raspberrypi.com/products/build-hat-power-supply +It is now possible to use custom firmware with the library. To do this you can follow the steps below. + +.. code-block:: + :caption: Using custom firmware + + sudo apt install cmake python3 build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib + + git clone https://github.com/raspberrypi/pico-sdk.git --recursive + git clone https://github.com/raspberrypi/buildhat.git --recursive + + cd buildhat + export PICO_SDK_PATH="$(pwd)/../pico-sdk/" + make + + cd .. + mkdir test + cd test + mkdir data + + cp ../buildhat/firmware-pico/build/main.bin data/firmware.bin + cp ../buildhat/bhbl-pico/signature.bin data/signature.bin + cat ../buildhat/firmware-pico/version.h | sed 's/#define FWVERSION "//g; s/ .*//g' > data/version + +Then place your script, such as the following, within the test/ directory. + +.. code-block:: + :caption: Create test.py in test directory + + import time + from buildhat import Motor + + m = Motor('A') + m.start() + + time.sleep(5) + +Then use: ``python test.py`` in the test directory, to run your script with your custom firmware. + +Note if you want python to always reload the firmware from your **data/** directory each time +you run your script, simply write the value: -1 to **data/version**. + .. warning:: The API for the Build HAT is undergoing active development and is subject - to change. + to change. .. toctree:: :maxdepth: 2 diff --git a/test/color.py b/test/color.py index 688e23c..ba23ff2 100644 --- a/test/color.py +++ b/test/color.py @@ -34,7 +34,7 @@ def test_caching(self): """Test to make sure we're not reading cached data""" color = ColorSensor('A') color.avg_reads = 1 - color.interval = 1 + color.interval = 10 for _ in range(100): color.mode(2)