From a6e8867baf7f78bb1ceed6122e61ac44c43044ff Mon Sep 17 00:00:00 2001 From: Lidia Parrilla <75931652+lidiapb@users.noreply.github.com> Date: Mon, 12 Apr 2021 22:08:11 +0200 Subject: [PATCH 001/240] Enabled led test --- run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run.py b/run.py index f832555..62b69c8 100755 --- a/run.py +++ b/run.py @@ -75,8 +75,8 @@ def new_problem_cb(mb,holds_string): led_layout = LED_LAYOUT.get(args.led_layout) if args.led_layout is not None else None MOONBOARD = MoonBoard(args.driver_type, led_layout) - # run led led - #MOONBOARD.led_.clear()test() + # run led test + MOONBOARD.led_test() MOONBOARD.clear() # connect to dbus signal new problem From 44fa8198ae4a6dbef294e6359021f7e1b6e81fc8 Mon Sep 17 00:00:00 2001 From: Lidia Parrilla <75931652+lidiapb@users.noreply.github.com> Date: Wed, 14 Apr 2021 18:32:28 +0200 Subject: [PATCH 002/240] Corrected led mapping for J1 --- led/led_mapping.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/led_mapping.json b/led/led_mapping.json index 1e5edca..a6898cb 100644 --- a/led/led_mapping.json +++ b/led/led_mapping.json @@ -1 +1 @@ -{"A1": 0, "A2": 1, "A3": 2, "A4": 3, "A5": 4, "A6": 5, "A7": 6, "A8": 7, "A9": 8, "A10": 9, "A11": 10, "A12": 11, "A13": 12, "A14": 13, "A15": 14, "A16": 15, "A17": 16, "A18": 17, "B18": 18, "B17": 19, "B16": 20, "B15": 21, "B14": 22, "B13": 23, "B12": 24, "B11": 25, "B10": 26, "B9": 27, "B8": 28, "B7": 29, "B6": 30, "B5": 31, "B4": 32, "B3": 33, "B2": 34, "B1": 35, "C1": 36, "C2": 37, "C3": 38, "C4": 39, "C5": 40, "C6": 41, "C7": 42, "C8": 43, "C9": 44, "C10": 45, "C11": 46, "C12": 47, "C13": 48, "C14": 49, "C15": 50, "C16": 51, "C17": 52, "C18": 53, "D18": 54, "D17": 55, "D16": 56, "D15": 57, "D14": 58, "D13": 59, "D12": 60, "D11": 61, "D10": 62, "D9": 63, "D8": 64, "D7": 65, "D6": 66, "D5": 67, "D4": 68, "D3": 69, "D2": 70, "D1": 71, "E1": 72, "E2": 73, "E3": 74, "E4": 75, "E5": 76, "E6": 77, "E7": 78, "E8": 79, "E9": 80, "E10": 81, "E11": 82, "E12": 83, "E13": 84, "E14": 85, "E15": 86, "E16": 87, "E17": 88, "E18": 89, "F18": 90, "F17": 91, "F16": 92, "F15": 93, "F14": 94, "F13": 95, "F12": 96, "F11": 97, "F10": 98, "F9": 99, "F8": 100, "F7": 101, "F6": 102, "F5": 103, "F4": 104, "F3": 105, "F2": 106, "F1": 107, "G1": 108, "G2": 109, "G3": 110, "G4": 111, "G5": 112, "G6": 113, "G7": 114, "G8": 115, "G9": 116, "G10": 117, "G11": 118, "G12": 119, "G13": 120, "G14": 121, "G15": 122, "G16": 123, "G17": 124, "G18": 125, "H18": 126, "H17": 127, "H16": 128, "H15": 129, "H14": 130, "H13": 131, "H12": 132, "H11": 133, "H10": 134, "H9": 135, "H8": 136, "H7": 137, "H6": 138, "H5": 139, "H4": 140, "H3": 141, "H2": 142, "H1": 143, "I1": 144, "I2": 145, "I3": 146, "I4": 147, "I5": 148, "I6": 149, "I7": 150, "I8": 151, "I9": 152, "I10": 153, "I11": 154, "I12": 155, "I13": 156, "I14": 157, "I15": 158, "I16": 159, "I17": 160, "I18": 161, "J18": 162, "J17": 163, "J16": 164, "J15": 165, "J14": 166, "J13": 167, "J12": 168, "J11": 169, "J10": 170, "J9": 171, "J8": 172, "J7": 173, "J6": 174, "J5": 175, "J4": 176, "J3": 177, "J2": 178, "J1": 178, "K1": 180, "K2": 181, "K3": 182, "K4": 183, "K5": 184, "K6": 185, "K7": 186, "K8": 187, "K9": 188, "K10": 189, "K11": 190, "K12": 191, "K13": 192, "K14": 193, "K15": 194, "K16": 195, "K17": 196, "K18": 197} +{"A1": 0, "A2": 1, "A3": 2, "A4": 3, "A5": 4, "A6": 5, "A7": 6, "A8": 7, "A9": 8, "A10": 9, "A11": 10, "A12": 11, "A13": 12, "A14": 13, "A15": 14, "A16": 15, "A17": 16, "A18": 17, "B18": 18, "B17": 19, "B16": 20, "B15": 21, "B14": 22, "B13": 23, "B12": 24, "B11": 25, "B10": 26, "B9": 27, "B8": 28, "B7": 29, "B6": 30, "B5": 31, "B4": 32, "B3": 33, "B2": 34, "B1": 35, "C1": 36, "C2": 37, "C3": 38, "C4": 39, "C5": 40, "C6": 41, "C7": 42, "C8": 43, "C9": 44, "C10": 45, "C11": 46, "C12": 47, "C13": 48, "C14": 49, "C15": 50, "C16": 51, "C17": 52, "C18": 53, "D18": 54, "D17": 55, "D16": 56, "D15": 57, "D14": 58, "D13": 59, "D12": 60, "D11": 61, "D10": 62, "D9": 63, "D8": 64, "D7": 65, "D6": 66, "D5": 67, "D4": 68, "D3": 69, "D2": 70, "D1": 71, "E1": 72, "E2": 73, "E3": 74, "E4": 75, "E5": 76, "E6": 77, "E7": 78, "E8": 79, "E9": 80, "E10": 81, "E11": 82, "E12": 83, "E13": 84, "E14": 85, "E15": 86, "E16": 87, "E17": 88, "E18": 89, "F18": 90, "F17": 91, "F16": 92, "F15": 93, "F14": 94, "F13": 95, "F12": 96, "F11": 97, "F10": 98, "F9": 99, "F8": 100, "F7": 101, "F6": 102, "F5": 103, "F4": 104, "F3": 105, "F2": 106, "F1": 107, "G1": 108, "G2": 109, "G3": 110, "G4": 111, "G5": 112, "G6": 113, "G7": 114, "G8": 115, "G9": 116, "G10": 117, "G11": 118, "G12": 119, "G13": 120, "G14": 121, "G15": 122, "G16": 123, "G17": 124, "G18": 125, "H18": 126, "H17": 127, "H16": 128, "H15": 129, "H14": 130, "H13": 131, "H12": 132, "H11": 133, "H10": 134, "H9": 135, "H8": 136, "H7": 137, "H6": 138, "H5": 139, "H4": 140, "H3": 141, "H2": 142, "H1": 143, "I1": 144, "I2": 145, "I3": 146, "I4": 147, "I5": 148, "I6": 149, "I7": 150, "I8": 151, "I9": 152, "I10": 153, "I11": 154, "I12": 155, "I13": 156, "I14": 157, "I15": 158, "I16": 159, "I17": 160, "I18": 161, "J18": 162, "J17": 163, "J16": 164, "J15": 165, "J14": 166, "J13": 167, "J12": 168, "J11": 169, "J10": 170, "J9": 171, "J8": 172, "J7": 173, "J6": 174, "J5": 175, "J4": 176, "J3": 177, "J2": 178, "J1": 179, "K1": 180, "K2": 181, "K3": 182, "K4": 183, "K5": 184, "K6": 185, "K7": 186, "K8": 187, "K9": 188, "K10": 189, "K11": 190, "K12": 191, "K13": 192, "K14": 193, "K15": 194, "K16": 195, "K17": 196, "K18": 197} From 1e728683fb0fbbc4cede7bb814145ecad2471948 Mon Sep 17 00:00:00 2001 From: Lidia Parrilla Date: Sat, 19 Jun 2021 10:25:23 +0100 Subject: [PATCH 003/240] fix(BLE): Disabled battery module from bluez to fix issue with iPhone BLE #4 --- install/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install/install.sh b/install/install.sh index 179bd20..05a2cc0 100755 --- a/install/install.sh +++ b/install/install.sh @@ -26,6 +26,8 @@ pip3 install -r install/requirements.txt sudo pip3 install -r install/requirements.txt # pip3 uninstall -y -r install/requirements.txt # uninstall +echo "Applying patch to bluez for iPhone" +sudo sed -i '/ExecStart/ c ExecStart=/usr/lib/bluetooth/bluetoothd -P battery' /usr/lib/systemd/system/bluetooth.service echo "Install service" # FIXME cd /home/pi/moonboard/services From b545bf67f0d24c087a93660b18b84de90c54da5d Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Sun, 1 Aug 2021 11:33:33 +0200 Subject: [PATCH 004/240] cleanup --- .github/workflows/codeql-analysis.yml | 71 --------------------------- 1 file changed, 71 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index f1425c9..0000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,71 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '28 3 * * 1' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'python' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 From c8e54594b6cf57fade0b80be4e2a7972c5d25e6c Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Sun, 1 Aug 2021 13:48:39 +0200 Subject: [PATCH 005/240] install docker on raspi --- doc/OVERVIEW-SOFTWARE.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/OVERVIEW-SOFTWARE.md b/doc/OVERVIEW-SOFTWARE.md index d8bf257..65d6481 100755 --- a/doc/OVERVIEW-SOFTWARE.md +++ b/doc/OVERVIEW-SOFTWARE.md @@ -30,3 +30,7 @@ To stop / restart the moonboard services (i.e. for debugging) use systemctl: *** FIXME *** The LED driver scripts are located in the folder LED. moonboard.py is invoked by the BLE service. Alternatively you can run moonboard.py directly, i.e. for LED strip installation or hold setup. + + +# Docker version ++ Install docker `curl -fsSL https://get.docker.com -o get-docker.sh` and `sudo sh get-docker.sh` \ No newline at end of file From c905977b06d8d2325edf5660f9ffb4c10cd91e15 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Sun, 1 Aug 2021 14:00:22 +0200 Subject: [PATCH 006/240] Experimenting with docker --- ble/Dockerfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ble/Dockerfile diff --git a/ble/Dockerfile b/ble/Dockerfile new file mode 100644 index 0000000..ae02ed5 --- /dev/null +++ b/ble/Dockerfile @@ -0,0 +1,13 @@ +FROM debian:latest + +RUN apt-get -y update && apt-get upgrade +RUN apt-get -y install git vim python3-pip gcc make build-essential libatlas-base-dev python-dev swig scons + +WORKDIR /ble +ADD . /ble/ + +#https://georgik.rocks/how-to-start-d-bus-in-docker-container/ +#dbus-uuidgen > /var/lib/dbus/machine-id +#mkdir -p /var/run/dbus +#dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address +#python3 moonboard_BLE_service.py \ No newline at end of file From 0c69a6e180515c614858e30e1b32ad96281a361e Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Sun, 1 Aug 2021 14:12:42 +0200 Subject: [PATCH 007/240] wip driver --- led/moonboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/moonboard.py b/led/moonboard.py index 86100b4..d4b318b 100755 --- a/led/moonboard.py +++ b/led/moonboard.py @@ -79,7 +79,7 @@ class MoonBoard: def __init__(self, driver_type, led_layout=None, brightness=DEFAULT_BRIGHTNESS): try: if driver_type == "PiWS281x": - driver = PiWS281X(self.NUM_PIXELS) + driver = PiWS281X(self.NUM_PIXELS, dev='/dev/spidev0.1',spi_interface= SPI_INTERFACES.PERIPHERY,spi_speed=1) elif driver_type == "WS2801": driver = WS2801(self.NUM_PIXELS, dev='/dev/spidev0.1',spi_interface= SPI_INTERFACES.PERIPHERY,spi_speed=1) elif driver_type == "SimPixel": From 33baa72ab4654a6674ef19df93f6fda767db0517 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Sun, 1 Aug 2021 14:14:12 +0200 Subject: [PATCH 008/240] spi does not work --- led/moonboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/moonboard.py b/led/moonboard.py index d4b318b..86100b4 100755 --- a/led/moonboard.py +++ b/led/moonboard.py @@ -79,7 +79,7 @@ class MoonBoard: def __init__(self, driver_type, led_layout=None, brightness=DEFAULT_BRIGHTNESS): try: if driver_type == "PiWS281x": - driver = PiWS281X(self.NUM_PIXELS, dev='/dev/spidev0.1',spi_interface= SPI_INTERFACES.PERIPHERY,spi_speed=1) + driver = PiWS281X(self.NUM_PIXELS) elif driver_type == "WS2801": driver = WS2801(self.NUM_PIXELS, dev='/dev/spidev0.1',spi_interface= SPI_INTERFACES.PERIPHERY,spi_speed=1) elif driver_type == "SimPixel": From a98eaa448d488739bf5862479d02598d0f8987ca Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 19:39:41 +0100 Subject: [PATCH 009/240] wip doc --- CHANGELOG.md | 3 + README.md | 5 +- TESTING.md | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 TESTING.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..01c97ef --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +- v0.28 merged moonboard mini protocol +- v0.27 merged bt fix test +- v0.23 running in gz setup \ No newline at end of file diff --git a/README.md b/README.md index 7a821f6..d788141 100755 --- a/README.md +++ b/README.md @@ -44,7 +44,4 @@ Free standing foldaway version of moonboard. Moonboard with 150mm kicker and tot ## Tested setups - Raspi W Zero with iPhone 5, 8, X, 11 (iOS >= 14) -# Versions -- v0.28 merged moonboard mini protocol -- v0.27 merged bt fix test -- v0.23 running in gz setup + diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000..8db7843 --- /dev/null +++ b/TESTING.md @@ -0,0 +1,197 @@ +# Bluetooth monitoring + +ssh -lpi raspi-moonboard sudo btmon + +## Example +sudo btmon +Bluetooth monitor ver 5.50 += Note: Linux version 5.10.63+ (armv6l) 0.749830 += Note: Bluetooth subsystem version 2.22 0.749846 += New Index: B8:27:EB:78:4B:E9 (Primary,UART,hci0) [hci0] 0.749853 += Open Index: B8:27:EB:78:4B:E9 [hci0] 0.749858 += Index Info: B8:27:EB:78:4B:E9 (Broadcom Corporation) [hci0] 0.749862 +@ MGMT Open: btmon (privileged) version 1.18 {0x0002} 0.749868 +@ MGMT Open: bluetoothd (privileged) version 1.18 {0x0001} 0.749873 +@ MGMT Open: btmon (privileged) version 1.18 {0x0003} 0.750001 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #1 [hci0] 3.977273 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c23533138332c533133392c5039392c5038372c +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #2 [hci0] 3.988939 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #3 [hci0] 4.037460 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 5038342c5037382c50332c5032352c503136342c +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #4 [hci0] 4.048985 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 12 #5 [hci0] 4.097163 + ATT: Write Request (0x12) len 7 + Handle: 0x000c + Data: 4531363223 +> HCI Event: Number of Completed Packets (0x13) plen 5 #6 [hci0] 4.097906 + Num handles: 1 + Handle: 64 + Count: 2 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #7 [hci0] 4.107769 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #8 [hci0] 4.351125 + Num handles: 1 + Handle: 64 + Count: 1 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #9 [hci0] 5.777284 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c235333322c5036312c5035372c503130302c45 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #10 [hci0] 5.784852 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 10 #11 [hci0] 5.837187 + ATT: Write Request (0x12) len 5 + Handle: 0x000c + Data: 353423 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #12 [hci0] 5.847927 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #13 [hci0] 5.897103 + Num handles: 1 + Handle: 64 + Count: 2 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #14 [hci0] 6.917365 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c235333342c5037392c5036302c5033302c5031 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #15 [hci0] 6.928987 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 25 #16 [hci0] 6.977342 + ATT: Write Request (0x12) len 20 + Handle: 0x000c + Data: 38372c503135362c503132372c4531393723 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #17 [hci0] 6.988511 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #18 [hci0] 7.037108 + Num handles: 1 + Handle: 64 + Count: 2 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #19 [hci0] 8.327395 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c2353332c533130392c5036342c5036312c5031 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #20 [hci0] 8.338614 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 19 #21 [hci0] 8.387308 + ATT: Write Request (0x12) len 14 + Handle: 0x000c + Data: 37302c503136362c45393023 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #22 [hci0] 8.396136 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #23 [hci0] 8.447137 + Num handles: 1 + Handle: 64 + Count: 2 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #24 [hci0] 9.227406 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c2353342c5333392c5039382c5032382c503137 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #25 [hci0] 9.239194 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #26 [hci0] 9.287598 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 362c503136392c503136342c503133302c503131 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #27 [hci0] 9.297212 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #28 [hci0] 9.347156 + Num handles: 1 + Handle: 64 + Count: 2 +> ACL Data RX: Handle 64 flags 0x02 dlen 13 #29 [hci0] 9.407244 + ATT: Write Request (0x12) len 8 + Handle: 0x000c + Data: 352c45393023 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #30 [hci0] 9.418438 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #31 [hci0] 9.601239 + Num handles: 1 + Handle: 64 + Count: 1 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #32 [hci0] 10.937405 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c23533138322c533137362c503139352c503138 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #33 [hci0] 10.945771 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #34 [hci0] 10.997617 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 372c503135352c503133352c503133302c453132 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #35 [hci0] 11.005984 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #36 [hci0] 11.087199 + Num handles: 1 + Handle: 64 + Count: 2 +> ACL Data RX: Handle 64 flags 0x02 dlen 9 #37 [hci0] 11.117202 + ATT: Write Request (0x12) len 4 + Handle: 0x000c + Data: 3623 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #38 [hci0] 11.124590 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #39 [hci0] 11.351131 + Num handles: 1 + Handle: 64 + Count: 1 +> HCI Event: LE Meta Event (0x3e) plen 10 #40 [hci0] 12.002693 + LE Connection Update Complete (0x03) + Status: Success (0x00) + Handle: 64 + Connection interval: 30.00 msec (0x0018) + Connection latency: 0 (0x0000) + Supervision timeout: 720 msec (0x0048) +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #41 [hci0] 13.892482 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c235333392c533131332c5039312c5036342c50 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #42 [hci0] 13.905726 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 19 #43 [hci0] 13.982417 + ATT: Write Request (0x12) len 14 + Handle: 0x000c + Data: 35382c503133322c45313823 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #44 [hci0] 13.993446 + ATT: Write Response (0x13) len 0 + + +# DBUS Monitoring +ssh -lpi raspi-moonboard sudo dbus-monitor --system|less + +## Example + +signal time=1638195833.267233 sender=org.freedesktop.DBus -> destination=:1.105 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired + string ":1.105" +signal time=1638195833.270379 sender=org.freedesktop.DBus -> destination=:1.105 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost + string ":1.105" +method call time=1638195834.405055 sender=:1.13 -> destination=:1.34 serial=191 path=/com/moonboard/service0/char1; interface=org.bluez.GattCharacteristic1; member=WriteValue + array of bytes "l#S3,S105,P60,P28,P1" + array [ + dict entry( + string "device" + variant object path "/org/bluez/hci0/dev_F0_A3_5A_A4_70_7F" + ) + dict entry( + string "link" + variant string "LE" + ) + ] +method return time=1638195834.417610 sender=:1.34 -> destination=:1.13 serial=108 reply_serial=191 +method call time=1638195834.463586 sender=:1.13 -> destination=:1.34 serial=192 path=/com/moonboard/service0/char1; interface=org.bluez.GattCharacteristic1; member=WriteValue + array of bytes "4,E90#" + array [ + dict entry( + string "device" + variant object path "/org/bluez/hci0/dev_F0_A3_5A_A4_70_7F" + ) + dict entry( + string "link" + variant string "LE" + ) + ] +method return time=1638195834.471207 sender=:1.34 -> destination=:1.13 serial=109 reply_serial=192 \ No newline at end of file From 5788a76a03e733e1e92aef37674308791e149359 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 19:40:55 +0100 Subject: [PATCH 010/240] command --- TESTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TESTING.md b/TESTING.md index 8db7843..3f625f6 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,6 +1,6 @@ # Bluetooth monitoring -ssh -lpi raspi-moonboard sudo btmon +```ssh -lpi raspi-moonboard sudo btmon``` ## Example sudo btmon @@ -161,7 +161,7 @@ Bluetooth monitor ver 5.50 # DBUS Monitoring -ssh -lpi raspi-moonboard sudo dbus-monitor --system|less +```ssh -lpi raspi-moonboard sudo dbus-monitor --system|less``` ## Example From eccca9806b00d86f44abb2e78d971378cd56c023 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Mon, 29 Nov 2021 20:01:50 +0100 Subject: [PATCH 011/240] cleanup --- TESTING.md | 191 -------------------------------- testing/BLE-TESTING_OUTPUTS.md | 197 +++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+), 191 deletions(-) create mode 100644 testing/BLE-TESTING_OUTPUTS.md diff --git a/TESTING.md b/TESTING.md index 3f625f6..1523d72 100644 --- a/TESTING.md +++ b/TESTING.md @@ -2,196 +2,5 @@ ```ssh -lpi raspi-moonboard sudo btmon``` -## Example -sudo btmon -Bluetooth monitor ver 5.50 -= Note: Linux version 5.10.63+ (armv6l) 0.749830 -= Note: Bluetooth subsystem version 2.22 0.749846 -= New Index: B8:27:EB:78:4B:E9 (Primary,UART,hci0) [hci0] 0.749853 -= Open Index: B8:27:EB:78:4B:E9 [hci0] 0.749858 -= Index Info: B8:27:EB:78:4B:E9 (Broadcom Corporation) [hci0] 0.749862 -@ MGMT Open: btmon (privileged) version 1.18 {0x0002} 0.749868 -@ MGMT Open: bluetoothd (privileged) version 1.18 {0x0001} 0.749873 -@ MGMT Open: btmon (privileged) version 1.18 {0x0003} 0.750001 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #1 [hci0] 3.977273 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c23533138332c533133392c5039392c5038372c -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #2 [hci0] 3.988939 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #3 [hci0] 4.037460 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 5038342c5037382c50332c5032352c503136342c -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #4 [hci0] 4.048985 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 12 #5 [hci0] 4.097163 - ATT: Write Request (0x12) len 7 - Handle: 0x000c - Data: 4531363223 -> HCI Event: Number of Completed Packets (0x13) plen 5 #6 [hci0] 4.097906 - Num handles: 1 - Handle: 64 - Count: 2 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #7 [hci0] 4.107769 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #8 [hci0] 4.351125 - Num handles: 1 - Handle: 64 - Count: 1 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #9 [hci0] 5.777284 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c235333322c5036312c5035372c503130302c45 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #10 [hci0] 5.784852 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 10 #11 [hci0] 5.837187 - ATT: Write Request (0x12) len 5 - Handle: 0x000c - Data: 353423 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #12 [hci0] 5.847927 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #13 [hci0] 5.897103 - Num handles: 1 - Handle: 64 - Count: 2 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #14 [hci0] 6.917365 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c235333342c5037392c5036302c5033302c5031 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #15 [hci0] 6.928987 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 25 #16 [hci0] 6.977342 - ATT: Write Request (0x12) len 20 - Handle: 0x000c - Data: 38372c503135362c503132372c4531393723 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #17 [hci0] 6.988511 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #18 [hci0] 7.037108 - Num handles: 1 - Handle: 64 - Count: 2 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #19 [hci0] 8.327395 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c2353332c533130392c5036342c5036312c5031 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #20 [hci0] 8.338614 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 19 #21 [hci0] 8.387308 - ATT: Write Request (0x12) len 14 - Handle: 0x000c - Data: 37302c503136362c45393023 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #22 [hci0] 8.396136 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #23 [hci0] 8.447137 - Num handles: 1 - Handle: 64 - Count: 2 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #24 [hci0] 9.227406 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c2353342c5333392c5039382c5032382c503137 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #25 [hci0] 9.239194 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #26 [hci0] 9.287598 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 362c503136392c503136342c503133302c503131 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #27 [hci0] 9.297212 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #28 [hci0] 9.347156 - Num handles: 1 - Handle: 64 - Count: 2 -> ACL Data RX: Handle 64 flags 0x02 dlen 13 #29 [hci0] 9.407244 - ATT: Write Request (0x12) len 8 - Handle: 0x000c - Data: 352c45393023 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #30 [hci0] 9.418438 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #31 [hci0] 9.601239 - Num handles: 1 - Handle: 64 - Count: 1 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #32 [hci0] 10.937405 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c23533138322c533137362c503139352c503138 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #33 [hci0] 10.945771 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #34 [hci0] 10.997617 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 372c503135352c503133352c503133302c453132 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #35 [hci0] 11.005984 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #36 [hci0] 11.087199 - Num handles: 1 - Handle: 64 - Count: 2 -> ACL Data RX: Handle 64 flags 0x02 dlen 9 #37 [hci0] 11.117202 - ATT: Write Request (0x12) len 4 - Handle: 0x000c - Data: 3623 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #38 [hci0] 11.124590 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #39 [hci0] 11.351131 - Num handles: 1 - Handle: 64 - Count: 1 -> HCI Event: LE Meta Event (0x3e) plen 10 #40 [hci0] 12.002693 - LE Connection Update Complete (0x03) - Status: Success (0x00) - Handle: 64 - Connection interval: 30.00 msec (0x0018) - Connection latency: 0 (0x0000) - Supervision timeout: 720 msec (0x0048) -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #41 [hci0] 13.892482 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c235333392c533131332c5039312c5036342c50 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #42 [hci0] 13.905726 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 19 #43 [hci0] 13.982417 - ATT: Write Request (0x12) len 14 - Handle: 0x000c - Data: 35382c503133322c45313823 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #44 [hci0] 13.993446 - ATT: Write Response (0x13) len 0 - - # DBUS Monitoring ```ssh -lpi raspi-moonboard sudo dbus-monitor --system|less``` - -## Example - -signal time=1638195833.267233 sender=org.freedesktop.DBus -> destination=:1.105 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired - string ":1.105" -signal time=1638195833.270379 sender=org.freedesktop.DBus -> destination=:1.105 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost - string ":1.105" -method call time=1638195834.405055 sender=:1.13 -> destination=:1.34 serial=191 path=/com/moonboard/service0/char1; interface=org.bluez.GattCharacteristic1; member=WriteValue - array of bytes "l#S3,S105,P60,P28,P1" - array [ - dict entry( - string "device" - variant object path "/org/bluez/hci0/dev_F0_A3_5A_A4_70_7F" - ) - dict entry( - string "link" - variant string "LE" - ) - ] -method return time=1638195834.417610 sender=:1.34 -> destination=:1.13 serial=108 reply_serial=191 -method call time=1638195834.463586 sender=:1.13 -> destination=:1.34 serial=192 path=/com/moonboard/service0/char1; interface=org.bluez.GattCharacteristic1; member=WriteValue - array of bytes "4,E90#" - array [ - dict entry( - string "device" - variant object path "/org/bluez/hci0/dev_F0_A3_5A_A4_70_7F" - ) - dict entry( - string "link" - variant string "LE" - ) - ] -method return time=1638195834.471207 sender=:1.34 -> destination=:1.13 serial=109 reply_serial=192 \ No newline at end of file diff --git a/testing/BLE-TESTING_OUTPUTS.md b/testing/BLE-TESTING_OUTPUTS.md new file mode 100644 index 0000000..3f625f6 --- /dev/null +++ b/testing/BLE-TESTING_OUTPUTS.md @@ -0,0 +1,197 @@ +# Bluetooth monitoring + +```ssh -lpi raspi-moonboard sudo btmon``` + +## Example +sudo btmon +Bluetooth monitor ver 5.50 += Note: Linux version 5.10.63+ (armv6l) 0.749830 += Note: Bluetooth subsystem version 2.22 0.749846 += New Index: B8:27:EB:78:4B:E9 (Primary,UART,hci0) [hci0] 0.749853 += Open Index: B8:27:EB:78:4B:E9 [hci0] 0.749858 += Index Info: B8:27:EB:78:4B:E9 (Broadcom Corporation) [hci0] 0.749862 +@ MGMT Open: btmon (privileged) version 1.18 {0x0002} 0.749868 +@ MGMT Open: bluetoothd (privileged) version 1.18 {0x0001} 0.749873 +@ MGMT Open: btmon (privileged) version 1.18 {0x0003} 0.750001 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #1 [hci0] 3.977273 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c23533138332c533133392c5039392c5038372c +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #2 [hci0] 3.988939 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #3 [hci0] 4.037460 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 5038342c5037382c50332c5032352c503136342c +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #4 [hci0] 4.048985 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 12 #5 [hci0] 4.097163 + ATT: Write Request (0x12) len 7 + Handle: 0x000c + Data: 4531363223 +> HCI Event: Number of Completed Packets (0x13) plen 5 #6 [hci0] 4.097906 + Num handles: 1 + Handle: 64 + Count: 2 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #7 [hci0] 4.107769 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #8 [hci0] 4.351125 + Num handles: 1 + Handle: 64 + Count: 1 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #9 [hci0] 5.777284 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c235333322c5036312c5035372c503130302c45 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #10 [hci0] 5.784852 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 10 #11 [hci0] 5.837187 + ATT: Write Request (0x12) len 5 + Handle: 0x000c + Data: 353423 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #12 [hci0] 5.847927 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #13 [hci0] 5.897103 + Num handles: 1 + Handle: 64 + Count: 2 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #14 [hci0] 6.917365 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c235333342c5037392c5036302c5033302c5031 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #15 [hci0] 6.928987 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 25 #16 [hci0] 6.977342 + ATT: Write Request (0x12) len 20 + Handle: 0x000c + Data: 38372c503135362c503132372c4531393723 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #17 [hci0] 6.988511 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #18 [hci0] 7.037108 + Num handles: 1 + Handle: 64 + Count: 2 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #19 [hci0] 8.327395 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c2353332c533130392c5036342c5036312c5031 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #20 [hci0] 8.338614 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 19 #21 [hci0] 8.387308 + ATT: Write Request (0x12) len 14 + Handle: 0x000c + Data: 37302c503136362c45393023 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #22 [hci0] 8.396136 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #23 [hci0] 8.447137 + Num handles: 1 + Handle: 64 + Count: 2 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #24 [hci0] 9.227406 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c2353342c5333392c5039382c5032382c503137 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #25 [hci0] 9.239194 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #26 [hci0] 9.287598 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 362c503136392c503136342c503133302c503131 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #27 [hci0] 9.297212 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #28 [hci0] 9.347156 + Num handles: 1 + Handle: 64 + Count: 2 +> ACL Data RX: Handle 64 flags 0x02 dlen 13 #29 [hci0] 9.407244 + ATT: Write Request (0x12) len 8 + Handle: 0x000c + Data: 352c45393023 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #30 [hci0] 9.418438 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #31 [hci0] 9.601239 + Num handles: 1 + Handle: 64 + Count: 1 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #32 [hci0] 10.937405 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c23533138322c533137362c503139352c503138 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #33 [hci0] 10.945771 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #34 [hci0] 10.997617 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 372c503135352c503133352c503133302c453132 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #35 [hci0] 11.005984 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #36 [hci0] 11.087199 + Num handles: 1 + Handle: 64 + Count: 2 +> ACL Data RX: Handle 64 flags 0x02 dlen 9 #37 [hci0] 11.117202 + ATT: Write Request (0x12) len 4 + Handle: 0x000c + Data: 3623 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #38 [hci0] 11.124590 + ATT: Write Response (0x13) len 0 +> HCI Event: Number of Completed Packets (0x13) plen 5 #39 [hci0] 11.351131 + Num handles: 1 + Handle: 64 + Count: 1 +> HCI Event: LE Meta Event (0x3e) plen 10 #40 [hci0] 12.002693 + LE Connection Update Complete (0x03) + Status: Success (0x00) + Handle: 64 + Connection interval: 30.00 msec (0x0018) + Connection latency: 0 (0x0000) + Supervision timeout: 720 msec (0x0048) +> ACL Data RX: Handle 64 flags 0x02 dlen 27 #41 [hci0] 13.892482 + ATT: Write Request (0x12) len 22 + Handle: 0x000c + Data: 6c235333392c533131332c5039312c5036342c50 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #42 [hci0] 13.905726 + ATT: Write Response (0x13) len 0 +> ACL Data RX: Handle 64 flags 0x02 dlen 19 #43 [hci0] 13.982417 + ATT: Write Request (0x12) len 14 + Handle: 0x000c + Data: 35382c503133322c45313823 +< ACL Data TX: Handle 64 flags 0x00 dlen 5 #44 [hci0] 13.993446 + ATT: Write Response (0x13) len 0 + + +# DBUS Monitoring +```ssh -lpi raspi-moonboard sudo dbus-monitor --system|less``` + +## Example + +signal time=1638195833.267233 sender=org.freedesktop.DBus -> destination=:1.105 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired + string ":1.105" +signal time=1638195833.270379 sender=org.freedesktop.DBus -> destination=:1.105 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost + string ":1.105" +method call time=1638195834.405055 sender=:1.13 -> destination=:1.34 serial=191 path=/com/moonboard/service0/char1; interface=org.bluez.GattCharacteristic1; member=WriteValue + array of bytes "l#S3,S105,P60,P28,P1" + array [ + dict entry( + string "device" + variant object path "/org/bluez/hci0/dev_F0_A3_5A_A4_70_7F" + ) + dict entry( + string "link" + variant string "LE" + ) + ] +method return time=1638195834.417610 sender=:1.34 -> destination=:1.13 serial=108 reply_serial=191 +method call time=1638195834.463586 sender=:1.13 -> destination=:1.34 serial=192 path=/com/moonboard/service0/char1; interface=org.bluez.GattCharacteristic1; member=WriteValue + array of bytes "4,E90#" + array [ + dict entry( + string "device" + variant object path "/org/bluez/hci0/dev_F0_A3_5A_A4_70_7F" + ) + dict entry( + string "link" + variant string "LE" + ) + ] +method return time=1638195834.471207 sender=:1.34 -> destination=:1.13 serial=109 reply_serial=192 \ No newline at end of file From fc8938bbd839c98ca37e4b05cec7d48baa267040 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Mon, 29 Nov 2021 20:05:12 +0100 Subject: [PATCH 012/240] format --- TESTING.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/TESTING.md b/TESTING.md index 1523d72..930777c 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,6 +1,10 @@ # Bluetooth monitoring -```ssh -lpi raspi-moonboard sudo btmon``` +``` +ssh -lpi raspi-moonboard sudo btmon +``` # DBUS Monitoring -```ssh -lpi raspi-moonboard sudo dbus-monitor --system|less``` +``` +ssh -lpi raspi-moonboard sudo dbus-monitor --system|less +``` From 03a83eb4daa829e061b86a33ac3dd17ad390ce06 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Mon, 29 Nov 2021 20:19:13 +0100 Subject: [PATCH 013/240] logging --- ble/com.moonboard.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble/com.moonboard.service b/ble/com.moonboard.service index c2e5427..39662a1 100755 --- a/ble/com.moonboard.service +++ b/ble/com.moonboard.service @@ -6,7 +6,7 @@ SystemdService=dbus-org.com.moonbooard.service [Service] Type=dbus BusName=com.moonboard -ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_BLE_service.py +ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_BLE_service.py >> /var/log/moonboard_ble User=root [Install] From 60b6ce5b8a00070ac2e2b1b2d13dc8b370b55835 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Mon, 29 Nov 2021 20:22:27 +0100 Subject: [PATCH 014/240] no logging --- ble/com.moonboard.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble/com.moonboard.service b/ble/com.moonboard.service index 39662a1..04f5667 100755 --- a/ble/com.moonboard.service +++ b/ble/com.moonboard.service @@ -6,7 +6,7 @@ SystemdService=dbus-org.com.moonbooard.service [Service] Type=dbus BusName=com.moonboard -ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_BLE_service.py >> /var/log/moonboard_ble +ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_BLE_service.py User=root [Install] From 73681467801bb65c5d7e9979c76564eb83f033e6 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 20:36:50 +0100 Subject: [PATCH 015/240] logging services --- ble/com.moonboard.service | 6 ++++-- services/moonboard-install.service | 2 ++ services/moonboard.service | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ble/com.moonboard.service b/ble/com.moonboard.service index 39662a1..b5e152a 100755 --- a/ble/com.moonboard.service +++ b/ble/com.moonboard.service @@ -1,13 +1,15 @@ [Unit] -Description=Moonboard DBUS Service +Description=Moonboard BLE DBUS Service After=multi-user.target SystemdService=dbus-org.com.moonbooard.service [Service] Type=dbus BusName=com.moonboard -ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_BLE_service.py >> /var/log/moonboard_ble +ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_BLE_service.py User=root +StandardOutput=file:/var/log/moonboard_ble_stdout.log +StandardError=file:/var/log/moonboard_ble_stderr.log [Install] WantedBy=multi-user.target diff --git a/services/moonboard-install.service b/services/moonboard-install.service index 76473e4..648c0ad 100755 --- a/services/moonboard-install.service +++ b/services/moonboard-install.service @@ -5,6 +5,8 @@ After=multi-user.target [Service] ExecStart=/home/pi/moonboard/install-phase2.sh User=root +StandardOutput=file:/var/log/moonboard_install_stdout.log +StandardError=file:/var/log/moonboard_install_stderr.log [Install] WantedBy=multi-user.target diff --git a/services/moonboard.service b/services/moonboard.service index 02d5829..ac90684 100755 --- a/services/moonboard.service +++ b/services/moonboard.service @@ -1,12 +1,13 @@ - [Unit] -Description= moon board app service +Description=Moonboad App Service After=multi-user.target [Service] User=pi Type=idle ExecStart=/bin/bash /home/pi/moonboard/scripts/run.sh +StandardOutput=file:/var/log/moonboard_stdout.log +StandardError=file:/var/log/moonboard_stderr.log [Install] WantedBy=multi-user.target \ No newline at end of file From 5c3c9dd278f9e2d5fbbb7476521dad7dfcc13abe Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 20:37:28 +0100 Subject: [PATCH 016/240] cleanup --- install/install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/install/install.sh b/install/install.sh index e3556b6..43f77b2 100755 --- a/install/install.sh +++ b/install/install.sh @@ -44,7 +44,6 @@ sudo cp /home/pi/moonboard/ble/com.moonboard.service /usr/share/dbus-1/system-se echo "Prepare logfiles" sudo touch /var/log/moonboard sudo chown pi:pi /var/log/moonboard -sudo chown pi:pi /var/log/moonboard # Prepare phase 2 to run at boot sudo cp --verbose /home/pi/moonboard/services/moonboard-install.service /lib/systemd/system/moonboard-install.service From 6665520aa699f6598ff30252f0ad6183be8ee170 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 20:40:13 +0100 Subject: [PATCH 017/240] fixme --- install/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/install.sh b/install/install.sh index 43f77b2..4532a8b 100755 --- a/install/install.sh +++ b/install/install.sh @@ -23,7 +23,7 @@ test -d moonboard || git clone https://github.com/8cH9azbsFifZ/moonboard.git cd moonboard git pull -# Installing python dependencies +# Installing python dependencies # FIXME venv echo "Installing python dependencies" pip3 install -r install/requirements.txt sudo pip3 install -r install/requirements.txt From 1714b3395e22fd5bafa8d0bf1eb995f2edb5552c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 20:55:17 +0100 Subject: [PATCH 018/240] cleanup installation procedure --- install/10-prepare-raspi.sh | 19 +++++++++ install/install-phase2.sh | 14 ------ install/install.sh | 68 +++++++----------------------- services/install_service.sh | 10 ----- services/moonboard-install.service | 13 ------ 5 files changed, 35 insertions(+), 89 deletions(-) create mode 100644 install/10-prepare-raspi.sh delete mode 100755 install/install-phase2.sh delete mode 100755 services/install_service.sh delete mode 100755 services/moonboard-install.service diff --git a/install/10-prepare-raspi.sh b/install/10-prepare-raspi.sh new file mode 100644 index 0000000..a307389 --- /dev/null +++ b/install/10-prepare-raspi.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +echo "Enable SPI" +sudo sed -i 's/\#dtparam=spi=on/dtparam=spi=on/g' /boot/config.txt + +echo "Disable Audio" +sudo sed -i 's/\dtparam=audio=on/#dtparam=audio=on/g' /boot/config.txt +echo blacklist snd_bcm2835 | sudo tee /etc/modprobe.d/raspi-blacklist.conf + + +# Install dependencies +echo "Install dependencies" +sudo apt-get update +sudo apt-get upgrade + +echo "Install + build led drivers" +sudo apt-get -y install git vim python3-pip python3-rpi.gpio gcc make build-essential +sudo apt-get -y install libatlas-base-dev +sudo apt-get -y install python-dev swig scons # for building WS2811 drivers \ No newline at end of file diff --git a/install/install-phase2.sh b/install/install-phase2.sh deleted file mode 100755 index 79dacf4..0000000 --- a/install/install-phase2.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# FIXME: installdir -echo "Install DBUS service" -sudo cp /home/pi/moonboard/ble/com.moonboard.conf /etc/dbus-1/system.d -cd /home/pi/moonboard/ble -sudo /home/pi/moonboard/services/install_service.sh com.moonboard.service > /tmp/moonboard-service-install.log - - -sudo systemctl enable com.moonboard -sudo systemctl enable moonboard.service - -# Remove phase 2 from boot -sudo systemctl disable moonboard-install.service -sudo systemctl start moonboard.service diff --git a/install/install.sh b/install/install.sh index 4532a8b..2e8a24e 100755 --- a/install/install.sh +++ b/install/install.sh @@ -1,65 +1,29 @@ #!/bin/bash -echo "Enable SPI" -sudo sed -i 's/\#dtparam=spi=on/dtparam=spi=on/g' /boot/config.txt - -echo "Disable Audio" -sudo sed -i 's/\dtparam=audio=on/#dtparam=audio=on/g' /boot/config.txt -echo blacklist snd_bcm2835 | sudo tee /etc/modprobe.d/raspi-blacklist.conf - - -# Install dependencies -echo "Install dependencies" -sudo apt-get update -sudo apt-get upgrade - -echo "Install + build led drivers" -sudo apt-get -y install git vim python3-pip python3-rpi.gpio gcc make build-essential -sudo apt-get -y install libatlas-base-dev -sudo apt-get -y install python-dev swig scons # for building WS2811 drivers - -echo "Install application" -test -d moonboard || git clone https://github.com/8cH9azbsFifZ/moonboard.git -cd moonboard -git pull +#./10-prepare-raspi.sh # FIXME # Installing python dependencies # FIXME venv echo "Installing python dependencies" pip3 install -r install/requirements.txt sudo pip3 install -r install/requirements.txt -# pip3 uninstall -y -r install/requirements.txt # uninstall -echo "Install service" # FIXME -cd /home/pi/moonboard/services -sudo ./install_service.sh moonboard.service -cd /home/pi/moonboard - - -echo "Install DBUS service" -sudo cp /home/pi/moonboard/ble/com.moonboard.conf /etc/dbus-1/system.d -sudo cp /home/pi/moonboard/ble/com.moonboard.service /usr/share/dbus-1/system-services/ - +echo "Install DBUS service" # FIXME +sudo cp --verbose /home/pi/moonboard/ble/com.moonboard.conf /etc/dbus-1/system.d +sudo cp --verbose /home/pi/moonboard/ble/com.moonboard.service /lib/systemd/system/com.moonboard.service +sudo chmod 644 /lib/systemd/system/com.moonboard.service +sudo systemctl daemon-reload +sudo systemctl enable com.moonboard.service +sudo systemctl restart com.moonboard.service -echo "Prepare logfiles" -sudo touch /var/log/moonboard -sudo chown pi:pi /var/log/moonboard -# Prepare phase 2 to run at boot -sudo cp --verbose /home/pi/moonboard/services/moonboard-install.service /lib/systemd/system/moonboard-install.service -sudo chmod 644 /lib/systemd/system/moonboard-install.service +echo "Install service for Moonboard app" +sudo cp --verbose /home/pi/moonboard/services/moonboard.service /lib/systemd/system/moonboard.service +sudo chmod 644 /lib/systemd/system/moonboard.service sudo systemctl daemon-reload -sudo systemctl enable moonboard-install.service +sudo systemctl enable moonboard.service +sudo systemctl restart moonboard.service + -echo "Restarting in 5 seconds to finalize changes. CTRL+C to cancel." -sleep 1 > /dev/null -printf "." -sleep 1 > /dev/null -printf "." -sleep 1 > /dev/null -printf "." -sleep 1 > /dev/null -printf "." -sleep 1 > /dev/null -printf " Restarting" -sudo shutdown -r now +#printf " Restarting" # FIXME +#sudo shutdown -r now diff --git a/services/install_service.sh b/services/install_service.sh deleted file mode 100755 index caeb63e..0000000 --- a/services/install_service.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -FILE=$1 -echo "Copy service file $FILE" -cp --verbose $FILE /lib/systemd/system/$FILE -echo "set permission" -chmod 644 /lib/systemd/system/$FILE -echo "restart service" -systemctl daemon-reload -systemctl enable $FILE -systemctl restart $FILE diff --git a/services/moonboard-install.service b/services/moonboard-install.service deleted file mode 100755 index 648c0ad..0000000 --- a/services/moonboard-install.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Install Phase 2 -After=multi-user.target - -[Service] -ExecStart=/home/pi/moonboard/install-phase2.sh -User=root -StandardOutput=file:/var/log/moonboard_install_stdout.log -StandardError=file:/var/log/moonboard_install_stderr.log - -[Install] -WantedBy=multi-user.target - From e4a23b0592433bc0be351083ecb96d6450503e19 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 20:57:27 +0100 Subject: [PATCH 019/240] simplify --- scripts/run.sh | 8 -------- services/moonboard.service | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100755 scripts/run.sh diff --git a/scripts/run.sh b/scripts/run.sh deleted file mode 100755 index 853907a..0000000 --- a/scripts/run.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -o errexit -LOG_FILE=/var/log/moonboard - -exec 1>$LOG_FILE -exec 2>&1 - -sudo /usr/bin/python3 /home/pi/moonboard/run.py --debug --driver PiWS281x $1 \ No newline at end of file diff --git a/services/moonboard.service b/services/moonboard.service index ac90684..0c3d339 100755 --- a/services/moonboard.service +++ b/services/moonboard.service @@ -5,7 +5,7 @@ After=multi-user.target [Service] User=pi Type=idle -ExecStart=/bin/bash /home/pi/moonboard/scripts/run.sh +ExecStart=/usr/bin/python3 /home/pi/moonboard/run.py --debug --driver PiWS281x StandardOutput=file:/var/log/moonboard_stdout.log StandardError=file:/var/log/moonboard_stderr.log From 32e8cc8152ff4153fc8724f443ff39f25bb3243c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:00:54 +0100 Subject: [PATCH 020/240] root --- TESTING.md | 4 ++++ install/install.sh | 12 +++++++----- services/moonboard.service | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/TESTING.md b/TESTING.md index 930777c..ae50b61 100644 --- a/TESTING.md +++ b/TESTING.md @@ -8,3 +8,7 @@ ssh -lpi raspi-moonboard sudo btmon ``` ssh -lpi raspi-moonboard sudo dbus-monitor --system|less ``` + +# Logfiles +/var/log/moonboard_stdout.log +/var/log/moonboard_ble_stdout.log \ No newline at end of file diff --git a/install/install.sh b/install/install.sh index 2e8a24e..21800b8 100755 --- a/install/install.sh +++ b/install/install.sh @@ -1,16 +1,18 @@ #!/bin/bash +# FIXME: must run from this dir in checkout out version + #./10-prepare-raspi.sh # FIXME # Installing python dependencies # FIXME venv echo "Installing python dependencies" -pip3 install -r install/requirements.txt -sudo pip3 install -r install/requirements.txt +pip3 install -r requirements.txt +sudo pip3 install -r requirements.txt echo "Install DBUS service" # FIXME -sudo cp --verbose /home/pi/moonboard/ble/com.moonboard.conf /etc/dbus-1/system.d -sudo cp --verbose /home/pi/moonboard/ble/com.moonboard.service /lib/systemd/system/com.moonboard.service +sudo cp /home/pi/moonboard/ble/com.moonboard.conf /etc/dbus-1/system.d +sudo cp /home/pi/moonboard/ble/com.moonboard.service /lib/systemd/system/com.moonboard.service sudo chmod 644 /lib/systemd/system/com.moonboard.service sudo systemctl daemon-reload sudo systemctl enable com.moonboard.service @@ -18,7 +20,7 @@ sudo systemctl restart com.moonboard.service echo "Install service for Moonboard app" -sudo cp --verbose /home/pi/moonboard/services/moonboard.service /lib/systemd/system/moonboard.service +sudo cp /home/pi/moonboard/services/moonboard.service /lib/systemd/system/moonboard.service sudo chmod 644 /lib/systemd/system/moonboard.service sudo systemctl daemon-reload sudo systemctl enable moonboard.service diff --git a/services/moonboard.service b/services/moonboard.service index 0c3d339..19ef1d0 100755 --- a/services/moonboard.service +++ b/services/moonboard.service @@ -3,7 +3,8 @@ Description=Moonboad App Service After=multi-user.target [Service] -User=pi +User=root +#pi Type=idle ExecStart=/usr/bin/python3 /home/pi/moonboard/run.py --debug --driver PiWS281x StandardOutput=file:/var/log/moonboard_stdout.log From b5001a0ad2e642940a435ba1034c91ad5cb5e279 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:01:19 +0100 Subject: [PATCH 021/240] speedup --- install/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/install.sh b/install/install.sh index 21800b8..400f211 100755 --- a/install/install.sh +++ b/install/install.sh @@ -6,8 +6,8 @@ # Installing python dependencies # FIXME venv echo "Installing python dependencies" -pip3 install -r requirements.txt -sudo pip3 install -r requirements.txt +#pip3 install -r requirements.txt +#sudo pip3 install -r requirements.txt echo "Install DBUS service" # FIXME From 58f4604e93366eed1961d634f87a80241f31c4b7 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:03:23 +0100 Subject: [PATCH 022/240] logging --- TESTING.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/TESTING.md b/TESTING.md index ae50b61..d446cf4 100644 --- a/TESTING.md +++ b/TESTING.md @@ -11,4 +11,7 @@ ssh -lpi raspi-moonboard sudo dbus-monitor --system|less # Logfiles /var/log/moonboard_stdout.log -/var/log/moonboard_ble_stdout.log \ No newline at end of file +/var/log/moonboard_ble_stdout.log +``` +tail -f /var/log/moonboard* +``` \ No newline at end of file From 5a5ef77f3a69ddc61e50e5d0ff418084f8d7ce0a Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:05:42 +0100 Subject: [PATCH 023/240] chmodx --- install/10-prepare-raspi.sh | 0 install/install.sh | 5 +---- 2 files changed, 1 insertion(+), 4 deletions(-) mode change 100644 => 100755 install/10-prepare-raspi.sh diff --git a/install/10-prepare-raspi.sh b/install/10-prepare-raspi.sh old mode 100644 new mode 100755 diff --git a/install/install.sh b/install/install.sh index 400f211..a1e81d2 100755 --- a/install/install.sh +++ b/install/install.sh @@ -3,11 +3,8 @@ # FIXME: must run from this dir in checkout out version #./10-prepare-raspi.sh # FIXME +#./20-prepare-python.sh # FIXME -# Installing python dependencies # FIXME venv -echo "Installing python dependencies" -#pip3 install -r requirements.txt -#sudo pip3 install -r requirements.txt echo "Install DBUS service" # FIXME From dbf70598daf108a2edf7d776d93e6639bcd3f20a Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:06:01 +0100 Subject: [PATCH 024/240] python dev sep --- install/20-prepare-python.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 install/20-prepare-python.sh diff --git a/install/20-prepare-python.sh b/install/20-prepare-python.sh new file mode 100755 index 0000000..6be4f33 --- /dev/null +++ b/install/20-prepare-python.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Installing python dependencies # FIXME venv +echo "Installing python dependencies" +pip3 install -r requirements.txt +sudo pip3 install -r requirements.txt \ No newline at end of file From e7442abc35d087639ef6f9863535ce104734c45f Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:06:16 +0100 Subject: [PATCH 025/240] cleanup --- services/moonboard.service | 1 - 1 file changed, 1 deletion(-) diff --git a/services/moonboard.service b/services/moonboard.service index 19ef1d0..2f66dfc 100755 --- a/services/moonboard.service +++ b/services/moonboard.service @@ -4,7 +4,6 @@ After=multi-user.target [Service] User=root -#pi Type=idle ExecStart=/usr/bin/python3 /home/pi/moonboard/run.py --debug --driver PiWS281x StandardOutput=file:/var/log/moonboard_stdout.log From 42bd3dbfd31bddbd44efa8b9e6fd81702ce74eaa Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:06:35 +0100 Subject: [PATCH 026/240] cleanup --- install/install.sh | 2 -- TESTING.md => testing/TESTING.md | 0 2 files changed, 2 deletions(-) rename TESTING.md => testing/TESTING.md (100%) diff --git a/install/install.sh b/install/install.sh index a1e81d2..bec1b8a 100755 --- a/install/install.sh +++ b/install/install.sh @@ -5,8 +5,6 @@ #./10-prepare-raspi.sh # FIXME #./20-prepare-python.sh # FIXME - - echo "Install DBUS service" # FIXME sudo cp /home/pi/moonboard/ble/com.moonboard.conf /etc/dbus-1/system.d sudo cp /home/pi/moonboard/ble/com.moonboard.service /lib/systemd/system/com.moonboard.service diff --git a/TESTING.md b/testing/TESTING.md similarity index 100% rename from TESTING.md rename to testing/TESTING.md From 1af84967b6241e7a9460d6c8cd43c0b4e0fbd0f2 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:07:36 +0100 Subject: [PATCH 027/240] 0.30 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01c97ef..f2b403e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- v0.30 simplified installation procedure, fix service logging and installtion collisions - v0.28 merged moonboard mini protocol - v0.27 merged bt fix test - v0.23 running in gz setup \ No newline at end of file From 3159f799847972369ef7db01f3839616fe577459 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:21:51 +0100 Subject: [PATCH 028/240] dependency --- services/moonboard.service | 1 + 1 file changed, 1 insertion(+) diff --git a/services/moonboard.service b/services/moonboard.service index 2f66dfc..9ced0c7 100755 --- a/services/moonboard.service +++ b/services/moonboard.service @@ -1,5 +1,6 @@ [Unit] Description=Moonboad App Service +Wants=com.moonboard.service After=multi-user.target [Service] From 82a53ffbb978191a3d53d67a6280e29e4319e174 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:31:41 +0100 Subject: [PATCH 029/240] debugging --- testing/TESTING.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/testing/TESTING.md b/testing/TESTING.md index d446cf4..421df6f 100644 --- a/testing/TESTING.md +++ b/testing/TESTING.md @@ -13,5 +13,14 @@ ssh -lpi raspi-moonboard sudo dbus-monitor --system|less /var/log/moonboard_stdout.log /var/log/moonboard_ble_stdout.log ``` -tail -f /var/log/moonboard* -``` \ No newline at end of file +ssh -lpi raspi-moonboard "tail -f /var/log/moonboard*" +``` + +# Resetting services +``` +ssh -lpi raspi-moonboard "./moonboard/scripts/fix_startup.sh" +``` + + +# Updating +ssh -lpi raspi-moonboard "cd moonboard ; git pull; cd install ; ./install.sh" From 150f87b925975588645230284a3b238b22487e7c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 21:42:37 +0100 Subject: [PATCH 030/240] status checks --- testing/TESTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testing/TESTING.md b/testing/TESTING.md index 421df6f..41b1004 100644 --- a/testing/TESTING.md +++ b/testing/TESTING.md @@ -21,6 +21,10 @@ ssh -lpi raspi-moonboard "tail -f /var/log/moonboard*" ssh -lpi raspi-moonboard "./moonboard/scripts/fix_startup.sh" ``` +# Checking status of services +ssh -lpi raspi-moonboard sudo systemctl status moonboard.service + +ssh -lpi raspi-moonboard sudo systemctl status com.moonboard.service # Updating ssh -lpi raspi-moonboard "cd moonboard ; git pull; cd install ; ./install.sh" From 9cc16a53ae121c92a8efbb04892b702962f321fa Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 22:06:49 +0100 Subject: [PATCH 031/240] orders --- ble/com.moonboard.service | 2 +- services/moonboard.service | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ble/com.moonboard.service b/ble/com.moonboard.service index b5e152a..a9c26c2 100755 --- a/ble/com.moonboard.service +++ b/ble/com.moonboard.service @@ -1,6 +1,6 @@ [Unit] Description=Moonboard BLE DBUS Service -After=multi-user.target +After=multi-user.target bluetooth.service dbus.service SystemdService=dbus-org.com.moonbooard.service [Service] diff --git a/services/moonboard.service b/services/moonboard.service index 9ced0c7..2a464cb 100755 --- a/services/moonboard.service +++ b/services/moonboard.service @@ -1,7 +1,7 @@ [Unit] Description=Moonboad App Service -Wants=com.moonboard.service -After=multi-user.target +After=com.moonboard.service dbus.service multi-user.target + [Service] User=root From a1125e524ff8a7e61ce4f5c487d7dbe7f8aa60bd Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 22:23:43 +0100 Subject: [PATCH 032/240] debug startup --- ble/com.moonboard.service | 4 +++- services/moonboard.service | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ble/com.moonboard.service b/ble/com.moonboard.service index a9c26c2..8604337 100755 --- a/ble/com.moonboard.service +++ b/ble/com.moonboard.service @@ -1,7 +1,7 @@ [Unit] Description=Moonboard BLE DBUS Service After=multi-user.target bluetooth.service dbus.service -SystemdService=dbus-org.com.moonbooard.service +#SystemdService=dbus-org.com.moonbooard.service [Service] Type=dbus @@ -10,6 +10,8 @@ ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_BLE_service.py User=root StandardOutput=file:/var/log/moonboard_ble_stdout.log StandardError=file:/var/log/moonboard_ble_stderr.log +ExecStartPre=/bin/sleep 30 + [Install] WantedBy=multi-user.target diff --git a/services/moonboard.service b/services/moonboard.service index 2a464cb..45721e5 100755 --- a/services/moonboard.service +++ b/services/moonboard.service @@ -7,6 +7,7 @@ After=com.moonboard.service dbus.service multi-user.target User=root Type=idle ExecStart=/usr/bin/python3 /home/pi/moonboard/run.py --debug --driver PiWS281x +ExecStartPre=/bin/sleep 30 StandardOutput=file:/var/log/moonboard_stdout.log StandardError=file:/var/log/moonboard_stderr.log From 51396a41804a2e19ef31902f3d2b3f3a4d2adb01 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 22:32:16 +0100 Subject: [PATCH 033/240] no startup wait --- ble/com.moonboard.service | 2 -- services/moonboard.service | 2 -- 2 files changed, 4 deletions(-) diff --git a/ble/com.moonboard.service b/ble/com.moonboard.service index 8604337..03256a4 100755 --- a/ble/com.moonboard.service +++ b/ble/com.moonboard.service @@ -10,8 +10,6 @@ ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_BLE_service.py User=root StandardOutput=file:/var/log/moonboard_ble_stdout.log StandardError=file:/var/log/moonboard_ble_stderr.log -ExecStartPre=/bin/sleep 30 - [Install] WantedBy=multi-user.target diff --git a/services/moonboard.service b/services/moonboard.service index 45721e5..db7084a 100755 --- a/services/moonboard.service +++ b/services/moonboard.service @@ -2,12 +2,10 @@ Description=Moonboad App Service After=com.moonboard.service dbus.service multi-user.target - [Service] User=root Type=idle ExecStart=/usr/bin/python3 /home/pi/moonboard/run.py --debug --driver PiWS281x -ExecStartPre=/bin/sleep 30 StandardOutput=file:/var/log/moonboard_stdout.log StandardError=file:/var/log/moonboard_stderr.log From cbaae99e865b4394a9ad7209867752a2db09193d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 22:34:51 +0100 Subject: [PATCH 034/240] dbus --- ble/com.moonboard.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble/com.moonboard.service b/ble/com.moonboard.service index 03256a4..a9c26c2 100755 --- a/ble/com.moonboard.service +++ b/ble/com.moonboard.service @@ -1,7 +1,7 @@ [Unit] Description=Moonboard BLE DBUS Service After=multi-user.target bluetooth.service dbus.service -#SystemdService=dbus-org.com.moonbooard.service +SystemdService=dbus-org.com.moonbooard.service [Service] Type=dbus From e7f976df287b3a983731dd3553e8421aac379cb5 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 22:49:25 +0100 Subject: [PATCH 035/240] uart modem? --- ble/com.moonboard.service | 5 +++-- testing/TESTING.md | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ble/com.moonboard.service b/ble/com.moonboard.service index a9c26c2..6723244 100755 --- a/ble/com.moonboard.service +++ b/ble/com.moonboard.service @@ -1,7 +1,8 @@ [Unit] Description=Moonboard BLE DBUS Service -After=multi-user.target bluetooth.service dbus.service -SystemdService=dbus-org.com.moonbooard.service +After=multi-user.target bluetooth.service dbus.service hciuart.service +SystemdService=dbus-org.com.moonbooard.service +# FIXME: SystemdService not known [Service] Type=dbus diff --git a/testing/TESTING.md b/testing/TESTING.md index 41b1004..7f12c70 100644 --- a/testing/TESTING.md +++ b/testing/TESTING.md @@ -28,3 +28,6 @@ ssh -lpi raspi-moonboard sudo systemctl status com.moonboard.service # Updating ssh -lpi raspi-moonboard "cd moonboard ; git pull; cd install ; ./install.sh" + + +sudo systemctl disable hciuart.service From 8b292ab8afba3e117ae87a8284574bcdc5d5007d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Mon, 29 Nov 2021 22:57:59 +0100 Subject: [PATCH 036/240] cleanup --- testing/TESTING.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/testing/TESTING.md b/testing/TESTING.md index 7f12c70..41b1004 100644 --- a/testing/TESTING.md +++ b/testing/TESTING.md @@ -28,6 +28,3 @@ ssh -lpi raspi-moonboard sudo systemctl status com.moonboard.service # Updating ssh -lpi raspi-moonboard "cd moonboard ; git pull; cd install ; ./install.sh" - - -sudo systemctl disable hciuart.service From 30c17faa64c8a74ad36466cbb8d572a1c21e5ac4 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:09:38 +0100 Subject: [PATCH 037/240] test --- test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.txt diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..e69de29 From 4aaba18a411bd73b9260ca4c2d3744b028db7a18 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:09:51 +0100 Subject: [PATCH 038/240] test --- test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test.txt diff --git a/test.txt b/test.txt deleted file mode 100644 index e69de29..0000000 From daec3ff7de3c396251abc00e9e4c599dba159a1a Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:14:55 +0100 Subject: [PATCH 039/240] minimize installer --- install/install-phase2.sh | 14 -------------- install/install.sh | 13 +++++++------ services/moonboard-install.service | 11 ----------- 3 files changed, 7 insertions(+), 31 deletions(-) delete mode 100755 install/install-phase2.sh delete mode 100755 services/moonboard-install.service diff --git a/install/install-phase2.sh b/install/install-phase2.sh deleted file mode 100755 index 79dacf4..0000000 --- a/install/install-phase2.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# FIXME: installdir -echo "Install DBUS service" -sudo cp /home/pi/moonboard/ble/com.moonboard.conf /etc/dbus-1/system.d -cd /home/pi/moonboard/ble -sudo /home/pi/moonboard/services/install_service.sh com.moonboard.service > /tmp/moonboard-service-install.log - - -sudo systemctl enable com.moonboard -sudo systemctl enable moonboard.service - -# Remove phase 2 from boot -sudo systemctl disable moonboard-install.service -sudo systemctl start moonboard.service diff --git a/install/install.sh b/install/install.sh index e3556b6..70bef70 100755 --- a/install/install.sh +++ b/install/install.sh @@ -36,21 +36,22 @@ sudo ./install_service.sh moonboard.service cd /home/pi/moonboard -echo "Install DBUS service" +echo "Install DBUS service" # FIXME - script install_service can be used or removed sudo cp /home/pi/moonboard/ble/com.moonboard.conf /etc/dbus-1/system.d sudo cp /home/pi/moonboard/ble/com.moonboard.service /usr/share/dbus-1/system-services/ +cd /home/pi/moonboard/ble +sudo /home/pi/moonboard/services/install_service.sh com.moonboard.service > /tmp/moonboard-service-install.log +sudo systemctl enable com.moonboard +sudo systemctl enable moonboard.service + +# FIXME Update scripts with logfile information echo "Prepare logfiles" sudo touch /var/log/moonboard sudo chown pi:pi /var/log/moonboard sudo chown pi:pi /var/log/moonboard -# Prepare phase 2 to run at boot -sudo cp --verbose /home/pi/moonboard/services/moonboard-install.service /lib/systemd/system/moonboard-install.service -sudo chmod 644 /lib/systemd/system/moonboard-install.service -sudo systemctl daemon-reload -sudo systemctl enable moonboard-install.service echo "Restarting in 5 seconds to finalize changes. CTRL+C to cancel." sleep 1 > /dev/null diff --git a/services/moonboard-install.service b/services/moonboard-install.service deleted file mode 100755 index 76473e4..0000000 --- a/services/moonboard-install.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Install Phase 2 -After=multi-user.target - -[Service] -ExecStart=/home/pi/moonboard/install-phase2.sh -User=root - -[Install] -WantedBy=multi-user.target - From 89fda8f81ebb9d1b721ae80cc8a061aa1ed9c8c3 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:22:12 +0100 Subject: [PATCH 040/240] testing interface --- run_testing_interface.py | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 run_testing_interface.py diff --git a/run_testing_interface.py b/run_testing_interface.py new file mode 100644 index 0000000..e2fa6ad --- /dev/null +++ b/run_testing_interface.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +import argparse +from led.moonboard import MoonBoard,LED_LAYOUT +from gi.repository import GLib +import dbus +from dbus.mainloop.glib import DBusGMainLoop +from functools import partial +import json +import json +import RPi.GPIO as GPIO +import os +#import signal +import sys +import logging + +# external power LED and power button +LED_GPIO = 26 +BUTTON_GPIO = 3 + +# Main stuff +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='') + + parser.add_argument('--driver_type', + help='driver type, depends on leds and device controlling the led.', + choices=['PiWS281x', 'WS2801', 'SimPixel'], + default='WS2801') + + parser.add_argument('--brightness', default=100, type=int) + + parser.add_argument('--led_layout', + default=None, + choices=list(LED_LAYOUT.keys()) + ) + + parser.add_argument('--debug', action = "store_true") + + + args = parser.parse_args() + argsd=vars(args) + logger = logging.getLogger('run') + logger.setLevel(logging.DEBUG) + logger.addHandler(logging.StreamHandler()) + + if args.debug: + logger.setLevel(logging.DEBUG) + else: + logger.setLevel(logging.INFO) + + #problems + led_layout = LED_LAYOUT.get(args.led_layout) if args.led_layout is not None else None + MOONBOARD = MoonBoard(args.driver_type, led_layout) + + holds = "K7" + MOONBOARD.show_problem(holds) From 07d9208d512ef988831f13736934b84948830ce2 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:23:05 +0100 Subject: [PATCH 041/240] fix --- run_testing_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index e2fa6ad..8f05575 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -51,5 +51,5 @@ led_layout = LED_LAYOUT.get(args.led_layout) if args.led_layout is not None else None MOONBOARD = MoonBoard(args.driver_type, led_layout) - holds = "K7" + holds = ["K7"] MOONBOARD.show_problem(holds) From f592a4f4d47d0a9d26f5327bec7e4a6b118eab54 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:25:43 +0100 Subject: [PATCH 042/240] fix --- run_testing_interface.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 8f05575..6f7e671 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -51,5 +51,11 @@ led_layout = LED_LAYOUT.get(args.led_layout) if args.led_layout is not None else None MOONBOARD = MoonBoard(args.driver_type, led_layout) - holds = ["K7"] + #holds = ["K7"] + holds = {} + #['START'] + holds ["START"] = "K1" + holds ["TOP"] = "K7" + #for k in ['START', 'MOVES', 'TOP']: + # for hold in holds[k]: MOONBOARD.show_problem(holds) From be6aa4edac07db1be46b9b83bce8361f79c3d2cf Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:29:40 +0100 Subject: [PATCH 043/240] fix --- run_testing_interface.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run_testing_interface.py b/run_testing_interface.py index 6f7e671..c6122f0 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -55,6 +55,8 @@ holds = {} #['START'] holds ["START"] = "K1" + holds ["MOVES"] = ["B2", "B5"] + holds ["TOP"] = "K7" #for k in ['START', 'MOVES', 'TOP']: # for hold in holds[k]: From da32d4dd25dd61afd9610a261249f19efcc8abbe Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:31:13 +0100 Subject: [PATCH 044/240] single hold --- run_testing_interface.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index c6122f0..3b375f4 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -51,13 +51,9 @@ led_layout = LED_LAYOUT.get(args.led_layout) if args.led_layout is not None else None MOONBOARD = MoonBoard(args.driver_type, led_layout) - #holds = ["K7"] holds = {} - #['START'] holds ["START"] = "K1" holds ["MOVES"] = ["B2", "B5"] - holds ["TOP"] = "K7" - #for k in ['START', 'MOVES', 'TOP']: - # for hold in holds[k]: - MOONBOARD.show_problem(holds) + #MOONBOARD.show_problem(holds) + MOONBOARD.show_hold("A4") From 727070010de185aa4e6acde5d5b7326bd4a16b9b Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:34:06 +0100 Subject: [PATCH 045/240] clear --- run_testing_interface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/run_testing_interface.py b/run_testing_interface.py index 3b375f4..575f292 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -56,4 +56,5 @@ holds ["MOVES"] = ["B2", "B5"] holds ["TOP"] = "K7" #MOONBOARD.show_problem(holds) + MOONBOARD.clear() MOONBOARD.show_hold("A4") From f300fb9c1cd28e8faeefb848739a824b7483c33f Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:35:19 +0100 Subject: [PATCH 046/240] 2 holds --- run_testing_interface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/run_testing_interface.py b/run_testing_interface.py index 575f292..d52de80 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -58,3 +58,4 @@ #MOONBOARD.show_problem(holds) MOONBOARD.clear() MOONBOARD.show_hold("A4") + MOONBOARD.show_hold("B4") From 530f7ec36a90ea34364581ceb23658174c819477 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:38:20 +0100 Subject: [PATCH 047/240] cleanup --- run_testing_interface.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index d52de80..02b2dab 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -1,17 +1,15 @@ # -*- coding: utf-8 -*- import argparse from led.moonboard import MoonBoard,LED_LAYOUT -from gi.repository import GLib -import dbus -from dbus.mainloop.glib import DBusGMainLoop from functools import partial -import json import json import RPi.GPIO as GPIO import os #import signal import sys import logging +import paho.mqtt.client as paho +# FIXME pip install # external power LED and power button LED_GPIO = 26 From 26c21412e67ae4d7a9ad894e893cac00daa3bc35 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:42:10 +0100 Subject: [PATCH 048/240] mqtt connect --- run_testing_interface.py | 77 ++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 02b2dab..0648203 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -8,6 +8,7 @@ #import signal import sys import logging +import time import paho.mqtt.client as paho # FIXME pip install @@ -15,8 +16,69 @@ LED_GPIO = 26 BUTTON_GPIO = 3 + +import logging +logging.basicConfig(level=logging.DEBUG, + format='Display(%(threadName)-10s) %(message)s', + ) + + + +class Database(): + def __init__(self): + self._MOONBOARD = MoonBoard(driver_type, led_layout) + + # Init timers + self._time_current = time.time() + self._time_last = self._time_current + self._update_interval = 1.0 #0.5 # Update interval for display in seconds + + + def _on_message(self, client, userdata, message): + logging.debug("Write message " + str(message.payload.decode("utf-8"))) + + msg = json.loads(message.payload.decode("utf-8")) + + # Check if interval large enough + time_last = self._time_current + self._time_current = time.time() + del_time = self._time_current - self._time_last + #logging.debug(del_time) + if del_time < self._update_interval: + return + + self._time_last = time_last + + print (msg) + #l = "\rLoad: %.1f " % msg["loadcurrent"] + #t = "Time: " + str(msg["time"]) + #lmax = "\rLoad Max: %.1f " % msg["loadmaximal"] + + self._MOONBOARD.clear() + self._MOONBOARD.show_hold("A4") + self._MOONBOARD.show_hold("B4") + + + def _record_data(self, hostname="localhost",port=1883): + logging.debug("Start recording data from mqtt to database") + self._client= paho.Client("client-001") # FIXME + self._client.on_message=self._on_message + self._client.connect(hostname,port,60)#connect + + # FIXME: subscribe to all? + + self._client.subscribe("hangboard/sensor/load/loadstatus") + #self._client.subscribe("hangboard/sensor/sensorstatus") + #self._client.subscribe("hangboard/sensor/lastexercise") + #self._client.subscribe("hangboard/workout/userstatistics") + #self._client.subscribe("hangboard/workout/upcoming") + + self._client.loop_forever() + # Main stuff + if __name__ == "__main__": + parser = argparse.ArgumentParser(description='') parser.add_argument('--driver_type', @@ -33,7 +95,6 @@ parser.add_argument('--debug', action = "store_true") - args = parser.parse_args() argsd=vars(args) logger = logging.getLogger('run') @@ -47,13 +108,7 @@ #problems led_layout = LED_LAYOUT.get(args.led_layout) if args.led_layout is not None else None - MOONBOARD = MoonBoard(args.driver_type, led_layout) - - holds = {} - holds ["START"] = "K1" - holds ["MOVES"] = ["B2", "B5"] - holds ["TOP"] = "K7" - #MOONBOARD.show_problem(holds) - MOONBOARD.clear() - MOONBOARD.show_hold("A4") - MOONBOARD.show_hold("B4") + driver_type = args.driver_type + + d = Database() + d._record_data(hostname="raspi-hangboard") From 3bd9f78e9e7e2bba63ad95287561122f560b2f9a Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:50:26 +0100 Subject: [PATCH 049/240] test perc --- run_testing_interface.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 0648203..7148160 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -54,9 +54,20 @@ def _on_message(self, client, userdata, message): #t = "Time: " + str(msg["time"]) #lmax = "\rLoad Max: %.1f " % msg["loadmaximal"] + lc = int(msg["loadcurrent"]) + lc1 = int(repr(lc)[-1]) + #lc10 = int(repr(lc)[-2]) + #lc100 = int(repr(lc)[-3]) + self._MOONBOARD.clear() - self._MOONBOARD.show_hold("A4") - self._MOONBOARD.show_hold("B4") + + #charmax = chr(ord('@')+lc1) + for i1 in range (0, lc1): + ichar = chr(ord('@')+i1) + self._MOONBOARD.show_hold(ichar+"4") + + #self._MOONBOARD.show_hold("A4") + #self._MOONBOARD.show_hold("B4") def _record_data(self, hostname="localhost",port=1883): From 4a402b1423d5c71b6f870d515b56bb5b091ea3db Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:51:39 +0100 Subject: [PATCH 050/240] fix --- run_testing_interface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 7148160..1243c9d 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -44,8 +44,8 @@ def _on_message(self, client, userdata, message): self._time_current = time.time() del_time = self._time_current - self._time_last #logging.debug(del_time) - if del_time < self._update_interval: - return + #if del_time < self._update_interval: + # return self._time_last = time_last From c9c093dd94c2cbd6f92f8f7f783320ccfd6096a0 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:53:00 +0100 Subject: [PATCH 051/240] debug --- run_testing_interface.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 1243c9d..3f72677 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -35,7 +35,7 @@ def __init__(self): def _on_message(self, client, userdata, message): - logging.debug("Write message " + str(message.payload.decode("utf-8"))) + logging.debug("Received message " + str(message.payload.decode("utf-8"))) msg = json.loads(message.payload.decode("utf-8")) @@ -43,13 +43,13 @@ def _on_message(self, client, userdata, message): time_last = self._time_current self._time_current = time.time() del_time = self._time_current - self._time_last - #logging.debug(del_time) - #if del_time < self._update_interval: - # return + logging.debug(del_time) + if del_time < self._update_interval: + return self._time_last = time_last - print (msg) + logging.debug ("Using it") #l = "\rLoad: %.1f " % msg["loadcurrent"] #t = "Time: " + str(msg["time"]) #lmax = "\rLoad Max: %.1f " % msg["loadmaximal"] From 6f84f329bba9e0b7cc354f2d9cb9e228cfbfbb12 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:54:55 +0100 Subject: [PATCH 052/240] fix --- run_testing_interface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 3f72677..e2deec2 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -25,7 +25,7 @@ class Database(): - def __init__(self): + def __init__(self, driver_type="", led_layout=""): self._MOONBOARD = MoonBoard(driver_type, led_layout) # Init timers @@ -121,5 +121,5 @@ def _record_data(self, hostname="localhost",port=1883): led_layout = LED_LAYOUT.get(args.led_layout) if args.led_layout is not None else None driver_type = args.driver_type - d = Database() + d = Database(driver_type=driver_type, led_layout=led_layout) d._record_data(hostname="raspi-hangboard") From 71f161dd4242029c9479fdbae5419e680f9600ac Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:55:46 +0100 Subject: [PATCH 053/240] fix --- run_testing_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index e2deec2..89021af 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -62,7 +62,7 @@ def _on_message(self, client, userdata, message): self._MOONBOARD.clear() #charmax = chr(ord('@')+lc1) - for i1 in range (0, lc1): + for i1 in range (1, lc1): ichar = chr(ord('@')+i1) self._MOONBOARD.show_hold(ichar+"4") From cbe1a4522e37a6a1dfdf8941383ef42e2f956bb6 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:57:08 +0100 Subject: [PATCH 054/240] debug --- run_testing_interface.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 89021af..faf659d 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -64,7 +64,9 @@ def _on_message(self, client, userdata, message): #charmax = chr(ord('@')+lc1) for i1 in range (1, lc1): ichar = chr(ord('@')+i1) - self._MOONBOARD.show_hold(ichar+"4") + ihold = ichar+"4" + logging.debug("Use hold "+ihold) + self._MOONBOARD.show_hold(ihold) #self._MOONBOARD.show_hold("A4") #self._MOONBOARD.show_hold("B4") From 69a5a7189e2b29aee3bf14f2296d3544bc1b390e Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 21:58:01 +0100 Subject: [PATCH 055/240] debug --- run_testing_interface.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index faf659d..d8e30f7 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -58,9 +58,10 @@ def _on_message(self, client, userdata, message): lc1 = int(repr(lc)[-1]) #lc10 = int(repr(lc)[-2]) #lc100 = int(repr(lc)[-3]) - + logging.debug ("Clean board") self._MOONBOARD.clear() + logging.debug ("Begin display holds") #charmax = chr(ord('@')+lc1) for i1 in range (1, lc1): ichar = chr(ord('@')+i1) From 5d5d2713f4e2ccf0782f867a0afb30ee7a94c726 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 25 Dec 2021 22:00:39 +0100 Subject: [PATCH 056/240] not working yet - events too fast. --- run_testing_interface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/run_testing_interface.py b/run_testing_interface.py index d8e30f7..60ffa32 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -68,6 +68,7 @@ def _on_message(self, client, userdata, message): ihold = ichar+"4" logging.debug("Use hold "+ihold) self._MOONBOARD.show_hold(ihold) + # FIXME: Runs too long - next event occurs.... #self._MOONBOARD.show_hold("A4") #self._MOONBOARD.show_hold("B4") From 10fea905b6965b5c4094f0030faaecd7c0aa4177 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 12:37:43 +0100 Subject: [PATCH 057/240] test animation --- led/animation.py | 232 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100755 led/animation.py diff --git a/led/animation.py b/led/animation.py new file mode 100755 index 0000000..84ec08a --- /dev/null +++ b/led/animation.py @@ -0,0 +1,232 @@ +# -*- coding: utf-8 -*- +from bibliopixel.colors import COLORS +from bibliopixel import Strip +from bibliopixel.drivers.PiWS281X import PiWS281X +from bibliopixel.drivers.dummy_driver import DriverDummy +from bibliopixel.drivers.SPI.WS2801 import WS2801 +from bibliopixel.drivers.SimPixel import SimPixel +from bibliopixel.drivers.spi_interfaces import SPI_INTERFACES +import string +import json +import time + +# FIXME: Describe Layouts +# FIXME: Delete this +LED_LAYOUT = { + 'nest':[ + # Top panel + [137, 138, 149, 150, 161, 162, 173, 174, 185, 186, 197], + [136, 139, 148, 151, 160, 163, 172, 175, 184, 187, 196], + [135, 140, 147, 152, 159, 164, 171, 176, 183, 188, 195], + [134, 141, 146, 153, 158, 165, 170, 177, 182, 189, 194], + [133, 142, 145, 154, 157, 166, 169, 178, 181, 190, 193], + [132, 143, 144, 155, 156, 167, 168, 179, 180, 191, 192], + # Middle panel + [131, 120, 119, 108, 107, 96, 95, 84, 83, 72, 71], + [130, 121, 118, 109, 106, 97, 94, 85, 82, 73, 70], + [129, 122, 117, 110, 105, 98, 93, 86, 81, 74, 69], + [128, 123, 116, 111, 104, 99, 92, 87, 80, 75, 68], + [127, 124, 115, 112, 103, 100, 91, 88, 79, 76, 67], + [126, 125, 114, 113, 102, 101, 90, 89, 78, 77, 66], + # Bottom panel + [5, 6, 17, 18, 29, 30, 41, 42, 53, 54, 65], + [4, 7, 16, 19, 28, 31, 40, 43, 52, 55, 64], + [3, 8, 15, 20, 27, 32, 39, 44, 51, 56, 63], + [2, 9, 14, 21, 26, 33, 38, 45, 50, 57, 62], + [1, 10, 13, 22, 25, 34, 37, 46, 49, 58, 61], + [0, 11, 12, 23, 24, 35, 36, 47, 48, 59, 60]], + +'evo': [[ 17, 18, 53, 54, 89, 90, 125, 126, 161, 162, 197], + [ 16, 19, 52, 55, 88, 91, 124, 127, 160, 163, 196], + [ 15, 20, 51, 56, 87, 92, 123, 128, 159, 164, 195], + [ 14, 21, 50, 57, 86, 93, 122, 129, 158, 165, 194], + [ 13, 22, 49, 58, 85, 94, 121, 130, 157, 166, 193], + [ 12, 23, 48, 59, 84, 95, 120, 131, 156, 167, 192], + [ 11, 24, 47, 60, 83, 96, 119, 132, 155, 168, 191], + [ 10, 25, 46, 61, 82, 97, 118, 133, 154, 169, 190], + [ 9, 26, 45, 62, 81, 98, 117, 134, 153, 170, 189], + [ 8, 27, 44, 63, 80, 99, 116, 135, 152, 171, 188], + [ 7, 28, 43, 64, 79, 100, 115, 136, 151, 172, 187], + [ 6, 29, 42, 65, 78, 101, 114, 137, 150, 173, 186], + [ 5, 30, 41, 66, 77, 102, 113, 138, 149, 174, 185], + [ 4, 31, 40, 67, 76, 103, 112, 139, 148, 175, 184], + [ 3, 32, 39, 68, 75, 104, 111, 140, 147, 176, 183], + [ 2, 33, 38, 69, 74, 105, 110, 141, 146, 177, 182], + [ 1, 34, 37, 70, 73, 106, 109, 142, 145, 178, 181], + [ 0, 35, 36, 71, 72, 107, 108, 143, 144, 179, 180]] + } + +class MoonBoard: + DEFAULT_PROBLEM_COLORS = {'START':COLORS.blue,'TOP':COLORS.red,'MOVES':COLORS.green} + DEFAULT_COLOR = COLORS.blue #FIXME ? + X_GRID_NAMES = string.ascii_uppercase[0:11] # FIXME: del + LED_SPACING = 3 # Use every n-th LED only - used for 3 x 4x5 LED strp # FIXME: normal=1 + ROWS = 18 + COLS = 11 + NUM_PIXELS = ROWS*COLS * LED_SPACING + DEFAULT_BRIGHTNESS = 100 # FIXME: to config file + SETUP = 'MoonboardMasters2017' # FIXME: to config file / Arg + + + # FIXME: json + MAPPING= { } + + with open('/home/pi/moonboard/led/led_mapping.json') as json_file: + data = json.load(json_file) + MAPPING = data + + + def __init__(self, driver_type, led_layout=None, brightness=DEFAULT_BRIGHTNESS): + try: + if driver_type == "PiWS281x": + driver = PiWS281X(self.NUM_PIXELS) + elif driver_type == "WS2801": + driver = WS2801(self.NUM_PIXELS, dev='/dev/spidev0.1',spi_interface= SPI_INTERFACES.PERIPHERY,spi_speed=1) + elif driver_type == "SimPixel": + driver = SimPixel(self.NUM_PIXELS) + driver.open_browser() + else: + raise ValueError("driver_type {driver_type} unknow.".format(driver_type) ) + except (ImportError, ValueError) as e: + print("Not able to initialize the driver. Error{}".format(e)) + print("Use bibliopixel.drivers.dummy_driver") + driver = DriverDummy(self.NUM_PIXELS) + + if led_layout is not None: + self.layout = Strip (driver, brightness=brightness,threadedUpdate=True) + else: + self.layout = Strip (driver, brightness=brightness,threadedUpdate=True) + self.layout.cleanup_drivers() + self.layout.start() + self.animation = None + + def clear(self): + self.stop_animation() + self.layout.all_off() + self.layout.push_to_driver() + + def set_hold(self, hold, color=DEFAULT_COLOR): + self.layout.set(self.MAPPING[hold], color) + + def show_hold(self, hold, color=DEFAULT_COLOR): + self.set_hold(hold, color) + self.layout.push_to_driver() + + def show_problem(self, holds, hold_colors={}): + self.clear() + for k in ['START', 'MOVES', 'TOP']: + for hold in holds[k]: + self.set_hold( + hold, + hold_colors.get(k, self.DEFAULT_PROBLEM_COLORS[k]), + ) + self.layout.push_to_driver() + + # run all colors in led´s to see if something is missing + def led_test(self): + print('led test') + duration = 0.4 + COLORS = ['red', 'green', 'blue'] + + for color in range(len(COLORS)): + for i in range(1,self.ROWS+1): + for j in range (0,self.COLS): + le = chr(j+65) + h = le+str(i) + #print (h) + self.layout.set(self.MAPPING[h], COLORS[color]) + self.layout.push_to_driver() + time.sleep(duration) + + time.sleep (1.2) + self.clear() + + + def run_animation(self, run_options={}, **kwds): # FIXME: will it still work? + duration = 0.01 + + for i in range(1,self.ROWS+1): + for j in range (0,self.COLS): + + le = chr(j+65) + h = le+str(i) + print (h) + for c in [COLORS.purple, COLORS.blue, COLORS.red]: + self.layout.set(self.MAPPING[h], c) + self.layout.push_to_driver() + time.sleep(duration) + + time.sleep(60*10) + + self.clear() + + def display_holdset(self, holdset="Hold Set A", duration=10, **kwds): + print ("Display holdset: " + str(holdset)) + + with open('../problems/HoldSetup.json') as json_file: # FIXME: path + data = json.load(json_file) + for hold in data[self.SETUP]: + hs = (data[self.SETUP][hold]['HoldSet']) + color = COLORS.black + + if (hs == holdset):# FIXME + color = COLORS.green + + self.layout.set(self.MAPPING[hold], color) + + #self.set_hold (hold, color) + #print "Orientation" + + self.layout.push_to_driver() + + wait_holdset_duration = duration # FIXME + time.sleep(wait_holdset_duration) + + self.clear() + + + + def stop_animation(self): + if self.animation is not None: + self.animation.stop() + + +class TestAnimation: + COLOR=[COLORS.Green, COLORS.Blue] + def __init__(self, layout, ): + self.layout = layout + + def step(self, amt=1): + pass + +if __name__=="__main__": + import argparse + import time + import subprocess + + parser = argparse.ArgumentParser(description='Test led system') + + parser.add_argument('--driver_type', type=str, + help='driver type, depends on leds and device controlling the led.',choices=['PiWS281x', 'WS2801', 'SimPixel'], + default = "PiWS281x") + parser.add_argument('--duration', type=int, default=10, + help='Delay of progress.') + parser.add_argument('--holdset', type=str, help="Display a holdset for current layout", + choices=['Hold Set A', 'Hold Set B', 'Hold Set C', 'Original School Holds', "Wooden Holds"], + default = "Hold Set A") + args = parser.parse_args() + + led_layout = None + + MOONBOARD = MoonBoard(args.driver_type,led_layout ) + + # Display a holdset + #MOONBOARD.display_holdset(args.holdset, args.duration) + + print("Run animation,") + MOONBOARD.run_animation() # FIXME + + print(f"wait {args.duration} seconds,") + time.sleep(args.duration) + print("clear and exit.") + MOONBOARD.clear() \ No newline at end of file From 5d0633c018427679d32928dded3d08edfd11ece4 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 12:40:09 +0100 Subject: [PATCH 058/240] todo --- TODO.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..8b8cd22 --- /dev/null +++ b/TODO.md @@ -0,0 +1,10 @@ + +# Redesign TBD: +- Use MQTT instead of DBUS + +# Minor stuff +- uninstaller for services + +# Minor cleanups +- Select python version from "env" for all scripts +- FIXME in files From 22961c24920f8e71dffff303378baaf28abfbcde Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 12:40:38 +0100 Subject: [PATCH 059/240] wip --- led/animation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 84ec08a..1269564 100755 --- a/led/animation.py +++ b/led/animation.py @@ -144,6 +144,7 @@ def led_test(self): def run_animation(self, run_options={}, **kwds): # FIXME: will it still work? duration = 0.01 + duration2 = duration * 10 for i in range(1,self.ROWS+1): for j in range (0,self.COLS): @@ -156,7 +157,7 @@ def run_animation(self, run_options={}, **kwds): # FIXME: will it still work? self.layout.push_to_driver() time.sleep(duration) - time.sleep(60*10) + time.sleep(duration2) self.clear() From ce0b12bfd7d317de8fdba37d6848cbb36db36946 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:13:37 +0100 Subject: [PATCH 060/240] wip flare --- led/animation.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/led/animation.py b/led/animation.py index 1269564..7b784bd 100755 --- a/led/animation.py +++ b/led/animation.py @@ -9,6 +9,7 @@ import string import json import time +import random # FIXME: Describe Layouts # FIXME: Delete this @@ -141,8 +142,69 @@ def led_test(self): time.sleep (1.2) self.clear() + def clamp(n, minn, maxn): + return max(min(maxn, n), minn) + + def run_flare(self): + NUM_SPARKS = 18/2 #// max number (could be NUM_LEDS / 2); + + my_row = "F" + + sparkPos = [] + sparkVel = [] + sparkCol = [] + flarePos = 0. + + gravity = -.004; # m/s/s + + flarePos = 0 + flareVel = random.randint(50,90) / 100. # trial and error to get reasonable range + brightness = 1. + + print ("Run flare") + + # initialize launch sparks + for i in range (0,5): + sparkPos[i] = 0. + sparkVel[i] = float(random.randint(1,255) / 255) * (flareVel / 5) + # random around 20% of flare velocity + sparkCol[i] = sparkVel[i] * 1000 + sparkCol[i] = self.clamp(sparkCol[i], 0, 255) + + # launch + self.clear() + while flareVel >= -.2: + # sparks + for i in range (0,5): + sparkPos[i] = sparkPos[i] + sparkVel[i] + sparkPos[i] = self.clamp(sparkPos[i], 0, 120) + sparkVel[i] = sparkVel[i] + gravity + sparkCol[i] = sparkCol[i] -.8 + sparkCol[i] = self.clamp(sparkCol[i], 0, 255) + + #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) + #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 + c = (100,100,0) + tmp_led = my_row + str (sparkPos[i]) + self.layout.set(self.MAPPING[tmp_led], c) + + + # flare + #leds[int(flarePos)] = CHSV(0, 0, int(brightness * 255)); + #FastLED.show(); + #FastLED.clear(); + self.layout.push_to_driver() + flarePos = flarePos + flareVel + flareVel = flareVel + gravity + brightness = brightness * .985 + + + def run_animation(self, run_options={}, **kwds): # FIXME: will it still work? + # The moonboard can serve a (x,y) = (11,18) --> 198 Pixel display + # Refs: + # - http://www.anirama.com/1000leds/1d-fireworks/ duration = 0.01 duration2 = duration * 10 @@ -160,6 +222,8 @@ def run_animation(self, run_options={}, **kwds): # FIXME: will it still work? time.sleep(duration2) self.clear() + + def display_holdset(self, holdset="Hold Set A", duration=10, **kwds): print ("Display holdset: " + str(holdset)) From 74fcd8095b78e32c815acd6c4a8b52c8e81fccd0 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:14:34 +0100 Subject: [PATCH 061/240] activate flare --- led/animation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 7b784bd..8c612d0 100755 --- a/led/animation.py +++ b/led/animation.py @@ -289,7 +289,8 @@ def step(self, amt=1): #MOONBOARD.display_holdset(args.holdset, args.duration) print("Run animation,") - MOONBOARD.run_animation() # FIXME + #MOONBOARD.run_animation() + MOONBOARD.run_flare() print(f"wait {args.duration} seconds,") time.sleep(args.duration) From 1e4e869734a9cc0eee59113e8fe0e8b1fcb7804f Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:16:41 +0100 Subject: [PATCH 062/240] fix --- led/animation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/led/animation.py b/led/animation.py index 8c612d0..7f178bd 100755 --- a/led/animation.py +++ b/led/animation.py @@ -150,9 +150,9 @@ def run_flare(self): my_row = "F" - sparkPos = [] - sparkVel = [] - sparkCol = [] + sparkPos = [0,0,0,0,0] + sparkVel = [0,0,0,0,0] + sparkCol = [0,0,0,0,0] flarePos = 0. gravity = -.004; # m/s/s From b95d2b06d19e5591cecce82b092eb5c6bc1b0848 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:17:33 +0100 Subject: [PATCH 063/240] fix --- led/animation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/led/animation.py b/led/animation.py index 7f178bd..d49436a 100755 --- a/led/animation.py +++ b/led/animation.py @@ -169,7 +169,7 @@ def run_flare(self): sparkVel[i] = float(random.randint(1,255) / 255) * (flareVel / 5) # random around 20% of flare velocity sparkCol[i] = sparkVel[i] * 1000 - sparkCol[i] = self.clamp(sparkCol[i], 0, 255) + sparkCol[i] = self.clamp(self, sparkCol[i], 0, 255) # launch self.clear() @@ -177,10 +177,10 @@ def run_flare(self): # sparks for i in range (0,5): sparkPos[i] = sparkPos[i] + sparkVel[i] - sparkPos[i] = self.clamp(sparkPos[i], 0, 120) + sparkPos[i] = self.clamp(self, sparkPos[i], 0, 120) sparkVel[i] = sparkVel[i] + gravity sparkCol[i] = sparkCol[i] -.8 - sparkCol[i] = self.clamp(sparkCol[i], 0, 255) + sparkCol[i] = self.clamp(self, sparkCol[i], 0, 255) #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 From 8e1151e8bc99080fc8c7945b76b78f3fa380ab22 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:18:24 +0100 Subject: [PATCH 064/240] fix --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index d49436a..edf2b50 100755 --- a/led/animation.py +++ b/led/animation.py @@ -142,7 +142,7 @@ def led_test(self): time.sleep (1.2) self.clear() - def clamp(n, minn, maxn): + def clamp(self, n, minn, maxn): return max(min(maxn, n), minn) def run_flare(self): From 9e6ca6ca44890fd4d5d90ff66d649b126da89ed9 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:19:33 +0100 Subject: [PATCH 065/240] fix --- led/animation.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/led/animation.py b/led/animation.py index edf2b50..8fd9a65 100755 --- a/led/animation.py +++ b/led/animation.py @@ -11,6 +11,10 @@ import time import random +def clamp(n, minn, maxn): + return max(min(maxn, n), minn) + + # FIXME: Describe Layouts # FIXME: Delete this LED_LAYOUT = { @@ -142,8 +146,7 @@ def led_test(self): time.sleep (1.2) self.clear() - def clamp(self, n, minn, maxn): - return max(min(maxn, n), minn) + def run_flare(self): NUM_SPARKS = 18/2 #// max number (could be NUM_LEDS / 2); @@ -169,7 +172,7 @@ def run_flare(self): sparkVel[i] = float(random.randint(1,255) / 255) * (flareVel / 5) # random around 20% of flare velocity sparkCol[i] = sparkVel[i] * 1000 - sparkCol[i] = self.clamp(self, sparkCol[i], 0, 255) + sparkCol[i] = clamp(sparkCol[i], 0, 255) # launch self.clear() @@ -177,10 +180,10 @@ def run_flare(self): # sparks for i in range (0,5): sparkPos[i] = sparkPos[i] + sparkVel[i] - sparkPos[i] = self.clamp(self, sparkPos[i], 0, 120) + sparkPos[i] = clamp(sparkPos[i], 0, 120) sparkVel[i] = sparkVel[i] + gravity sparkCol[i] = sparkCol[i] -.8 - sparkCol[i] = self.clamp(self, sparkCol[i], 0, 255) + sparkCol[i] = clamp(sparkCol[i], 0, 255) #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 From 1b6bac6bfa0e0f8f16fc6044f6b2441032427c2b Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:20:13 +0100 Subject: [PATCH 066/240] fix --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 8fd9a65..e1ca4a9 100755 --- a/led/animation.py +++ b/led/animation.py @@ -188,7 +188,7 @@ def run_flare(self): #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 c = (100,100,0) - tmp_led = my_row + str (sparkPos[i]) + tmp_led = my_row + str (int (sparkPos[i])) self.layout.set(self.MAPPING[tmp_led], c) From f7c5d255ad1e58a3abcd95a61561648832e25220 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:21:47 +0100 Subject: [PATCH 067/240] contrain position --- led/animation.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index e1ca4a9..eea554a 100755 --- a/led/animation.py +++ b/led/animation.py @@ -151,7 +151,7 @@ def led_test(self): def run_flare(self): NUM_SPARKS = 18/2 #// max number (could be NUM_LEDS / 2); - my_row = "F" + my_col = "F" sparkPos = [0,0,0,0,0] sparkVel = [0,0,0,0,0] @@ -187,8 +187,9 @@ def run_flare(self): #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 + tmp_row = clamp(int (sparkPos[i]), 0, 18) c = (100,100,0) - tmp_led = my_row + str (int (sparkPos[i])) + tmp_led = my_col + str (tmp_row) self.layout.set(self.MAPPING[tmp_led], c) From 13df6bccbbe3c817334155bfda6bf88a37d55efc Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:22:09 +0100 Subject: [PATCH 068/240] fix --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index eea554a..e341dad 100755 --- a/led/animation.py +++ b/led/animation.py @@ -187,7 +187,7 @@ def run_flare(self): #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 - tmp_row = clamp(int (sparkPos[i]), 0, 18) + tmp_row = clamp(int (sparkPos[i]), 1, 18) c = (100,100,0) tmp_led = my_col + str (tmp_row) self.layout.set(self.MAPPING[tmp_led], c) From 18b461e91beea3ba5654cb0d7f38d53a1e539151 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:23:04 +0100 Subject: [PATCH 069/240] debugging --- led/animation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/led/animation.py b/led/animation.py index e341dad..2ce01e4 100755 --- a/led/animation.py +++ b/led/animation.py @@ -178,6 +178,7 @@ def run_flare(self): self.clear() while flareVel >= -.2: # sparks + print ("Run spark") for i in range (0,5): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0, 120) From 3bcad62dc81b0c07880312294064826b85b85b86 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:24:53 +0100 Subject: [PATCH 070/240] color test --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 2ce01e4..1af4eb3 100755 --- a/led/animation.py +++ b/led/animation.py @@ -189,7 +189,7 @@ def run_flare(self): #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 tmp_row = clamp(int (sparkPos[i]), 1, 18) - c = (100,100,0) + c = (sparkCol[i],0,0) tmp_led = my_col + str (tmp_row) self.layout.set(self.MAPPING[tmp_led], c) From f77f84ae8fc295ea4286cf12c36b5c3fca4bc07f Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:26:01 +0100 Subject: [PATCH 071/240] debugging --- led/animation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/led/animation.py b/led/animation.py index 1af4eb3..725d83b 100755 --- a/led/animation.py +++ b/led/animation.py @@ -150,6 +150,7 @@ def led_test(self): def run_flare(self): NUM_SPARKS = 18/2 #// max number (could be NUM_LEDS / 2); + # FIXME my_col = "F" @@ -191,6 +192,7 @@ def run_flare(self): tmp_row = clamp(int (sparkPos[i]), 1, 18) c = (sparkCol[i],0,0) tmp_led = my_col + str (tmp_row) + print ("Spark position "+str(tmp_led)) self.layout.set(self.MAPPING[tmp_led], c) From 282a4cf316eb869ee3cb069c08bd06c1d633405f Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:41:40 +0100 Subject: [PATCH 072/240] debug --- led/animation.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/led/animation.py b/led/animation.py index 725d83b..53cf8e7 100755 --- a/led/animation.py +++ b/led/animation.py @@ -149,9 +149,10 @@ def led_test(self): def run_flare(self): - NUM_SPARKS = 18/2 #// max number (could be NUM_LEDS / 2); + NUM_LEDS = 18 + NUM_SPARKS = NUM_LEDS/2 #// max number (could be NUM_LEDS / 2); + # FIXME - my_col = "F" sparkPos = [0,0,0,0,0] @@ -182,7 +183,7 @@ def run_flare(self): print ("Run spark") for i in range (0,5): sparkPos[i] = sparkPos[i] + sparkVel[i] - sparkPos[i] = clamp(sparkPos[i], 0, 120) + sparkPos[i] = clamp(sparkPos[i], 0, NUM_LEDS) sparkVel[i] = sparkVel[i] + gravity sparkCol[i] = sparkCol[i] -.8 sparkCol[i] = clamp(sparkCol[i], 0, 255) @@ -192,7 +193,7 @@ def run_flare(self): tmp_row = clamp(int (sparkPos[i]), 1, 18) c = (sparkCol[i],0,0) tmp_led = my_col + str (tmp_row) - print ("Spark position "+str(tmp_led)) + print ("Spark position "+str(tmp_led)+" with "+sparkPos[i]) self.layout.set(self.MAPPING[tmp_led], c) From c6986d78f2c664512be7ee9445414def7532e489 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:42:07 +0100 Subject: [PATCH 073/240] fix --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 53cf8e7..43b097c 100755 --- a/led/animation.py +++ b/led/animation.py @@ -193,7 +193,7 @@ def run_flare(self): tmp_row = clamp(int (sparkPos[i]), 1, 18) c = (sparkCol[i],0,0) tmp_led = my_col + str (tmp_row) - print ("Spark position "+str(tmp_led)+" with "+sparkPos[i]) + print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])) self.layout.set(self.MAPPING[tmp_led], c) From e7283fb0788b1cdfc9b6ea26aad4f8112f17094c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:43:47 +0100 Subject: [PATCH 074/240] scaling --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 43b097c..541c56c 100755 --- a/led/animation.py +++ b/led/animation.py @@ -190,7 +190,7 @@ def run_flare(self): #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 - tmp_row = clamp(int (sparkPos[i]), 1, 18) + tmp_row = clamp(int (sparkPos[i]*100.), 1, 18) c = (sparkCol[i],0,0) tmp_led = my_col + str (tmp_row) print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])) From 7aae207bd0a06dda961214593ced13224bdc4478 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:44:49 +0100 Subject: [PATCH 075/240] no bright --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 541c56c..c6a0e28 100755 --- a/led/animation.py +++ b/led/animation.py @@ -204,7 +204,7 @@ def run_flare(self): self.layout.push_to_driver() flarePos = flarePos + flareVel flareVel = flareVel + gravity - brightness = brightness * .985 + # FIXME brightness = brightness * .985 From 6d73c6a325046a476e5bf257cb09298c0550a5f1 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:45:55 +0100 Subject: [PATCH 076/240] debug --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index c6a0e28..b35479a 100755 --- a/led/animation.py +++ b/led/animation.py @@ -180,7 +180,7 @@ def run_flare(self): self.clear() while flareVel >= -.2: # sparks - print ("Run spark") + print ("Run spark with "+str(flareVel)) for i in range (0,5): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0, NUM_LEDS) From 0dad47c663fd1077d599ef3da8f70ffab7d4ddbb Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:46:58 +0100 Subject: [PATCH 077/240] scaling --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index b35479a..aab402a 100755 --- a/led/animation.py +++ b/led/animation.py @@ -163,7 +163,7 @@ def run_flare(self): gravity = -.004; # m/s/s flarePos = 0 - flareVel = random.randint(50,90) / 100. # trial and error to get reasonable range + flareVel = random.randint(50,90) #/ 100. # trial and error to get reasonable range brightness = 1. print ("Run flare") From fc754870a96614861fdf1fe47a624bfe0912ca0d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:47:48 +0100 Subject: [PATCH 078/240] scaling --- led/animation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index aab402a..7328e85 100755 --- a/led/animation.py +++ b/led/animation.py @@ -160,10 +160,10 @@ def run_flare(self): sparkCol = [0,0,0,0,0] flarePos = 0. - gravity = -.004; # m/s/s + gravity = -.004 * 100 # m/s/s flarePos = 0 - flareVel = random.randint(50,90) #/ 100. # trial and error to get reasonable range + flareVel = random.randint(50,90) / 100. # trial and error to get reasonable range brightness = 1. print ("Run flare") From 5fbbec3fd57a8f02c4f655931afd2813dfd0207f Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:48:38 +0100 Subject: [PATCH 079/240] scaling --- led/animation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index 7328e85..8770a7b 100755 --- a/led/animation.py +++ b/led/animation.py @@ -160,7 +160,7 @@ def run_flare(self): sparkCol = [0,0,0,0,0] flarePos = 0. - gravity = -.004 * 100 # m/s/s + gravity = -.004 * 10 # m/s/s flarePos = 0 flareVel = random.randint(50,90) / 100. # trial and error to get reasonable range @@ -190,7 +190,7 @@ def run_flare(self): #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 - tmp_row = clamp(int (sparkPos[i]*100.), 1, 18) + tmp_row = clamp(int (sparkPos[i]*10.), 1, 18) c = (sparkCol[i],0,0) tmp_led = my_col + str (tmp_row) print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])) From 75153a66a93b0f3600dbf3bf73f963858d1d4056 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:50:03 +0100 Subject: [PATCH 080/240] color --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 8770a7b..b2e8fa4 100755 --- a/led/animation.py +++ b/led/animation.py @@ -185,7 +185,7 @@ def run_flare(self): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0, NUM_LEDS) sparkVel[i] = sparkVel[i] + gravity - sparkCol[i] = sparkCol[i] -.8 + sparkCol[i] = sparkCol[i] # FIXME -.8 sparkCol[i] = clamp(sparkCol[i], 0, 255) #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) From e563f47a066d2782bad6d722291222b5ef1fcc47 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:51:33 +0100 Subject: [PATCH 081/240] float --- led/animation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index b2e8fa4..befffbc 100755 --- a/led/animation.py +++ b/led/animation.py @@ -183,10 +183,10 @@ def run_flare(self): print ("Run spark with "+str(flareVel)) for i in range (0,5): sparkPos[i] = sparkPos[i] + sparkVel[i] - sparkPos[i] = clamp(sparkPos[i], 0, NUM_LEDS) + sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) sparkVel[i] = sparkVel[i] + gravity sparkCol[i] = sparkCol[i] # FIXME -.8 - sparkCol[i] = clamp(sparkCol[i], 0, 255) + sparkCol[i] = clamp(sparkCol[i], 0.0, 255.0) #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 From c9f6c1c5ab910400bc5371e8504fd21b6d9c0329 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 13:53:15 +0100 Subject: [PATCH 082/240] float --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index befffbc..ba48902 100755 --- a/led/animation.py +++ b/led/animation.py @@ -190,7 +190,7 @@ def run_flare(self): #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 - tmp_row = clamp(int (sparkPos[i]*10.), 1, 18) + tmp_row = clamp(int (sparkPos[i]*10.), 1.0, 18.0) c = (sparkCol[i],0,0) tmp_led = my_col + str (tmp_row) print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])) From c674418adc915804a6fca653784da9654c85cd0d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:01:28 +0100 Subject: [PATCH 083/240] debug --- led/animation.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/led/animation.py b/led/animation.py index ba48902..e2bcaa5 100755 --- a/led/animation.py +++ b/led/animation.py @@ -150,38 +150,36 @@ def led_test(self): def run_flare(self): NUM_LEDS = 18 - NUM_SPARKS = NUM_LEDS/2 #// max number (could be NUM_LEDS / 2); + #NUM_SPARKS = NUM_LEDS/2 #// max number (could be NUM_LEDS / 2); - # FIXME - my_col = "F" + my_col = "F" # FIXME - sparkPos = [0,0,0,0,0] - sparkVel = [0,0,0,0,0] - sparkCol = [0,0,0,0,0] + sparkPos = [0,0,0] # width of flare: 3 LED + sparkVel = [0,0,0] + sparkCol = [0,0,0] + flarePos = 0. - gravity = -.004 * 10 # m/s/s - - flarePos = 0 flareVel = random.randint(50,90) / 100. # trial and error to get reasonable range brightness = 1. - print ("Run flare") - # initialize launch sparks - for i in range (0,5): + print ("Init launch sparks") + for i in range (0,2): sparkPos[i] = 0. - sparkVel[i] = float(random.randint(1,255) / 255) * (flareVel / 5) + sparkVel[i] = flareVel #float(random.randint(1,255) / 255) * (flareVel / 5) # random around 20% of flare velocity sparkCol[i] = sparkVel[i] * 1000 sparkCol[i] = clamp(sparkCol[i], 0, 255) + print (str(i)+ " with "+str(sparkVel[i])+" and "+str(sparkCol[i])) + print ("Run flare") # launch self.clear() while flareVel >= -.2: # sparks print ("Run spark with "+str(flareVel)) - for i in range (0,5): + for i in range (0,2): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) sparkVel[i] = sparkVel[i] + gravity From ef876a575d4cc4df186997f0718b7b83bb5bca99 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:01:59 +0100 Subject: [PATCH 084/240] fix --- led/animation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index e2bcaa5..a9c6f9f 100755 --- a/led/animation.py +++ b/led/animation.py @@ -165,7 +165,7 @@ def run_flare(self): # initialize launch sparks print ("Init launch sparks") - for i in range (0,2): + for i in range (0,3): sparkPos[i] = 0. sparkVel[i] = flareVel #float(random.randint(1,255) / 255) * (flareVel / 5) # random around 20% of flare velocity @@ -179,7 +179,7 @@ def run_flare(self): while flareVel >= -.2: # sparks print ("Run spark with "+str(flareVel)) - for i in range (0,2): + for i in range (0,3): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) sparkVel[i] = sparkVel[i] + gravity From 525c127dfc06c4fad73e5f9c4016dc01e316e0d5 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:03:04 +0100 Subject: [PATCH 085/240] fix --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index a9c6f9f..363e114 100755 --- a/led/animation.py +++ b/led/animation.py @@ -188,7 +188,7 @@ def run_flare(self): #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 - tmp_row = clamp(int (sparkPos[i]*10.), 1.0, 18.0) + tmp_row = clamp(int (sparkPos[i]), 1, 18) c = (sparkCol[i],0,0) tmp_led = my_col + str (tmp_row) print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])) From 9f0f4923e181b54e81207dffa7849fc6c978e490 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:04:17 +0100 Subject: [PATCH 086/240] debug --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 363e114..5892f32 100755 --- a/led/animation.py +++ b/led/animation.py @@ -178,7 +178,7 @@ def run_flare(self): self.clear() while flareVel >= -.2: # sparks - print ("Run spark with "+str(flareVel)) + print ("Run spark with velocity "+str(flareVel)) for i in range (0,3): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) From 44f98d27241391244439014dc4b222067415e8ca Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:05:18 +0100 Subject: [PATCH 087/240] clear --- led/animation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/led/animation.py b/led/animation.py index 5892f32..d054695 100755 --- a/led/animation.py +++ b/led/animation.py @@ -179,6 +179,7 @@ def run_flare(self): while flareVel >= -.2: # sparks print ("Run spark with velocity "+str(flareVel)) + self.clear() for i in range (0,3): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) From 07b409aa04f347e53dfca6c2a6ad419a35639886 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:07:53 +0100 Subject: [PATCH 088/240] led off --- led/animation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index d054695..7a42914 100755 --- a/led/animation.py +++ b/led/animation.py @@ -179,7 +179,10 @@ def run_flare(self): while flareVel >= -.2: # sparks print ("Run spark with velocity "+str(flareVel)) - self.clear() + for i in range (1,NUM_LEDS+1): + tmp_led = my_col + str (i) + self.layout.set(self.MAPPING[tmp_led], (0,0,0)) + for i in range (0,3): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) From 4e1aefb714b27cc86ea6f8afd9c740a7981f0b99 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:10:44 +0100 Subject: [PATCH 089/240] fluct --- led/animation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index 7a42914..f442bb4 100755 --- a/led/animation.py +++ b/led/animation.py @@ -167,7 +167,7 @@ def run_flare(self): print ("Init launch sparks") for i in range (0,3): sparkPos[i] = 0. - sparkVel[i] = flareVel #float(random.randint(1,255) / 255) * (flareVel / 5) + sparkVel[i] = flareVel * float(random.randint(80,120) / 100) # * (flareVel / 5) # random around 20% of flare velocity sparkCol[i] = sparkVel[i] * 1000 sparkCol[i] = clamp(sparkCol[i], 0, 255) @@ -182,7 +182,7 @@ def run_flare(self): for i in range (1,NUM_LEDS+1): tmp_led = my_col + str (i) self.layout.set(self.MAPPING[tmp_led], (0,0,0)) - + for i in range (0,3): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) From 6628618e32331a81d464e9598dc27be76bf36b6e Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:11:57 +0100 Subject: [PATCH 090/240] color --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index f442bb4..d6dc21b 100755 --- a/led/animation.py +++ b/led/animation.py @@ -187,7 +187,7 @@ def run_flare(self): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) sparkVel[i] = sparkVel[i] + gravity - sparkCol[i] = sparkCol[i] # FIXME -.8 + sparkCol[i] = sparkCol[i] -.8 # FIXME sparkCol[i] = clamp(sparkCol[i], 0.0, 255.0) #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) From e0de2fd03f4a927352b016bfd383f6b0498c5770 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:14:21 +0100 Subject: [PATCH 091/240] scaling --- led/animation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index d6dc21b..d6b22f9 100755 --- a/led/animation.py +++ b/led/animation.py @@ -179,6 +179,8 @@ def run_flare(self): while flareVel >= -.2: # sparks print ("Run spark with velocity "+str(flareVel)) + + # Disable all led in column for i in range (1,NUM_LEDS+1): tmp_led = my_col + str (i) self.layout.set(self.MAPPING[tmp_led], (0,0,0)) @@ -187,7 +189,7 @@ def run_flare(self): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) sparkVel[i] = sparkVel[i] + gravity - sparkCol[i] = sparkCol[i] -.8 # FIXME + sparkCol[i] = sparkCol[i] -.8*3 # FIXME sparkCol[i] = clamp(sparkCol[i], 0.0, 255.0) #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) From 1c6461582e54aad6aad811df86854335e1b4903c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:15:05 +0100 Subject: [PATCH 092/240] scaling --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index d6b22f9..280ee96 100755 --- a/led/animation.py +++ b/led/animation.py @@ -189,7 +189,7 @@ def run_flare(self): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) sparkVel[i] = sparkVel[i] + gravity - sparkCol[i] = sparkCol[i] -.8*3 # FIXME + sparkCol[i] = sparkCol[i] -.8*5 # FIXME sparkCol[i] = clamp(sparkCol[i], 0.0, 255.0) #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) From f80a9b7e152fa1e8f1f1915debbc9ae46aecb139 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:16:08 +0100 Subject: [PATCH 093/240] debug --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 280ee96..7468181 100755 --- a/led/animation.py +++ b/led/animation.py @@ -197,7 +197,7 @@ def run_flare(self): tmp_row = clamp(int (sparkPos[i]), 1, 18) c = (sparkCol[i],0,0) tmp_led = my_col + str (tmp_row) - print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])) + print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])+" and "+str(sparkCol[i])) self.layout.set(self.MAPPING[tmp_led], c) From 453d19dba604208ab47e9b422783e224b69bc03d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:16:21 +0100 Subject: [PATCH 094/240] brightness --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 7468181..a36c246 100755 --- a/led/animation.py +++ b/led/animation.py @@ -208,7 +208,7 @@ def run_flare(self): self.layout.push_to_driver() flarePos = flarePos + flareVel flareVel = flareVel + gravity - # FIXME brightness = brightness * .985 + brightness = brightness * .985 From a1ab7667e141f02dcab7663e4a5af8a1536debee Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:17:37 +0100 Subject: [PATCH 095/240] scaling --- led/animation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index a36c246..12fccdd 100755 --- a/led/animation.py +++ b/led/animation.py @@ -189,7 +189,7 @@ def run_flare(self): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) sparkVel[i] = sparkVel[i] + gravity - sparkCol[i] = sparkCol[i] -.8*5 # FIXME + sparkCol[i] = sparkCol[i] -.8*7 # FIXME sparkCol[i] = clamp(sparkCol[i], 0.0, 255.0) #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) @@ -208,7 +208,7 @@ def run_flare(self): self.layout.push_to_driver() flarePos = flarePos + flareVel flareVel = flareVel + gravity - brightness = brightness * .985 + brightness = brightness * 0.92 From e4ed52a1f6db5de767e7956d539ed38966828641 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:18:39 +0100 Subject: [PATCH 096/240] speed --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 12fccdd..5f2da1f 100755 --- a/led/animation.py +++ b/led/animation.py @@ -160,7 +160,7 @@ def run_flare(self): flarePos = 0. gravity = -.004 * 10 # m/s/s - flareVel = random.randint(50,90) / 100. # trial and error to get reasonable range + flareVel = random.randint(50,90) / 100. *6 # trial and error to get reasonable range brightness = 1. # initialize launch sparks From e654a382654cb0ae8399d9a4b4efdbe37cf1398f Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:19:16 +0100 Subject: [PATCH 097/240] scaling --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 5f2da1f..a9b47b5 100755 --- a/led/animation.py +++ b/led/animation.py @@ -160,7 +160,7 @@ def run_flare(self): flarePos = 0. gravity = -.004 * 10 # m/s/s - flareVel = random.randint(50,90) / 100. *6 # trial and error to get reasonable range + flareVel = random.randint(50,90) / 100. *2 # trial and error to get reasonable range brightness = 1. # initialize launch sparks From 8a33da4cd313004150f15c414fd74327d319761e Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:20:00 +0100 Subject: [PATCH 098/240] scaling --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index a9b47b5..d48e115 100755 --- a/led/animation.py +++ b/led/animation.py @@ -160,7 +160,7 @@ def run_flare(self): flarePos = 0. gravity = -.004 * 10 # m/s/s - flareVel = random.randint(50,90) / 100. *2 # trial and error to get reasonable range + flareVel = random.randint(50,90) / 100. *1.5 # trial and error to get reasonable range brightness = 1. # initialize launch sparks From f505d4c202b51e26c735d5a1da7fee0d465da958 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:20:42 +0100 Subject: [PATCH 099/240] scaling --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index d48e115..f7cb1b6 100755 --- a/led/animation.py +++ b/led/animation.py @@ -160,7 +160,7 @@ def run_flare(self): flarePos = 0. gravity = -.004 * 10 # m/s/s - flareVel = random.randint(50,90) / 100. *1.5 # trial and error to get reasonable range + flareVel = random.randint(50,90) / 100. *1.7 # trial and error to get reasonable range brightness = 1. # initialize launch sparks From 2af991f887114e16448c67795df6082bf5dc518d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:21:22 +0100 Subject: [PATCH 100/240] scaling --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index f7cb1b6..7043b35 100755 --- a/led/animation.py +++ b/led/animation.py @@ -160,7 +160,7 @@ def run_flare(self): flarePos = 0. gravity = -.004 * 10 # m/s/s - flareVel = random.randint(50,90) / 100. *1.7 # trial and error to get reasonable range + flareVel = random.randint(50,90) / 100. *1.55 # trial and error to get reasonable range brightness = 1. # initialize launch sparks From cb72cae3013b1db7711d7bf42667116bd6adcec0 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:25:21 +0100 Subject: [PATCH 101/240] flare --- led/animation.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index 7043b35..7ca20d1 100755 --- a/led/animation.py +++ b/led/animation.py @@ -203,8 +203,11 @@ def run_flare(self): # flare #leds[int(flarePos)] = CHSV(0, 0, int(brightness * 255)); - #FastLED.show(); - #FastLED.clear(); + tmp_row = clamp(int (flarePos), 1, 18) + tmp_led = my_col + str (tmp_row) + flareCol = (255.,0,0) + print ("Flare position "+str(tmp_led)+" with "+str(flarePos)+" and "+str(flareCol)) + self.layout.set(self.MAPPING[tmp_led], flareCol) self.layout.push_to_driver() flarePos = flarePos + flareVel flareVel = flareVel + gravity From 6b260d7684ec8cf0c50dbc962f889bac5bd565c4 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:26:34 +0100 Subject: [PATCH 102/240] multicol --- led/animation.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/led/animation.py b/led/animation.py index 7ca20d1..d77e24c 100755 --- a/led/animation.py +++ b/led/animation.py @@ -148,12 +148,10 @@ def led_test(self): - def run_flare(self): - NUM_LEDS = 18 + def run_flare(self, my_col="F"): + NUM_LEDS = 18 # FIXME #NUM_SPARKS = NUM_LEDS/2 #// max number (could be NUM_LEDS / 2); - my_col = "F" # FIXME - sparkPos = [0,0,0] # width of flare: 3 LED sparkVel = [0,0,0] sparkCol = [0,0,0] @@ -305,7 +303,8 @@ def step(self, amt=1): print("Run animation,") #MOONBOARD.run_animation() - MOONBOARD.run_flare() + MOONBOARD.run_flare(my_col="F") + MOONBOARD.run_flare(my_col="A") print(f"wait {args.duration} seconds,") time.sleep(args.duration) From 949b696a169efab657289cc426f46293c23b9af0 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:28:02 +0100 Subject: [PATCH 103/240] fixmes --- led/animation.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/led/animation.py b/led/animation.py index d77e24c..b076c50 100755 --- a/led/animation.py +++ b/led/animation.py @@ -189,21 +189,17 @@ def run_flare(self, my_col="F"): sparkVel[i] = sparkVel[i] + gravity sparkCol[i] = sparkCol[i] -.8*7 # FIXME sparkCol[i] = clamp(sparkCol[i], 0.0, 255.0) - - #leds[int(sparkPos[i])] = HeatColor(sparkCol[i]) - #leds[int(sparkPos[i])] %= 50 # reduce brightness to 50/255 - tmp_row = clamp(int (sparkPos[i]), 1, 18) - c = (sparkCol[i],0,0) + tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) + c = (sparkCol[i],0,0) # FIXME: cleanup tmp_led = my_col + str (tmp_row) print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])+" and "+str(sparkCol[i])) self.layout.set(self.MAPPING[tmp_led], c) # flare - #leds[int(flarePos)] = CHSV(0, 0, int(brightness * 255)); - tmp_row = clamp(int (flarePos), 1, 18) + tmp_row = clamp(int (flarePos), 1, NUM_LEDS) tmp_led = my_col + str (tmp_row) - flareCol = (255.,0,0) + flareCol = (255.,0,0) # FIXME print ("Flare position "+str(tmp_led)+" with "+str(flarePos)+" and "+str(flareCol)) self.layout.set(self.MAPPING[tmp_led], flareCol) self.layout.push_to_driver() From b282ce678148c8bf35e423a3578adc9b2dee03f2 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:37:11 +0100 Subject: [PATCH 104/240] setup explosion --- led/animation.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/led/animation.py b/led/animation.py index b076c50..1618035 100755 --- a/led/animation.py +++ b/led/animation.py @@ -152,9 +152,9 @@ def run_flare(self, my_col="F"): NUM_LEDS = 18 # FIXME #NUM_SPARKS = NUM_LEDS/2 #// max number (could be NUM_LEDS / 2); - sparkPos = [0,0,0] # width of flare: 3 LED - sparkVel = [0,0,0] - sparkCol = [0,0,0] + sparkPos = [0,0,0,0,0,0] # width of flare: 3 LED + sparkVel = [0,0,0,0,0,0] + sparkCol = [0,0,0,0,0,0] flarePos = 0. gravity = -.004 * 10 # m/s/s @@ -163,7 +163,7 @@ def run_flare(self, my_col="F"): # initialize launch sparks print ("Init launch sparks") - for i in range (0,3): + for i in range (0,3): # FIXME nSparks sparkPos[i] = 0. sparkVel[i] = flareVel * float(random.randint(80,120) / 100) # * (flareVel / 5) # random around 20% of flare velocity @@ -171,8 +171,8 @@ def run_flare(self, my_col="F"): sparkCol[i] = clamp(sparkCol[i], 0, 255) print (str(i)+ " with "+str(sparkVel[i])+" and "+str(sparkCol[i])) - print ("Run flare") - # launch + # Phase 1: Flare + print ("Launch flare") self.clear() while flareVel >= -.2: # sparks @@ -207,8 +207,19 @@ def run_flare(self, my_col="F"): flareVel = flareVel + gravity brightness = brightness * 0.92 + # Phase 2: Explosion + print ("Run explosion") + nSparks = int (flarePos / 2) + # Initialize Sparks + for i in range (0,nSparks): + sparkPos[i] = flarePos + sparkVel[i] = float(random.randint(-100,100) / 100) # from -1 to 1 + sparkCol[i] = abs(sparkVel[i]) * 500 # set colors before scaling velocity to keep them bright + sparkCol[i] = clamp(sparkCol[i], 0., 255.) + sparkVel[i] = sparkVel[i] * flarePos / NUM_LEDS # proportional to height + sparkCol[0] = 255 # // this will be our known spark def run_animation(self, run_options={}, **kwds): # FIXME: will it still work? # The moonboard can serve a (x,y) = (11,18) --> 198 Pixel display From f565c12f0c46c3fb9856663469381af06146049d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:41:17 +0100 Subject: [PATCH 105/240] explosion --- led/animation.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/led/animation.py b/led/animation.py index 1618035..1eb5048 100755 --- a/led/animation.py +++ b/led/animation.py @@ -220,6 +220,31 @@ def run_flare(self, my_col="F"): sparkVel[i] = sparkVel[i] * flarePos / NUM_LEDS # proportional to height sparkCol[0] = 255 # // this will be our known spark + dying_gravity = gravity + c1 = 120 + c2 = 50 + + while sparkCol[0] > c2/128: # as long as our known spark is lit, work with all the sparks + # Disable all led in column + for i in range (1,NUM_LEDS+1): + tmp_led = my_col + str (i) + self.layout.set(self.MAPPING[tmp_led], (0,0,0)) + + for i in range (0,nSparks): + sparkPos[i] = sparkPos[i] + sparkVel[i] + sparkPos[i] = clamp(sparkPos[i], 0, NUM_LEDS) + sparkVel[i] = sparkVel[i] + dying_gravity + sparkCol[i] = sparkCol[i] * .99 + sparkCol[i] = clamp(sparkCol[i], 0, 255) # // red cross dissolve + if(sparkCol[i] > c1): #// fade white to yellow + leds[int(sparkPos[i])] = CRGB(255, 255, (255 * (sparkCol[i] - c1)) / (255 - c1)) + elif sparkCol[i] < c2: # // fade from red to black + leds[int(sparkPos[i])] = CRGB((255 * sparkCol[i]) / c2, 0, 0) + else: # // fade from yellow to red + leds[int(sparkPos[i])] = CRGB(255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) + + dying_gravity = dying_gravity * .995 #// as sparks burn out they fall slower + self.layout.push_to_driver() def run_animation(self, run_options={}, **kwds): # FIXME: will it still work? # The moonboard can serve a (x,y) = (11,18) --> 198 Pixel display From 2a4252efbe86ef66eec05531ea1acf024aaa9e1d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:43:44 +0100 Subject: [PATCH 106/240] display --- led/animation.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/led/animation.py b/led/animation.py index 1eb5048..14f7b41 100755 --- a/led/animation.py +++ b/led/animation.py @@ -237,12 +237,18 @@ def run_flare(self, my_col="F"): sparkCol[i] = sparkCol[i] * .99 sparkCol[i] = clamp(sparkCol[i], 0, 255) # // red cross dissolve if(sparkCol[i] > c1): #// fade white to yellow - leds[int(sparkPos[i])] = CRGB(255, 255, (255 * (sparkCol[i] - c1)) / (255 - c1)) + c = (255, 255, (255 * (sparkCol[i] - c1)) / (255 - c1)) + tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) + self.layout.set(self.MAPPING[tmp_led], c) elif sparkCol[i] < c2: # // fade from red to black - leds[int(sparkPos[i])] = CRGB((255 * sparkCol[i]) / c2, 0, 0) + c = ((255 * sparkCol[i]) / c2, 0, 0) + tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) + self.layout.set(self.MAPPING[tmp_led], c) else: # // fade from yellow to red - leds[int(sparkPos[i])] = CRGB(255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) - + c = (255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) + tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) + self.layout.set(self.MAPPING[tmp_led], c) + dying_gravity = dying_gravity * .995 #// as sparks burn out they fall slower self.layout.push_to_driver() From f06649a7baca6dba0a04a0d8113af4cacf34fdf5 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:44:33 +0100 Subject: [PATCH 107/240] coord --- led/animation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 14f7b41..f65fe65 100755 --- a/led/animation.py +++ b/led/animation.py @@ -239,16 +239,19 @@ def run_flare(self, my_col="F"): if(sparkCol[i] > c1): #// fade white to yellow c = (255, 255, (255 * (sparkCol[i] - c1)) / (255 - c1)) tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) + tmp_led = my_col + str (tmp_row) self.layout.set(self.MAPPING[tmp_led], c) elif sparkCol[i] < c2: # // fade from red to black c = ((255 * sparkCol[i]) / c2, 0, 0) tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) + tmp_led = my_col + str (tmp_row) self.layout.set(self.MAPPING[tmp_led], c) else: # // fade from yellow to red c = (255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) + tmp_led = my_col + str (tmp_row) self.layout.set(self.MAPPING[tmp_led], c) - + dying_gravity = dying_gravity * .995 #// as sparks burn out they fall slower self.layout.push_to_driver() From 1352db5199c92c6cc9bf3aabbfca944f623339f3 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:45:21 +0100 Subject: [PATCH 108/240] fix --- led/animation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/led/animation.py b/led/animation.py index f65fe65..791a89d 100755 --- a/led/animation.py +++ b/led/animation.py @@ -204,6 +204,7 @@ def run_flare(self, my_col="F"): self.layout.set(self.MAPPING[tmp_led], flareCol) self.layout.push_to_driver() flarePos = flarePos + flareVel + flarePos = clamp(flarePos, 0, NUM_LEDS) flareVel = flareVel + gravity brightness = brightness * 0.92 From bf46541732c33aea7b069118116dec9e64beef2c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:46:23 +0100 Subject: [PATCH 109/240] debugging --- led/animation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/led/animation.py b/led/animation.py index 791a89d..f1b4db7 100755 --- a/led/animation.py +++ b/led/animation.py @@ -226,6 +226,8 @@ def run_flare(self, my_col="F"): c2 = 50 while sparkCol[0] > c2/128: # as long as our known spark is lit, work with all the sparks + print ("Run spark with reference spark lit "+str(sparkCol[0])) + # Disable all led in column for i in range (1,NUM_LEDS+1): tmp_led = my_col + str (i) From 0ea66d50282506e89acace148ab5f66fb70e6c61 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:49:28 +0100 Subject: [PATCH 110/240] debugging --- led/animation.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/led/animation.py b/led/animation.py index f1b4db7..6b79e88 100755 --- a/led/animation.py +++ b/led/animation.py @@ -239,21 +239,20 @@ def run_flare(self, my_col="F"): sparkVel[i] = sparkVel[i] + dying_gravity sparkCol[i] = sparkCol[i] * .99 sparkCol[i] = clamp(sparkCol[i], 0, 255) # // red cross dissolve + + c = (0,0,0) + tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) + tmp_led = my_col + str (tmp_row) if(sparkCol[i] > c1): #// fade white to yellow c = (255, 255, (255 * (sparkCol[i] - c1)) / (255 - c1)) - tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) - tmp_led = my_col + str (tmp_row) - self.layout.set(self.MAPPING[tmp_led], c) elif sparkCol[i] < c2: # // fade from red to black c = ((255 * sparkCol[i]) / c2, 0, 0) - tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) - tmp_led = my_col + str (tmp_row) - self.layout.set(self.MAPPING[tmp_led], c) else: # // fade from yellow to red - c = (255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) - tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) - tmp_led = my_col + str (tmp_row) - self.layout.set(self.MAPPING[tmp_led], c) + c = (255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) + + print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])+" and "+str(c)) + + self.layout.set(self.MAPPING[tmp_led], c) dying_gravity = dying_gravity * .995 #// as sparks burn out they fall slower self.layout.push_to_driver() From 541003cba986de538a02ba088e3b60065f734b61 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:50:34 +0100 Subject: [PATCH 111/240] scaling --- led/animation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index 6b79e88..11bde06 100755 --- a/led/animation.py +++ b/led/animation.py @@ -237,7 +237,7 @@ def run_flare(self, my_col="F"): sparkPos[i] = sparkPos[i] + sparkVel[i] sparkPos[i] = clamp(sparkPos[i], 0, NUM_LEDS) sparkVel[i] = sparkVel[i] + dying_gravity - sparkCol[i] = sparkCol[i] * .99 + sparkCol[i] = sparkCol[i] * .9 # FIXME sparkCol[i] = clamp(sparkCol[i], 0, 255) # // red cross dissolve c = (0,0,0) @@ -251,7 +251,7 @@ def run_flare(self, my_col="F"): c = (255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])+" and "+str(c)) - + self.layout.set(self.MAPPING[tmp_led], c) dying_gravity = dying_gravity * .995 #// as sparks burn out they fall slower From 5423a154effca8ab79e9cb571a903857265e4092 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:52:09 +0100 Subject: [PATCH 112/240] limits --- led/animation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/led/animation.py b/led/animation.py index 11bde06..549a38f 100755 --- a/led/animation.py +++ b/led/animation.py @@ -211,6 +211,7 @@ def run_flare(self, my_col="F"): # Phase 2: Explosion print ("Run explosion") nSparks = int (flarePos / 2) + nSparks = clamp(nSparks,0,5) # FIXME: Max sparks # Initialize Sparks for i in range (0,nSparks): From 6b112a86dc0d7c61858d6e5dbb857497d38ff28d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:53:43 +0100 Subject: [PATCH 113/240] no limit --- led/animation.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/led/animation.py b/led/animation.py index 549a38f..240787a 100755 --- a/led/animation.py +++ b/led/animation.py @@ -152,9 +152,9 @@ def run_flare(self, my_col="F"): NUM_LEDS = 18 # FIXME #NUM_SPARKS = NUM_LEDS/2 #// max number (could be NUM_LEDS / 2); - sparkPos = [0,0,0,0,0,0] # width of flare: 3 LED - sparkVel = [0,0,0,0,0,0] - sparkCol = [0,0,0,0,0,0] + sparkPos = [0,0,0,0,0,0,0,0,0] # width of flare: 3 LED + sparkVel = [0,0,0,0,0,0,0,0,0] + sparkCol = [0,0,0,0,0,0,0,0,0] flarePos = 0. gravity = -.004 * 10 # m/s/s @@ -211,7 +211,6 @@ def run_flare(self, my_col="F"): # Phase 2: Explosion print ("Run explosion") nSparks = int (flarePos / 2) - nSparks = clamp(nSparks,0,5) # FIXME: Max sparks # Initialize Sparks for i in range (0,nSparks): From ef382a43bef35062974604c3d01051dbbe20afce Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:55:59 +0100 Subject: [PATCH 114/240] scaling --- led/animation.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/led/animation.py b/led/animation.py index 240787a..c68b177 100755 --- a/led/animation.py +++ b/led/animation.py @@ -206,7 +206,7 @@ def run_flare(self, my_col="F"): flarePos = flarePos + flareVel flarePos = clamp(flarePos, 0, NUM_LEDS) flareVel = flareVel + gravity - brightness = brightness * 0.92 + brightness = brightness * 0.9 # Phase 2: Explosion print ("Run explosion") @@ -222,8 +222,8 @@ def run_flare(self, my_col="F"): sparkCol[0] = 255 # // this will be our known spark dying_gravity = gravity - c1 = 120 - c2 = 50 + c1 = 120*2 + c2 = 50*2d while sparkCol[0] > c2/128: # as long as our known spark is lit, work with all the sparks print ("Run spark with reference spark lit "+str(sparkCol[0])) @@ -257,6 +257,8 @@ def run_flare(self, my_col="F"): dying_gravity = dying_gravity * .995 #// as sparks burn out they fall slower self.layout.push_to_driver() + + def run_animation(self, run_options={}, **kwds): # FIXME: will it still work? # The moonboard can serve a (x,y) = (11,18) --> 198 Pixel display # Refs: From 5d064bbeef2e21fc5b943cf2214f571d835ad558 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:56:18 +0100 Subject: [PATCH 115/240] fix --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index c68b177..7282981 100755 --- a/led/animation.py +++ b/led/animation.py @@ -223,7 +223,7 @@ def run_flare(self, my_col="F"): sparkCol[0] = 255 # // this will be our known spark dying_gravity = gravity c1 = 120*2 - c2 = 50*2d + c2 = 50*2 while sparkCol[0] > c2/128: # as long as our known spark is lit, work with all the sparks print ("Run spark with reference spark lit "+str(sparkCol[0])) From d397193fc3739d2b9110bdbe7ec142311ca11c8e Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 14:58:15 +0100 Subject: [PATCH 116/240] scaling --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 7282981..f0a86fc 100755 --- a/led/animation.py +++ b/led/animation.py @@ -223,7 +223,7 @@ def run_flare(self, my_col="F"): sparkCol[0] = 255 # // this will be our known spark dying_gravity = gravity c1 = 120*2 - c2 = 50*2 + c2 = 50*2.5 while sparkCol[0] > c2/128: # as long as our known spark is lit, work with all the sparks print ("Run spark with reference spark lit "+str(sparkCol[0])) From d96ace1afe21101f4216c524e3c2ace75369294e Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:05:46 +0100 Subject: [PATCH 117/240] testing col --- led/animation.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index f0a86fc..9252163 100755 --- a/led/animation.py +++ b/led/animation.py @@ -155,6 +155,8 @@ def run_flare(self, my_col="F"): sparkPos = [0,0,0,0,0,0,0,0,0] # width of flare: 3 LED sparkVel = [0,0,0,0,0,0,0,0,0] sparkCol = [0,0,0,0,0,0,0,0,0] + tmp_col = ord (my_col) + spark_col = [tmp_col,tmp_col,tmp_col,tmp_col,tmp_col,tmp_col,tmp_col,tmp_col,tmp_col] flarePos = 0. gravity = -.004 * 10 # m/s/s @@ -239,10 +241,13 @@ def run_flare(self, my_col="F"): sparkVel[i] = sparkVel[i] + dying_gravity sparkCol[i] = sparkCol[i] * .9 # FIXME sparkCol[i] = clamp(sparkCol[i], 0, 255) # // red cross dissolve - + + spark_col[i] = spark_col[i] + sparkVel[i] + tmp_col = chr(int(spark_col[i])+65) + c = (0,0,0) tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) - tmp_led = my_col + str (tmp_row) + tmp_led = tmp_col + str (tmp_row) if(sparkCol[i] > c1): #// fade white to yellow c = (255, 255, (255 * (sparkCol[i] - c1)) / (255 - c1)) elif sparkCol[i] < c2: # // fade from red to black From 198bf307c45517b67f4f90b3268ec4969450448d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:08:23 +0100 Subject: [PATCH 118/240] debug --- led/animation.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index 9252163..71e296b 100755 --- a/led/animation.py +++ b/led/animation.py @@ -243,8 +243,9 @@ def run_flare(self, my_col="F"): sparkCol[i] = clamp(sparkCol[i], 0, 255) # // red cross dissolve spark_col[i] = spark_col[i] + sparkVel[i] + spark_col[i] = clamp(spark_col[i],65,65+11) # FIXME tmp_col = chr(int(spark_col[i])+65) - + c = (0,0,0) tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) tmp_led = tmp_col + str (tmp_row) @@ -255,7 +256,7 @@ def run_flare(self, my_col="F"): else: # // fade from yellow to red c = (255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) - print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])+" and "+str(c)) + print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])+" and "+str(tmp_col)+" and "+str(c)) self.layout.set(self.MAPPING[tmp_led], c) From 0401056a4b423a87769b700af1aacfd440b1a65c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:09:37 +0100 Subject: [PATCH 119/240] fix --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 71e296b..e0a6d97 100755 --- a/led/animation.py +++ b/led/animation.py @@ -244,7 +244,7 @@ def run_flare(self, my_col="F"): spark_col[i] = spark_col[i] + sparkVel[i] spark_col[i] = clamp(spark_col[i],65,65+11) # FIXME - tmp_col = chr(int(spark_col[i])+65) + tmp_col = chr(int(spark_col[i])) c = (0,0,0) tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) From a70b98d4da5873736b88f245de6e3b68b75b7838 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:10:21 +0100 Subject: [PATCH 120/240] fix --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index e0a6d97..17262d4 100755 --- a/led/animation.py +++ b/led/animation.py @@ -243,7 +243,7 @@ def run_flare(self, my_col="F"): sparkCol[i] = clamp(sparkCol[i], 0, 255) # // red cross dissolve spark_col[i] = spark_col[i] + sparkVel[i] - spark_col[i] = clamp(spark_col[i],65,65+11) # FIXME + spark_col[i] = clamp(spark_col[i],65,65+11-1) # FIXME tmp_col = chr(int(spark_col[i])) c = (0,0,0) From baf3011ba79a74bc9ed58bf4645d88d204f8d5b3 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:12:23 +0100 Subject: [PATCH 121/240] config var --- led/animation.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/led/animation.py b/led/animation.py index 17262d4..2793666 100755 --- a/led/animation.py +++ b/led/animation.py @@ -148,7 +148,7 @@ def led_test(self): - def run_flare(self, my_col="F"): + def run_flare(self, my_col="F", use_cols=False): NUM_LEDS = 18 # FIXME #NUM_SPARKS = NUM_LEDS/2 #// max number (could be NUM_LEDS / 2); @@ -242,9 +242,11 @@ def run_flare(self, my_col="F"): sparkCol[i] = sparkCol[i] * .9 # FIXME sparkCol[i] = clamp(sparkCol[i], 0, 255) # // red cross dissolve - spark_col[i] = spark_col[i] + sparkVel[i] - spark_col[i] = clamp(spark_col[i],65,65+11-1) # FIXME - tmp_col = chr(int(spark_col[i])) + tmp_col = my_col + if use_cols: + spark_col[i] = spark_col[i] + sparkVel[i] + spark_col[i] = clamp(spark_col[i],65,65+11-1) # FIXME + tmp_col = chr(int(spark_col[i])) c = (0,0,0) tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) From 2fb2b003fc09ef1b4a49ef387606ceaed39cf279 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:13:05 +0100 Subject: [PATCH 122/240] scaling --- led/animation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index 2793666..8876c90 100755 --- a/led/animation.py +++ b/led/animation.py @@ -224,8 +224,8 @@ def run_flare(self, my_col="F", use_cols=False): sparkCol[0] = 255 # // this will be our known spark dying_gravity = gravity - c1 = 120*2 - c2 = 50*2.5 + c1 = 120*2.3 + c2 = 50*2.7 while sparkCol[0] > c2/128: # as long as our known spark is lit, work with all the sparks print ("Run spark with reference spark lit "+str(sparkCol[0])) From b309a9827f5c71e2db678c9f3da3da0eb544aee6 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:14:15 +0100 Subject: [PATCH 123/240] wip --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 8876c90..0bfe0ca 100755 --- a/led/animation.py +++ b/led/animation.py @@ -224,7 +224,7 @@ def run_flare(self, my_col="F", use_cols=False): sparkCol[0] = 255 # // this will be our known spark dying_gravity = gravity - c1 = 120*2.3 + c1 = 120*1.5 c2 = 50*2.7 while sparkCol[0] > c2/128: # as long as our known spark is lit, work with all the sparks From 46b6001fef237c85cfec8ea1375bf13c551f6d12 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:16:29 +0100 Subject: [PATCH 124/240] animation on --- led/animation.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/led/animation.py b/led/animation.py index 0bfe0ca..15b00ef 100755 --- a/led/animation.py +++ b/led/animation.py @@ -267,12 +267,11 @@ def run_flare(self, my_col="F", use_cols=False): - def run_animation(self, run_options={}, **kwds): # FIXME: will it still work? + def run_animation(self, duration = 0.01): # The moonboard can serve a (x,y) = (11,18) --> 198 Pixel display # Refs: # - http://www.anirama.com/1000leds/1d-fireworks/ - duration = 0.01 - duration2 = duration * 10 + duration2 = duration * 5 for i in range(1,self.ROWS+1): for j in range (0,self.COLS): @@ -289,7 +288,9 @@ def run_animation(self, run_options={}, **kwds): # FIXME: will it still work? self.clear() - + def display_rainbow(self): + self.clear() + def display_holdset(self, holdset="Hold Set A", duration=10, **kwds): print ("Display holdset: " + str(holdset)) @@ -355,7 +356,7 @@ def step(self, amt=1): #MOONBOARD.display_holdset(args.holdset, args.duration) print("Run animation,") - #MOONBOARD.run_animation() + MOONBOARD.run_animation() MOONBOARD.run_flare(my_col="F") MOONBOARD.run_flare(my_col="A") From e1d05634810f4d39c3c9c3f489a5f2a4ef8bb2eb Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:16:59 +0100 Subject: [PATCH 125/240] ref --- led/animation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/led/animation.py b/led/animation.py index 15b00ef..e051d50 100755 --- a/led/animation.py +++ b/led/animation.py @@ -149,6 +149,7 @@ def led_test(self): def run_flare(self, my_col="F", use_cols=False): + # Reference: http://www.anirama.com/1000leds/1d-fireworks/ NUM_LEDS = 18 # FIXME #NUM_SPARKS = NUM_LEDS/2 #// max number (could be NUM_LEDS / 2); From 03fec49a5f9c3580aad1b0c4a1bb92c4db057865 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:24:29 +0100 Subject: [PATCH 126/240] scale --- led/animation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index e051d50..9ec5e0e 100755 --- a/led/animation.py +++ b/led/animation.py @@ -272,7 +272,7 @@ def run_animation(self, duration = 0.01): # The moonboard can serve a (x,y) = (11,18) --> 198 Pixel display # Refs: # - http://www.anirama.com/1000leds/1d-fireworks/ - duration2 = duration * 5 + duration2 = duration * 0 for i in range(1,self.ROWS+1): for j in range (0,self.COLS): @@ -292,6 +292,7 @@ def run_animation(self, duration = 0.01): def display_rainbow(self): self.clear() + def display_holdset(self, holdset="Hold Set A", duration=10, **kwds): print ("Display holdset: " + str(holdset)) From fa161670dbbab0950a1500c5bcbbc422e042136e Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:40:52 +0100 Subject: [PATCH 127/240] melon test --- led/animation.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/led/animation.py b/led/animation.py index 9ec5e0e..a8978ac 100755 --- a/led/animation.py +++ b/led/animation.py @@ -14,6 +14,12 @@ def clamp(n, minn, maxn): return max(min(maxn, n), minn) +def rgb2hex(r,g,b): + return "#{:02x}{:02x}{:02x}".format(r,g,b) + +def hex2rgb(hexcode): + return tuple(map(ord,hexcode[1:].decode('hex'))) + # FIXME: Describe Layouts # FIXME: Delete this @@ -289,8 +295,22 @@ def run_animation(self, duration = 0.01): self.clear() - def display_rainbow(self): + def display_melon(self): self.clear() + red = (255,0,0) + black = (0,0,0) + lila = hex2rgb'ff99dd') #(255,100,200) #ff99dd + green1 = hex2rgb('118233') #COLORS.lime) + green2 = hex2rgb('089c48') #COLORS.limegreen + + for h in ["A1","A2","A3","A4","A5"]: + self.layout.set(self.MAPPING[h], green2) + + self.layout.push_to_driver() + time.sleep(10) + + + @@ -358,9 +378,10 @@ def step(self, amt=1): #MOONBOARD.display_holdset(args.holdset, args.duration) print("Run animation,") - MOONBOARD.run_animation() - MOONBOARD.run_flare(my_col="F") - MOONBOARD.run_flare(my_col="A") + #MOONBOARD.run_animation() + #MOONBOARD.run_flare(my_col="F") + #MOONBOARD.run_flare(my_col="A") + MOONBOARD.display_melon() print(f"wait {args.duration} seconds,") time.sleep(args.duration) From c2759ff22b9350d8d68e8260cfc4bd17249f4efa Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:41:34 +0100 Subject: [PATCH 128/240] fix --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index a8978ac..2d5b153 100755 --- a/led/animation.py +++ b/led/animation.py @@ -299,7 +299,7 @@ def display_melon(self): self.clear() red = (255,0,0) black = (0,0,0) - lila = hex2rgb'ff99dd') #(255,100,200) #ff99dd + lila = hex2rgb('ff99dd') #(255,100,200) #ff99dd green1 = hex2rgb('118233') #COLORS.lime) green2 = hex2rgb('089c48') #COLORS.limegreen From c5e96c7486adbc02962d9ea46a09d4c21bb6b794 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:42:10 +0100 Subject: [PATCH 129/240] fix --- led/animation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/led/animation.py b/led/animation.py index 2d5b153..819fc3b 100755 --- a/led/animation.py +++ b/led/animation.py @@ -299,9 +299,9 @@ def display_melon(self): self.clear() red = (255,0,0) black = (0,0,0) - lila = hex2rgb('ff99dd') #(255,100,200) #ff99dd - green1 = hex2rgb('118233') #COLORS.lime) - green2 = hex2rgb('089c48') #COLORS.limegreen + lila = hex2rgb(0xff99dd) #(255,100,200) #ff99dd + green1 = hex2rgb(0x118233) #COLORS.lime) + green2 = hex2rgb(0x089c48) #COLORS.limegreen for h in ["A1","A2","A3","A4","A5"]: self.layout.set(self.MAPPING[h], green2) From 0423917f61c0d23ab4b73c6397748673fe762d7c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:45:17 +0100 Subject: [PATCH 130/240] fix --- led/animation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/led/animation.py b/led/animation.py index 819fc3b..dafcabb 100755 --- a/led/animation.py +++ b/led/animation.py @@ -299,9 +299,9 @@ def display_melon(self): self.clear() red = (255,0,0) black = (0,0,0) - lila = hex2rgb(0xff99dd) #(255,100,200) #ff99dd - green1 = hex2rgb(0x118233) #COLORS.lime) - green2 = hex2rgb(0x089c48) #COLORS.limegreen + lila = hex2rgb("#ff99dd") #(255,100,200) #ff99dd + green1 = hex2rgb("#118233") #COLORS.lime) + green2 = hex2rgb("#089c48") #COLORS.limegreen for h in ["A1","A2","A3","A4","A5"]: self.layout.set(self.MAPPING[h], green2) From ced53967a3ec98e681eb17aa7eb5055b08f92a69 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:46:05 +0100 Subject: [PATCH 131/240] hex --- led/animation.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/led/animation.py b/led/animation.py index dafcabb..493bc32 100755 --- a/led/animation.py +++ b/led/animation.py @@ -10,15 +10,11 @@ import json import time import random +from colormap import hex2rgb def clamp(n, minn, maxn): return max(min(maxn, n), minn) -def rgb2hex(r,g,b): - return "#{:02x}{:02x}{:02x}".format(r,g,b) - -def hex2rgb(hexcode): - return tuple(map(ord,hexcode[1:].decode('hex'))) # FIXME: Describe Layouts From dc60f430a26bd05862fa62cf286f1a3f3bc55833 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:47:12 +0100 Subject: [PATCH 132/240] colormap --- install/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/install/requirements.txt b/install/requirements.txt index b9db341..a597b91 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -37,3 +37,4 @@ wrapt==1.11.1 spidev python-periphery rpi-ws281x==4.2.2 +colormap \ No newline at end of file From d04ba52e8a7007dd8c8992d0e5a9006970c37b53 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:51:37 +0100 Subject: [PATCH 133/240] line2 --- install/requirements.txt | 3 ++- led/animation.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/install/requirements.txt b/install/requirements.txt index a597b91..8c87be2 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -37,4 +37,5 @@ wrapt==1.11.1 spidev python-periphery rpi-ws281x==4.2.2 -colormap \ No newline at end of file +colormap +easydev \ No newline at end of file diff --git a/led/animation.py b/led/animation.py index 493bc32..7f136f4 100755 --- a/led/animation.py +++ b/led/animation.py @@ -299,9 +299,12 @@ def display_melon(self): green1 = hex2rgb("#118233") #COLORS.lime) green2 = hex2rgb("#089c48") #COLORS.limegreen - for h in ["A1","A2","A3","A4","A5"]: + for h in ["C1","D1","E1","F1","G1"]: self.layout.set(self.MAPPING[h], green2) - + for h in ["B2","H2"]: + self.layout.set(self.MAPPING[h], green2) + for h in ["C2","D2","E2","F2","G2"]: + self.layout.set(self.MAPPING[h], green1) self.layout.push_to_driver() time.sleep(10) From 9784debc654b0b19adbac2ff28b27c915f1a53d7 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:53:18 +0100 Subject: [PATCH 134/240] line3 --- led/animation.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/led/animation.py b/led/animation.py index 7f136f4..796c23a 100755 --- a/led/animation.py +++ b/led/animation.py @@ -305,6 +305,13 @@ def display_melon(self): self.layout.set(self.MAPPING[h], green2) for h in ["C2","D2","E2","F2","G2"]: self.layout.set(self.MAPPING[h], green1) + for h in ["A3","I3"]: + self.layout.set(self.MAPPING[h], green2) + for h in ["H3"]: + self.layout.set(self.MAPPING[h], green1) + for h in ["B3","C3","D3","E3","F3","G3"]: + self.layout.set(self.MAPPING[h], lila) + self.layout.push_to_driver() time.sleep(10) From 455b6ada4d379557d04484e93b9d3f160c912572 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:54:52 +0100 Subject: [PATCH 135/240] linea4 --- led/animation.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/led/animation.py b/led/animation.py index 796c23a..c5adcfd 100755 --- a/led/animation.py +++ b/led/animation.py @@ -311,6 +311,14 @@ def display_melon(self): self.layout.set(self.MAPPING[h], green1) for h in ["B3","C3","D3","E3","F3","G3"]: self.layout.set(self.MAPPING[h], lila) + for f in ["A4","C4","D4","E4","F4","G4"]: + self.layout.set(self.MAPPING[h], red) + for f in ["H4"]: + self.layout.set(self.MAPPING[h], lila) + for f in ["I4"]: + self.layout.set(self.MAPPING[h], green1) + for f in ["I4"]: + self.layout.set(self.MAPPING[h], green2) self.layout.push_to_driver() time.sleep(10) From 7eba972d3b33ef98556f45ee93a41c014cb8084e Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 15:58:25 +0100 Subject: [PATCH 136/240] line6 --- led/animation.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/led/animation.py b/led/animation.py index c5adcfd..67391b3 100755 --- a/led/animation.py +++ b/led/animation.py @@ -311,14 +311,33 @@ def display_melon(self): self.layout.set(self.MAPPING[h], green1) for h in ["B3","C3","D3","E3","F3","G3"]: self.layout.set(self.MAPPING[h], lila) - for f in ["A4","C4","D4","E4","F4","G4"]: + for h in ["A4","C4","D4","E4","F4","G4"]: self.layout.set(self.MAPPING[h], red) - for f in ["H4"]: + for h in ["H4"]: self.layout.set(self.MAPPING[h], lila) - for f in ["I4"]: + for h in ["I4"]: self.layout.set(self.MAPPING[h], green1) - for f in ["I4"]: + for h in ["J4"]: self.layout.set(self.MAPPING[h], green2) + for h in ["A5","B5","C5","E5","G4"]: + self.layout.set(self.MAPPING[h], red) + for h in ["H5"]: + self.layout.set(self.MAPPING[h], lila) + for h in ["I5"]: + self.layout.set(self.MAPPING[h], green1) + for h in ["J5"]: + self.layout.set(self.MAPPING[h], green2) + for h in ["B6","C6","D6","E6","F6","G6"]: + self.layout.set(self.MAPPING[h], red) + for h in ["H6"]: + self.layout.set(self.MAPPING[h], lila) + for h in ["I6"]: + self.layout.set(self.MAPPING[h], green1) + for h in ["J6"]: + self.layout.set(self.MAPPING[h], green2) + + + self.layout.push_to_driver() time.sleep(10) From f1983782a1bffbf3bda68ae0f50c39054eea0665 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 16:02:19 +0100 Subject: [PATCH 137/240] full --- led/animation.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/led/animation.py b/led/animation.py index 67391b3..9ebca48 100755 --- a/led/animation.py +++ b/led/animation.py @@ -335,9 +335,36 @@ def display_melon(self): self.layout.set(self.MAPPING[h], green1) for h in ["J6"]: self.layout.set(self.MAPPING[h], green2) - - - + for h in ["C7","D7","F7","G7"]: + self.layout.set(self.MAPPING[h], red) + for h in ["H7"]: + self.layout.set(self.MAPPING[h], lila) + for h in ["I7"]: + self.layout.set(self.MAPPING[h], green1) + for h in ["J7"]: + self.layout.set(self.MAPPING[h], green2) + for h in ["D8","E8","F8"]: + self.layout.set(self.MAPPING[h], red) + for h in ["H8"]: + self.layout.set(self.MAPPING[h], lila) + for h in ["I8"]: + self.layout.set(self.MAPPING[h], green1) + for h in ["J8"]: + self.layout.set(self.MAPPING[h], green2) + for h in ["E9","F9"]: + self.layout.set(self.MAPPING[h], red) + for h in ["G9"]: + self.layout.set(self.MAPPING[h], lila) + for h in ["H9"]: + self.layout.set(self.MAPPING[h], green1) + for h in ["I9"]: + self.layout.set(self.MAPPING[h], green2) + for h in ["F10"]: + self.layout.set(self.MAPPING[h], lila) + for h in ["G10"]: + self.layout.set(self.MAPPING[h], green1) + for h in ["H10"]: + self.layout.set(self.MAPPING[h], green2) self.layout.push_to_driver() time.sleep(10) From 072379e5451304fbda8587d050eea9870464ceab Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 16:02:37 +0100 Subject: [PATCH 138/240] ref --- led/animation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/led/animation.py b/led/animation.py index 9ebca48..bd753ef 100755 --- a/led/animation.py +++ b/led/animation.py @@ -292,6 +292,7 @@ def run_animation(self, duration = 0.01): self.clear() def display_melon(self): + # Ref: http://pixelartmaker.com/art/d8f3ce82dd215ed self.clear() red = (255,0,0) black = (0,0,0) From c8631f92483f03d68a8f4c5e24ddc3e8251d9650 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Wed, 29 Dec 2021 16:04:52 +0100 Subject: [PATCH 139/240] wip --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index bd753ef..0d024ff 100755 --- a/led/animation.py +++ b/led/animation.py @@ -440,9 +440,9 @@ def step(self, amt=1): print("Run animation,") #MOONBOARD.run_animation() - #MOONBOARD.run_flare(my_col="F") #MOONBOARD.run_flare(my_col="A") MOONBOARD.display_melon() + MOONBOARD.run_flare(my_col="F") print(f"wait {args.duration} seconds,") time.sleep(args.duration) From 1e97776d6c7fd0a092f12eeef1dd9bb88f3b2c8c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Thu, 30 Dec 2021 22:15:39 +0100 Subject: [PATCH 140/240] multi --- led/animation.py | 123 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index 0d024ff..78f0b85 100755 --- a/led/animation.py +++ b/led/animation.py @@ -268,7 +268,125 @@ def run_flare(self, my_col="F", use_cols=False): dying_gravity = dying_gravity * .995 #// as sparks burn out they fall slower self.layout.push_to_driver() + def run_flare_multi(self, my_col="F", use_cols=False): + # Reference: http://www.anirama.com/1000leds/1d-fireworks/ + NUM_LEDS = 18 # FIXME + #NUM_SPARKS = NUM_LEDS/2 #// max number (could be NUM_LEDS / 2); + + sparkPos = [0,0,0,0,0,0,0,0,0] # width of flare: 3 LED + sparkVel = [0,0,0,0,0,0,0,0,0] + sparkCol = [0,0,0,0,0,0,0,0,0] + tmp_col = ord (my_col) + spark_col = [tmp_col,tmp_col,tmp_col,tmp_col,tmp_col,tmp_col,tmp_col,tmp_col,tmp_col] + + flarePos = 0. + gravity = -.004 * 10 # m/s/s + flareVel = random.randint(50,90) / 100. *1.55 # trial and error to get reasonable range + brightness = 1. + + # initialize launch sparks + print ("Init launch sparks") + for i in range (0,3): # FIXME nSparks + sparkPos[i] = 0. + sparkVel[i] = flareVel * float(random.randint(80,120) / 100) # * (flareVel / 5) + # random around 20% of flare velocity + sparkCol[i] = sparkVel[i] * 1000 + sparkCol[i] = clamp(sparkCol[i], 0, 255) + print (str(i)+ " with "+str(sparkVel[i])+" and "+str(sparkCol[i])) + + # Phase 1: Flare + print ("Launch flare") + self.clear() + while flareVel >= -.2: + # sparks + print ("Run spark with velocity "+str(flareVel)) + + # Disable all led in column + for i in range (1,NUM_LEDS+1): + for my_col in ["A","B","C","D","E","F","G","H","I","J","K"]: + tmp_led = my_col + str (i) + self.layout.set(self.MAPPING[tmp_led], (0,0,0)) + + for i in range (0,3): + sparkPos[i] = sparkPos[i] + sparkVel[i] + sparkPos[i] = clamp(sparkPos[i], 0.0, NUM_LEDS*1.0) + sparkVel[i] = sparkVel[i] + gravity + sparkCol[i] = sparkCol[i] -.8*7 # FIXME + sparkCol[i] = clamp(sparkCol[i], 0.0, 255.0) + tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) + c = (sparkCol[i],0,0) # FIXME: cleanup + for my_col in ["A","B","C","D","E","F","G","H","I","J","K"]: + tmp_led = my_col + str (tmp_row) + print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])+" and "+str(sparkCol[i])) + self.layout.set(self.MAPPING[tmp_led], c) + + + # flare + tmp_row = clamp(int (flarePos), 1, NUM_LEDS) + for my_col in ["A","B","C","D","E","F","G","H","I","J","K"]: + tmp_led = my_col + str (tmp_row) + flareCol = (255.,0,0) # FIXME + print ("Flare position "+str(tmp_led)+" with "+str(flarePos)+" and "+str(flareCol)) + self.layout.set(self.MAPPING[tmp_led], flareCol) + + self.layout.push_to_driver() + flarePos = flarePos + flareVel + flarePos = clamp(flarePos, 0, NUM_LEDS) + flareVel = flareVel + gravity + brightness = brightness * 0.9 + # Phase 2: Explosion + print ("Run explosion") + nSparks = int (flarePos / 2) + + # Initialize Sparks + for i in range (0,nSparks): + sparkPos[i] = flarePos + sparkVel[i] = float(random.randint(-100,100) / 100) # from -1 to 1 + sparkCol[i] = abs(sparkVel[i]) * 500 # set colors before scaling velocity to keep them bright + sparkCol[i] = clamp(sparkCol[i], 0., 255.) + sparkVel[i] = sparkVel[i] * flarePos / NUM_LEDS # proportional to height + + sparkCol[0] = 255 # // this will be our known spark + dying_gravity = gravity + c1 = 120*1.5 + c2 = 50*2.7 + + while sparkCol[0] > c2/128: # as long as our known spark is lit, work with all the sparks + print ("Run spark with reference spark lit "+str(sparkCol[0])) + + # Disable all led in column + for i in range (1,NUM_LEDS+1): + for my_col in ["A","B","C","D","E","F","G","H","I","J","K"]: + tmp_led = my_col + str (i) + self.layout.set(self.MAPPING[tmp_led], (0,0,0)) + + for i in range (0,nSparks): + sparkPos[i] = sparkPos[i] + sparkVel[i] + sparkPos[i] = clamp(sparkPos[i], 0, NUM_LEDS) + sparkVel[i] = sparkVel[i] + dying_gravity + sparkCol[i] = sparkCol[i] * .9 # FIXME + sparkCol[i] = clamp(sparkCol[i], 0, 255) # // red cross dissolve + + for my_col in ["A","B","C","D","E","F","G","H","I","J","K"]: + tmp_col = my_col + + c = (0,0,0) + tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) + tmp_led = tmp_col + str (tmp_row) + if(sparkCol[i] > c1): #// fade white to yellow + c = (255, 255, (255 * (sparkCol[i] - c1)) / (255 - c1)) + elif sparkCol[i] < c2: # // fade from red to black + c = ((255 * sparkCol[i]) / c2, 0, 0) + else: # // fade from yellow to red + c = (255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) + + print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])+" and "+str(tmp_col)+" and "+str(c)) + + self.layout.set(self.MAPPING[tmp_led], c) + + dying_gravity = dying_gravity * .995 #// as sparks burn out they fall slower + self.layout.push_to_driver() def run_animation(self, duration = 0.01): # The moonboard can serve a (x,y) = (11,18) --> 198 Pixel display @@ -441,8 +559,9 @@ def step(self, amt=1): print("Run animation,") #MOONBOARD.run_animation() #MOONBOARD.run_flare(my_col="A") - MOONBOARD.display_melon() - MOONBOARD.run_flare(my_col="F") + #MOONBOARD.display_melon() + #MOONBOARD.run_flare(my_col="F") + MOONBOARD.run_flare_multi() print(f"wait {args.duration} seconds,") time.sleep(args.duration) From 61f27cd8b5e9c0022db4f8730e735a8fa0774454 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Thu, 30 Dec 2021 22:22:01 +0100 Subject: [PATCH 141/240] single --- led/animation.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/led/animation.py b/led/animation.py index 78f0b85..78c9f71 100755 --- a/led/animation.py +++ b/led/animation.py @@ -368,18 +368,20 @@ def run_flare_multi(self, my_col="F", use_cols=False): sparkCol[i] = sparkCol[i] * .9 # FIXME sparkCol[i] = clamp(sparkCol[i], 0, 255) # // red cross dissolve + if(sparkCol[i] > c1): #// fade white to yellow + c = (255, 255, (255 * (sparkCol[i] - c1)) / (255 - c1)) + elif sparkCol[i] < c2: # // fade from red to black + c = ((255 * sparkCol[i]) / c2, 0, 0) + else: # // fade from yellow to red + c = (255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) + for my_col in ["A","B","C","D","E","F","G","H","I","J","K"]: tmp_col = my_col c = (0,0,0) tmp_row = clamp(int (sparkPos[i]), 1, NUM_LEDS) tmp_led = tmp_col + str (tmp_row) - if(sparkCol[i] > c1): #// fade white to yellow - c = (255, 255, (255 * (sparkCol[i] - c1)) / (255 - c1)) - elif sparkCol[i] < c2: # // fade from red to black - c = ((255 * sparkCol[i]) / c2, 0, 0) - else: # // fade from yellow to red - c = (255, (255 * (sparkCol[i] - c2)) / (c1 - c2), 0) + print ("Spark position "+str(tmp_led)+" with "+str(sparkPos[i])+" and "+str(tmp_col)+" and "+str(c)) @@ -490,7 +492,25 @@ def display_melon(self): + def run_animation_single_color(self, duration = 0.01,color=(255,0,0)): + # The moonboard can serve a (x,y) = (11,18) --> 198 Pixel display + # Refs: + # - http://www.anirama.com/1000leds/1d-fireworks/ + duration2 = duration * 0 + + for i in range(1,self.ROWS+1): + for j in range (0,self.COLS): + + le = chr(j+65) + h = le+str(i) + print (h) + self.layout.set(self.MAPPING[h], color) + self.layout.push_to_driver() + + time.sleep(duration2) + + self.clear() def display_holdset(self, holdset="Hold Set A", duration=10, **kwds): @@ -561,7 +581,7 @@ def step(self, amt=1): #MOONBOARD.run_flare(my_col="A") #MOONBOARD.display_melon() #MOONBOARD.run_flare(my_col="F") - MOONBOARD.run_flare_multi() + MOONBOARD.run_animation_single_color() print(f"wait {args.duration} seconds,") time.sleep(args.duration) From 9c0deb7a61a592b022250256aee8b580f7327c3e Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Thu, 30 Dec 2021 22:23:25 +0100 Subject: [PATCH 142/240] time --- led/animation.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/led/animation.py b/led/animation.py index 78c9f71..56f2b21 100755 --- a/led/animation.py +++ b/led/animation.py @@ -492,7 +492,7 @@ def display_melon(self): - def run_animation_single_color(self, duration = 0.01,color=(255,0,0)): + def run_animation_single_color(self, duration = 5,color=(255,0,0)): # The moonboard can serve a (x,y) = (11,18) --> 198 Pixel display # Refs: # - http://www.anirama.com/1000leds/1d-fireworks/ @@ -508,7 +508,7 @@ def run_animation_single_color(self, duration = 0.01,color=(255,0,0)): self.layout.push_to_driver() - time.sleep(duration2) + time.sleep(duration) self.clear() @@ -581,7 +581,8 @@ def step(self, amt=1): #MOONBOARD.run_flare(my_col="A") #MOONBOARD.display_melon() #MOONBOARD.run_flare(my_col="F") - MOONBOARD.run_animation_single_color() + MOONBOARD.run_animation_single_color(color=(255,0,0)) + MOONBOARD.run_animation_single_color(color=(0,0,255)) print(f"wait {args.duration} seconds,") time.sleep(args.duration) From 2ab5728212ae563b5de4d632f1e6690727816af8 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Thu, 30 Dec 2021 22:24:45 +0100 Subject: [PATCH 143/240] color --- led/animation.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index 56f2b21..7ee977e 100755 --- a/led/animation.py +++ b/led/animation.py @@ -581,8 +581,9 @@ def step(self, amt=1): #MOONBOARD.run_flare(my_col="A") #MOONBOARD.display_melon() #MOONBOARD.run_flare(my_col="F") - MOONBOARD.run_animation_single_color(color=(255,0,0)) - MOONBOARD.run_animation_single_color(color=(0,0,255)) + MOONBOARD.run_animation_single_color(color=(255,192,203)) + MOONBOARD.run_animation_single_color(color=(255,255,0)) + #MOONBOARD.run_animation_single_color(color=(0,0,255)) print(f"wait {args.duration} seconds,") time.sleep(args.duration) From 571848e282c06ce241cae9ca58c78f8ea90f83d1 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Thu, 30 Dec 2021 22:29:22 +0100 Subject: [PATCH 144/240] colors --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 7ee977e..c429743 100755 --- a/led/animation.py +++ b/led/animation.py @@ -581,7 +581,7 @@ def step(self, amt=1): #MOONBOARD.run_flare(my_col="A") #MOONBOARD.display_melon() #MOONBOARD.run_flare(my_col="F") - MOONBOARD.run_animation_single_color(color=(255,192,203)) + MOONBOARD.run_animation_single_color(color=(255,1,154)) MOONBOARD.run_animation_single_color(color=(255,255,0)) #MOONBOARD.run_animation_single_color(color=(0,0,255)) From 8c8af7a40c3d5b0d8d9bfeeed477a2b2e2da5659 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Thu, 30 Dec 2021 22:33:51 +0100 Subject: [PATCH 145/240] all --- led/animation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/led/animation.py b/led/animation.py index c429743..ece6be1 100755 --- a/led/animation.py +++ b/led/animation.py @@ -579,8 +579,8 @@ def step(self, amt=1): print("Run animation,") #MOONBOARD.run_animation() #MOONBOARD.run_flare(my_col="A") - #MOONBOARD.display_melon() - #MOONBOARD.run_flare(my_col="F") + MOONBOARD.display_melon() + MOONBOARD.run_flare(my_col="F") MOONBOARD.run_animation_single_color(color=(255,1,154)) MOONBOARD.run_animation_single_color(color=(255,255,0)) #MOONBOARD.run_animation_single_color(color=(0,0,255)) From b07d193b6aeb69a15d5b6bafddb6321a1d52a251 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Thu, 30 Dec 2021 22:37:32 +0100 Subject: [PATCH 146/240] xmas --- led/animation.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/led/animation.py b/led/animation.py index ece6be1..4ad6a73 100755 --- a/led/animation.py +++ b/led/animation.py @@ -493,11 +493,6 @@ def display_melon(self): def run_animation_single_color(self, duration = 5,color=(255,0,0)): - # The moonboard can serve a (x,y) = (11,18) --> 198 Pixel display - # Refs: - # - http://www.anirama.com/1000leds/1d-fireworks/ - duration2 = duration * 0 - for i in range(1,self.ROWS+1): for j in range (0,self.COLS): @@ -512,6 +507,27 @@ def run_animation_single_color(self, duration = 5,color=(255,0,0)): self.clear() + def run_animation_xmas(self, duration = 0.01): + + duration2 = duration * 10 + + for c in [COLORS.purple, COLORS.blue, COLORS.red]: + + for i in range(1,self.ROWS+1): + for j in range (0,self.COLS): + + le = chr(j+65) + h = le+str(i) + print (h) + self.layout.set(self.MAPPING[h], c) + time.sleep(duration) + + + self.layout.push_to_driver() + + time.sleep(duration2) + + self.clear() def display_holdset(self, holdset="Hold Set A", duration=10, **kwds): print ("Display holdset: " + str(holdset)) @@ -579,10 +595,11 @@ def step(self, amt=1): print("Run animation,") #MOONBOARD.run_animation() #MOONBOARD.run_flare(my_col="A") - MOONBOARD.display_melon() - MOONBOARD.run_flare(my_col="F") - MOONBOARD.run_animation_single_color(color=(255,1,154)) - MOONBOARD.run_animation_single_color(color=(255,255,0)) + #MOONBOARD.display_melon() + #MOONBOARD.run_flare(my_col="F") + #MOONBOARD.run_animation_single_color(color=(255,1,154)) + #MOONBOARD.run_animation_single_color(color=(255,255,0)) + MOONBOARD.run_animation_xmas() #MOONBOARD.run_animation_single_color(color=(0,0,255)) print(f"wait {args.duration} seconds,") From d4b0fbbabebf69ee77a3513110ee46915134e020 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Thu, 30 Dec 2021 22:39:14 +0100 Subject: [PATCH 147/240] timing --- led/animation.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/led/animation.py b/led/animation.py index 4ad6a73..031f927 100755 --- a/led/animation.py +++ b/led/animation.py @@ -509,7 +509,7 @@ def run_animation_single_color(self, duration = 5,color=(255,0,0)): def run_animation_xmas(self, duration = 0.01): - duration2 = duration * 10 + duration2 = 1#duration * 10 for c in [COLORS.purple, COLORS.blue, COLORS.red]: @@ -520,12 +520,16 @@ def run_animation_xmas(self, duration = 0.01): h = le+str(i) print (h) self.layout.set(self.MAPPING[h], c) + + self.layout.push_to_driver() + time.sleep(duration) + time.sleep(duration2) + + - self.layout.push_to_driver() - time.sleep(duration2) self.clear() From 57f9433eaa326d62c5a9d1c10ab8c3fa8baee9dd Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Thu, 30 Dec 2021 22:41:29 +0100 Subject: [PATCH 148/240] loop --- led/animation.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/led/animation.py b/led/animation.py index 031f927..200e3fd 100755 --- a/led/animation.py +++ b/led/animation.py @@ -599,12 +599,14 @@ def step(self, amt=1): print("Run animation,") #MOONBOARD.run_animation() #MOONBOARD.run_flare(my_col="A") - #MOONBOARD.display_melon() - #MOONBOARD.run_flare(my_col="F") - #MOONBOARD.run_animation_single_color(color=(255,1,154)) - #MOONBOARD.run_animation_single_color(color=(255,255,0)) - MOONBOARD.run_animation_xmas() - #MOONBOARD.run_animation_single_color(color=(0,0,255)) + while True: + # + MOONBOARD.display_melon() + MOONBOARD.run_flare(my_col="F") + MOONBOARD.run_animation_single_color(color=(255,1,154)) + MOONBOARD.run_animation_single_color(color=(255,255,0)) + MOONBOARD.run_animation_xmas() + #MOONBOARD.run_animation_single_color(color=(0,0,255)) print(f"wait {args.duration} seconds,") time.sleep(args.duration) From a98f7c83a4deaf3aedb8fedebc5717a0a30db0a0 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Thu, 30 Dec 2021 22:41:45 +0100 Subject: [PATCH 149/240] order --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 200e3fd..63b2eb9 100755 --- a/led/animation.py +++ b/led/animation.py @@ -601,11 +601,11 @@ def step(self, amt=1): #MOONBOARD.run_flare(my_col="A") while True: # + MOONBOARD.run_animation_xmas() MOONBOARD.display_melon() MOONBOARD.run_flare(my_col="F") MOONBOARD.run_animation_single_color(color=(255,1,154)) MOONBOARD.run_animation_single_color(color=(255,255,0)) - MOONBOARD.run_animation_xmas() #MOONBOARD.run_animation_single_color(color=(0,0,255)) print(f"wait {args.duration} seconds,") From 3692c88b84837106fc7b724caf36304d660c531e Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 00:33:42 +0100 Subject: [PATCH 150/240] no clear --- run_testing_interface.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 60ffa32..9b65f29 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -59,7 +59,8 @@ def _on_message(self, client, userdata, message): #lc10 = int(repr(lc)[-2]) #lc100 = int(repr(lc)[-3]) logging.debug ("Clean board") - self._MOONBOARD.clear() + + #self._MOONBOARD.clear() logging.debug ("Begin display holds") #charmax = chr(ord('@')+lc1) From 3103a0bc30ce3c22cfad810592097f7193768441 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 00:36:28 +0100 Subject: [PATCH 151/240] set default to gz config --- run.py | 2 +- run_testing_interface.py | 2 +- scripts/run.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/run.py b/run.py index 403a2a5..976d37b 100755 --- a/run.py +++ b/run.py @@ -55,7 +55,7 @@ def new_problem_cb(mb,holds_string): parser.add_argument('--driver_type', help='driver type, depends on leds and device controlling the led.', choices=['PiWS281x', 'WS2801', 'SimPixel'], - default='WS2801') + default='PiWS281x') parser.add_argument('--brightness', default=100, type=int) diff --git a/run_testing_interface.py b/run_testing_interface.py index 9b65f29..64a55cb 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -100,7 +100,7 @@ def _record_data(self, hostname="localhost",port=1883): parser.add_argument('--driver_type', help='driver type, depends on leds and device controlling the led.', choices=['PiWS281x', 'WS2801', 'SimPixel'], - default='WS2801') + default='PiWS281x') parser.add_argument('--brightness', default=100, type=int) diff --git a/scripts/run.sh b/scripts/run.sh index 853907a..c22aee1 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -5,4 +5,4 @@ LOG_FILE=/var/log/moonboard exec 1>$LOG_FILE exec 2>&1 -sudo /usr/bin/python3 /home/pi/moonboard/run.py --debug --driver PiWS281x $1 \ No newline at end of file +sudo /usr/bin/python3 /home/pi/moonboard/run.py --debug $1 \ No newline at end of file From b0be58f36b0664c70303a4f44e0b94c56db94b1f Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 00:40:19 +0100 Subject: [PATCH 152/240] debugging --- run_testing_interface.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 64a55cb..1f0fc40 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -9,8 +9,8 @@ import sys import logging import time -import paho.mqtt.client as paho -# FIXME pip install +import paho.mqtt.client as paho # FIXME pip install +import math # floor # external power LED and power button LED_GPIO = 26 @@ -56,8 +56,10 @@ def _on_message(self, client, userdata, message): lc = int(msg["loadcurrent"]) lc1 = int(repr(lc)[-1]) + lc10 = math.floor(lc/10) #lc10 = int(repr(lc)[-2]) #lc100 = int(repr(lc)[-3]) + logging.debug("Using: lc10:"+str(lc10)) logging.debug ("Clean board") #self._MOONBOARD.clear() From bd60afcd361dc25aa617b030b12e0db64cfde0ef Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 00:43:50 +0100 Subject: [PATCH 153/240] pos --- run_testing_interface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 1f0fc40..c2908de 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -67,8 +67,8 @@ def _on_message(self, client, userdata, message): logging.debug ("Begin display holds") #charmax = chr(ord('@')+lc1) for i1 in range (1, lc1): - ichar = chr(ord('@')+i1) - ihold = ichar+"4" + ichar = "B"#chr(ord('@')+i1) + ihold = ichar+str(10-lc10) logging.debug("Use hold "+ihold) self._MOONBOARD.show_hold(ihold) # FIXME: Runs too long - next event occurs.... From 3b6859414c573fb0031b6b7e085567cd9e499919 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 00:47:56 +0100 Subject: [PATCH 154/240] multiple --- run_testing_interface.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index c2908de..647f285 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -66,12 +66,20 @@ def _on_message(self, client, userdata, message): logging.debug ("Begin display holds") #charmax = chr(ord('@')+lc1) + ymax = 10 + ymin = 1 for i1 in range (1, lc1): ichar = "B"#chr(ord('@')+i1) - ihold = ichar+str(10-lc10) - logging.debug("Use hold "+ihold) - self._MOONBOARD.show_hold(ihold) + ytmp = ymax - lc10 + for y in range(ymin,ytmp): + + ihold = ichar+str(y) + logging.debug("Use hold "+ihold) + #self._MOONBOARD.show_hold(ihold) + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (255,0,0)) + # FIXME: Runs too long - next event occurs.... + self._MOONBOARD.layout.push_to_driver() #self._MOONBOARD.show_hold("A4") #self._MOONBOARD.show_hold("B4") From 6a14ee07fa8cae1ce2c53d80dcc9bc55445f215b Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 00:49:58 +0100 Subject: [PATCH 155/240] clear --- run_testing_interface.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 647f285..86404e5 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -71,12 +71,15 @@ def _on_message(self, client, userdata, message): for i1 in range (1, lc1): ichar = "B"#chr(ord('@')+i1) ytmp = ymax - lc10 - for y in range(ymin,ytmp): - + for y in range(ymin,ymax): ihold = ichar+str(y) - logging.debug("Use hold "+ihold) - #self._MOONBOARD.show_hold(ihold) - self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (255,0,0)) + + if y < ytmp: + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (0,0,0)) + else: + logging.debug("Use hold "+ihold) + #self._MOONBOARD.show_hold(ihold) + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (255,0,0)) # FIXME: Runs too long - next event occurs.... self._MOONBOARD.layout.push_to_driver() From f7392b320a03fae7737ccc7c9da967ea50a183ce Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 00:52:57 +0100 Subject: [PATCH 156/240] 2 digits --- run_testing_interface.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 86404e5..e92d2b5 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -66,20 +66,34 @@ def _on_message(self, client, userdata, message): logging.debug ("Begin display holds") #charmax = chr(ord('@')+lc1) + + ## 10er ymax = 10 ymin = 1 - for i1 in range (1, lc1): - ichar = "B"#chr(ord('@')+i1) - ytmp = ymax - lc10 - for y in range(ymin,ymax): - ihold = ichar+str(y) - - if y < ytmp: - self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (0,0,0)) - else: - logging.debug("Use hold "+ihold) - #self._MOONBOARD.show_hold(ihold) - self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (255,0,0)) + ichar = "E"#chr(ord('@')+i1) + ytmp = ymax - lc10 + for y in range(ymin,ymax): + ihold = ichar+str(y) + + if y < ytmp: + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (0,0,0)) + else: + logging.debug("Use hold "+ihold) + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (255,0,0)) + + ## 1er + ichar = "F"#chr(ord('@')+i1) + ytmp = ymax - lc1 + for y in range(ymin,ymax): + ihold = ichar+str(y) + + if y < ytmp: + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (0,0,0)) + else: + logging.debug("Use hold "+ihold) + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (255,255,0)) + + # FIXME: Runs too long - next event occurs.... self._MOONBOARD.layout.push_to_driver() From 3209908f506ae8819a42fe69085eb7c7b115c03e Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 00:56:33 +0100 Subject: [PATCH 157/240] 0.31 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..4950d3c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- v0.31 Animations and prototyped mqtt linkage to hangboard \ No newline at end of file From bb26deafacc132296e352c55946e86aa989bf907 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 01:01:24 +0100 Subject: [PATCH 158/240] colors --- run_testing_interface.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index e92d2b5..1b29349 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -72,26 +72,30 @@ def _on_message(self, client, userdata, message): ymin = 1 ichar = "E"#chr(ord('@')+i1) ytmp = ymax - lc10 + color_10er_done = (255,0,0) + color_10er_not_done = (100,0,0) for y in range(ymin,ymax): ihold = ichar+str(y) if y < ytmp: - self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (0,0,0)) + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], color_10er_not_done) else: logging.debug("Use hold "+ihold) - self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (255,0,0)) + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], color_10er_done) ## 1er ichar = "F"#chr(ord('@')+i1) ytmp = ymax - lc1 + color_1er_done = (0,255,0) + color_1er_not_done = (0,100,0) for y in range(ymin,ymax): ihold = ichar+str(y) if y < ytmp: - self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (0,0,0)) + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], color_1er_not_done) else: logging.debug("Use hold "+ihold) - self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], (255,255,0)) + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], color_1er_done) From b4eca570d4c65ea3968355cf76ff55c2c7182211 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 01:02:56 +0100 Subject: [PATCH 159/240] fix --- run_testing_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index 1b29349..c96efe2 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import argparse -from led.moonboard import MoonBoard,LED_LAYOUT +from led.moonboard import MoonBoard from functools import partial import json import RPi.GPIO as GPIO From 8007d9cc3766342f60fc78564baab29eb63953ca Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 01:05:49 +0100 Subject: [PATCH 160/240] fix --- run_testing_interface.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index c96efe2..b88fe3e 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -135,9 +135,9 @@ def _record_data(self, hostname="localhost",port=1883): parser.add_argument('--brightness', default=100, type=int) - parser.add_argument('--led_layout', - default=None, - choices=list(LED_LAYOUT.keys()) + parser.add_argument('--led_mapping', + type=str, + default='led_mapping.json', ) parser.add_argument('--debug', action = "store_true") @@ -154,7 +154,7 @@ def _record_data(self, hostname="localhost",port=1883): logger.setLevel(logging.INFO) #problems - led_layout = LED_LAYOUT.get(args.led_layout) if args.led_layout is not None else None + led_layout = args.led_mapping driver_type = args.driver_type d = Database(driver_type=driver_type, led_layout=led_layout) From e8b7adf331e7271072cffb7aa3f06d755c88f049 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 01:07:32 +0100 Subject: [PATCH 161/240] colors --- run_testing_interface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_testing_interface.py b/run_testing_interface.py index b88fe3e..1ea55af 100644 --- a/run_testing_interface.py +++ b/run_testing_interface.py @@ -73,7 +73,7 @@ def _on_message(self, client, userdata, message): ichar = "E"#chr(ord('@')+i1) ytmp = ymax - lc10 color_10er_done = (255,0,0) - color_10er_not_done = (100,0,0) + color_10er_not_done = (0,0,50) for y in range(ymin,ymax): ihold = ichar+str(y) @@ -87,7 +87,7 @@ def _on_message(self, client, userdata, message): ichar = "F"#chr(ord('@')+i1) ytmp = ymax - lc1 color_1er_done = (0,255,0) - color_1er_not_done = (0,100,0) + color_1er_not_done = (0,0,50) for y in range(ymin,ymax): ihold = ichar+str(y) From 8f09742f18075553c322bf25ae78cacf9c999211 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Fri, 31 Dec 2021 01:10:46 +0100 Subject: [PATCH 162/240] renamed --- run_testing_interface.py => run_testing_interface_hangboard.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename run_testing_interface.py => run_testing_interface_hangboard.py (100%) diff --git a/run_testing_interface.py b/run_testing_interface_hangboard.py similarity index 100% rename from run_testing_interface.py rename to run_testing_interface_hangboard.py From 15f98f0f0dd968be1e6c5abfccbe6b397dce28e7 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 1 Jan 2022 12:20:06 +0100 Subject: [PATCH 163/240] paw patrol colors --- led/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/animation.py b/led/animation.py index 63b2eb9..1ecea74 100755 --- a/led/animation.py +++ b/led/animation.py @@ -511,7 +511,7 @@ def run_animation_xmas(self, duration = 0.01): duration2 = 1#duration * 10 - for c in [COLORS.purple, COLORS.blue, COLORS.red]: + for c in [COLORS.purple, COLORS.blue, COLORS.red, COLORS.green]: for i in range(1,self.ROWS+1): for j in range (0,self.COLS): From c6c5a2714df879a34a8a325618aaaf71a9a19f66 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 1 Jan 2022 19:37:55 +0100 Subject: [PATCH 164/240] debug --- run_testing_interface_hangboard.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run_testing_interface_hangboard.py b/run_testing_interface_hangboard.py index 1ea55af..ea41e80 100644 --- a/run_testing_interface_hangboard.py +++ b/run_testing_interface_hangboard.py @@ -60,6 +60,8 @@ def _on_message(self, client, userdata, message): #lc10 = int(repr(lc)[-2]) #lc100 = int(repr(lc)[-3]) logging.debug("Using: lc10:"+str(lc10)) + logging.debug("Using: lc1:"+str(lc1)) + logging.debug ("Clean board") #self._MOONBOARD.clear() From ff02aeec40bbbd98f95f4a8376287dbc129d71af Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 1 Jan 2022 19:41:20 +0100 Subject: [PATCH 165/240] fix --- run_testing_interface_hangboard.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/run_testing_interface_hangboard.py b/run_testing_interface_hangboard.py index ea41e80..840733c 100644 --- a/run_testing_interface_hangboard.py +++ b/run_testing_interface_hangboard.py @@ -53,8 +53,11 @@ def _on_message(self, client, userdata, message): #l = "\rLoad: %.1f " % msg["loadcurrent"] #t = "Time: " + str(msg["time"]) #lmax = "\rLoad Max: %.1f " % msg["loadmaximal"] - - lc = int(msg["loadcurrent"]) + ll = msg["loadcurrent"] + if ll < 0: + ll = 0 + + lc = int(ll) lc1 = int(repr(lc)[-1]) lc10 = math.floor(lc/10) #lc10 = int(repr(lc)[-2]) From 64bc240666df923b4790afc9cff420939f014c19 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 1 Jan 2022 19:47:20 +0100 Subject: [PATCH 166/240] test --- run_testing_interface_hangboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_testing_interface_hangboard.py b/run_testing_interface_hangboard.py index 840733c..48486ba 100644 --- a/run_testing_interface_hangboard.py +++ b/run_testing_interface_hangboard.py @@ -67,7 +67,7 @@ def _on_message(self, client, userdata, message): logging.debug ("Clean board") - #self._MOONBOARD.clear() + self._MOONBOARD.clear() logging.debug ("Begin display holds") #charmax = chr(ord('@')+lc1) From 7162e02833c5efc2ffa8303ff7dd363027171540 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sat, 1 Jan 2022 19:49:01 +0100 Subject: [PATCH 167/240] except less 0 --- run_testing_interface_hangboard.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/run_testing_interface_hangboard.py b/run_testing_interface_hangboard.py index 48486ba..ad69d00 100644 --- a/run_testing_interface_hangboard.py +++ b/run_testing_interface_hangboard.py @@ -54,12 +54,13 @@ def _on_message(self, client, userdata, message): #t = "Time: " + str(msg["time"]) #lmax = "\rLoad Max: %.1f " % msg["loadmaximal"] ll = msg["loadcurrent"] - if ll < 0: - ll = 0 - - lc = int(ll) - lc1 = int(repr(lc)[-1]) - lc10 = math.floor(lc/10) + lc = 0 + lc1 = 0 + lc10 = 0 + if ll > 0: + lc = int(ll) + lc1 = int(repr(lc)[-1]) + lc10 = math.floor(lc/10) #lc10 = int(repr(lc)[-2]) #lc100 = int(repr(lc)[-3]) logging.debug("Using: lc10:"+str(lc10)) From 1e2e02b47815e5c03b91f2a7a3009b609c62df32 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:27:57 +0100 Subject: [PATCH 168/240] mqtt proto strip down init --- ble/moon_ble_mqtt_proto.py | 149 +++++++++++++++++++++++++++++++++++++ ble/simple_client.py | 1 + 2 files changed, 150 insertions(+) create mode 100755 ble/moon_ble_mqtt_proto.py diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py new file mode 100755 index 0000000..afd0e21 --- /dev/null +++ b/ble/moon_ble_mqtt_proto.py @@ -0,0 +1,149 @@ +import sys +from gatt_base.gatt_lib_advertisement import Advertisement +from gatt_base.gatt_lib_characteristic import Characteristic +from gatt_base.gatt_lib_service import Service +import string,json +import subprocess +import logging +from moonboard_app_protocol import UnstuffSequence, decode_problem_string + +import os +import threading +import pty + +BLUEZ_SERVICE_NAME = 'org.bluez' +LE_ADVERTISING_MANAGER_IFACE = 'org.bluez.LEAdvertisingManager1' +GATT_MANAGER_IFACE = 'org.bluez.GattManager1' +GATT_CHRC_IFACE = 'org.bluez.GattCharacteristic1' +UART_SERVICE_UUID = '6e400001-b5a3-f393-e0a9-e50e24dcca9e' +UART_RX_CHARACTERISTIC_UUID = '6e400002-b5a3-f393-e0a9-e50e24dcca9e' +UART_TX_CHARACTERISTIC_UUID = '6e400003-b5a3-f393-e0a9-e50e24dcca9e' +LOCAL_NAME = 'Moonboard A' + +class RxCharacteristic(Characteristic): + def __init__(self, bus, index, service, process_rx): + Characteristic.__init__(self, bus, index, UART_RX_CHARACTERISTIC_UUID, + ['write'], service) + self.process_rx=process_rx + + def WriteValue(self, value, options): + pass + #self.process_rx(value) + +class UartService(Service): + def __init__(self, bus,path, index, process_rx): + Service.__init__(self, bus,path, index, UART_SERVICE_UUID, True) + self.add_characteristic(RxCharacteristic(bus, 1, self, process_rx)) + +class OutStream: + def __init__(self, fileno): + self._fileno = fileno + self._buffer = b"" + + def read_lines(self): + try: + output = os.read(self._fileno, 1000) + except OSError as e: + if e.errno != errno.EIO: raise + output = b"" + lines = output.split(b"\n") + lines[0] = self._buffer + lines[0] # prepend previous + # non-finished line. + if output: + self._buffer = lines[-1] + finished_lines = lines[:-1] + readable = True + else: + self._buffer = b"" + if len(lines) == 1 and not lines[0]: + # We did not have buffer left, so no output at all. + lines = [] + finished_lines = lines + readable = False + + finished_lines = [line.rstrip(b"\r") + for line in finished_lines] + + return finished_lines, readable + + +class MoonApplication(): + def __init__(self): + return + + + def monitor_btmon(self): + out_r, out_w = pty.openpty() + cmd = ["sudo","btmon"] + process = subprocess.Popen(cmd, stdout=out_w) + f = OutStream(out_r) + while True: + lines, readable = f.read_lines() + if not readable: break + for line in lines: + if line != '': + line = line.decode() + if 'Data:' in line: + data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') + self.process_rx(data) + #self.logger.info('New data '+ data) + + def process_rx(self,ba): + new_problem_string= self.unstuffer.process_bytes(ba) + flags = self.unstuffer.flags + + if new_problem_string is not None: + problem= decode_problem_string(new_problem_string, flags) + self.new_problem(json.dumps(problem)) + self.unstuffer.flags = '' + start_adv() + +def setup_adv(logger): + logger.info('setup adv') + setup_adv = [ + "hcitool -i hci0 cmd 0x08 0x000a 00", + "hcitool -i hci0 cmd 0x08 0x0008 18 02 01 06 02 0a 00 11 07 9e ca dc 24 0e e5 a9 e0 93 f3 a3 b5 01 00 40 6e 00 00 00 00 00 00 00", + "hcitool -i hci0 cmd 0x08 0x0009 0d 0c 09 4d 6f 6f 6e 62 6f 61 72 64 20 41", + "hcitool -i hci0 cmd 0x08 0x0006 80 02 c0 03 00 00 00 00 00 00 00 00 00 07 00" + ] + for c in setup_adv: + run("sudo "+ c, shell=True) + + +def start_adv(logger,start=True): + if start: + start='01' + logger.info('start adv') + else: + start='00' + logger.info('stop adv') + start_adv= "hcitool -i hci0 cmd 0x08 0x000a {}".format(start) + run("sudo " +start_adv, shell=True) + +def main(logger,adapter): + logger.info("Bluetooth adapter: "+ str(adapter)) + app = MoonApplication(bus_name,None,logger) + + setup_adv(logger) + start_adv(logger) + + +if __name__ == '__main__': + + import argparse + parser = argparse.ArgumentParser(description='Moonboard bluetooth service') + parser.add_argument('--debug', action = "store_true") + + args = parser.parse_args() + argsd=vars(args) + + logger = logging.getLogger('moonboard.ble') + logger.setLevel(logging.DEBUG) + logger.addHandler(logging.StreamHandler()) + + if args.debug: + logger.setLevel(logging.DEBUG) + else: + logger.setLevel(logging.INFO) + + main(logger,adapter='/org/bluez/hci0') diff --git a/ble/simple_client.py b/ble/simple_client.py index 563e9b5..185629e 100755 --- a/ble/simple_client.py +++ b/ble/simple_client.py @@ -1,3 +1,4 @@ +# FIXME: delete, when port to MQTT done from gi.repository import GLib import dbus from dbus.mainloop.glib import DBusGMainLoop From cb4570a3bdb5a3e4c1343e157e7625661fdda441 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:28:28 +0100 Subject: [PATCH 169/240] fix --- ble/moon_ble_mqtt_proto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index afd0e21..e1db70d 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -122,7 +122,7 @@ def start_adv(logger,start=True): def main(logger,adapter): logger.info("Bluetooth adapter: "+ str(adapter)) - app = MoonApplication(bus_name,None,logger) + app = MoonApplication() setup_adv(logger) start_adv(logger) From 37ad6192c5c68ab4249ad21485c32c69886cf382 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:28:52 +0100 Subject: [PATCH 170/240] fix --- ble/moon_ble_mqtt_proto.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index e1db70d..6df5804 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -106,8 +106,8 @@ def setup_adv(logger): "hcitool -i hci0 cmd 0x08 0x0009 0d 0c 09 4d 6f 6f 6e 62 6f 61 72 64 20 41", "hcitool -i hci0 cmd 0x08 0x0006 80 02 c0 03 00 00 00 00 00 00 00 00 00 07 00" ] - for c in setup_adv: - run("sudo "+ c, shell=True) + #for c in setup_adv: + # run("sudo "+ c, shell=True) # FIXME def start_adv(logger,start=True): From 1e66170eff27a96027b03561bb19a528db8b8fa6 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:29:15 +0100 Subject: [PATCH 171/240] fix --- ble/moon_ble_mqtt_proto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 6df5804..ee3a525 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -118,7 +118,7 @@ def start_adv(logger,start=True): start='00' logger.info('stop adv') start_adv= "hcitool -i hci0 cmd 0x08 0x000a {}".format(start) - run("sudo " +start_adv, shell=True) + #run("sudo " +start_adv, shell=True) # FIXME def main(logger,adapter): logger.info("Bluetooth adapter: "+ str(adapter)) From fb3f8225297b3a70fbb9b96f2271c6cd1b013ea2 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:31:21 +0100 Subject: [PATCH 172/240] start adv --- ble/moon_ble_mqtt_proto.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index ee3a525..14768b9 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -99,6 +99,8 @@ def process_rx(self,ba): start_adv() def setup_adv(logger): + """ + Setup Advertisinf""" logger.info('setup adv') setup_adv = [ "hcitool -i hci0 cmd 0x08 0x000a 00", @@ -106,11 +108,14 @@ def setup_adv(logger): "hcitool -i hci0 cmd 0x08 0x0009 0d 0c 09 4d 6f 6f 6e 62 6f 61 72 64 20 41", "hcitool -i hci0 cmd 0x08 0x0006 80 02 c0 03 00 00 00 00 00 00 00 00 00 07 00" ] - #for c in setup_adv: - # run("sudo "+ c, shell=True) # FIXME + for c in setup_adv: + os.system("sudo "+ c) def start_adv(logger,start=True): + """ + Start Advertising + """ if start: start='01' logger.info('start adv') @@ -118,7 +123,7 @@ def start_adv(logger,start=True): start='00' logger.info('stop adv') start_adv= "hcitool -i hci0 cmd 0x08 0x000a {}".format(start) - #run("sudo " +start_adv, shell=True) # FIXME + os.system("sudo " +start_adv) def main(logger,adapter): logger.info("Bluetooth adapter: "+ str(adapter)) From f3e2d08b095364e113894ac7c1043ee7867afe79 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:35:29 +0100 Subject: [PATCH 173/240] btmon --- ble/moon_ble_mqtt_proto.py | 39 ++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 14768b9..7d3447c 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -72,21 +72,7 @@ def __init__(self): return - def monitor_btmon(self): - out_r, out_w = pty.openpty() - cmd = ["sudo","btmon"] - process = subprocess.Popen(cmd, stdout=out_w) - f = OutStream(out_r) - while True: - lines, readable = f.read_lines() - if not readable: break - for line in lines: - if line != '': - line = line.decode() - if 'Data:' in line: - data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') - self.process_rx(data) - #self.logger.info('New data '+ data) + def process_rx(self,ba): new_problem_string= self.unstuffer.process_bytes(ba) @@ -125,12 +111,33 @@ def start_adv(logger,start=True): start_adv= "hcitool -i hci0 cmd 0x08 0x000a {}".format(start) os.system("sudo " +start_adv) + + + +def monitor_btmon(logger): + out_r, out_w = pty.openpty() + cmd = ["sudo","btmon"] + process = subprocess.Popen(cmd, stdout=out_w) + f = OutStream(out_r) + while True: + lines, readable = f.read_lines() + if not readable: break + for line in lines: + if line != '': + line = line.decode() + if 'Data:' in line: + data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') + self.process_rx(data) + self.logger.info('New data '+ data) + + def main(logger,adapter): logger.info("Bluetooth adapter: "+ str(adapter)) app = MoonApplication() setup_adv(logger) start_adv(logger) + monitor_btmon(logger) if __name__ == '__main__': @@ -151,4 +158,4 @@ def main(logger,adapter): else: logger.setLevel(logging.INFO) - main(logger,adapter='/org/bluez/hci0') + main(logger,adapter='/org/bluez/hci0') # FIXME: use configured adapter From b092b7385921376541f98bbb79d5bd35e08f46cf Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:36:03 +0100 Subject: [PATCH 174/240] fix --- ble/moon_ble_mqtt_proto.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 7d3447c..8d9c3df 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -127,8 +127,8 @@ def monitor_btmon(logger): line = line.decode() if 'Data:' in line: data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') - self.process_rx(data) - self.logger.info('New data '+ data) + #self.process_rx(data) + logger.info('New data '+ data) def main(logger,adapter): From 56ccfccf43fd59df47175fd400d08097a13a9bf0 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:39:26 +0100 Subject: [PATCH 175/240] try decode --- ble/moon_ble_mqtt_proto.py | 73 ++++++-------------------------------- 1 file changed, 10 insertions(+), 63 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 8d9c3df..e64af48 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -20,69 +20,6 @@ UART_TX_CHARACTERISTIC_UUID = '6e400003-b5a3-f393-e0a9-e50e24dcca9e' LOCAL_NAME = 'Moonboard A' -class RxCharacteristic(Characteristic): - def __init__(self, bus, index, service, process_rx): - Characteristic.__init__(self, bus, index, UART_RX_CHARACTERISTIC_UUID, - ['write'], service) - self.process_rx=process_rx - - def WriteValue(self, value, options): - pass - #self.process_rx(value) - -class UartService(Service): - def __init__(self, bus,path, index, process_rx): - Service.__init__(self, bus,path, index, UART_SERVICE_UUID, True) - self.add_characteristic(RxCharacteristic(bus, 1, self, process_rx)) - -class OutStream: - def __init__(self, fileno): - self._fileno = fileno - self._buffer = b"" - - def read_lines(self): - try: - output = os.read(self._fileno, 1000) - except OSError as e: - if e.errno != errno.EIO: raise - output = b"" - lines = output.split(b"\n") - lines[0] = self._buffer + lines[0] # prepend previous - # non-finished line. - if output: - self._buffer = lines[-1] - finished_lines = lines[:-1] - readable = True - else: - self._buffer = b"" - if len(lines) == 1 and not lines[0]: - # We did not have buffer left, so no output at all. - lines = [] - finished_lines = lines - readable = False - - finished_lines = [line.rstrip(b"\r") - for line in finished_lines] - - return finished_lines, readable - - -class MoonApplication(): - def __init__(self): - return - - - - - def process_rx(self,ba): - new_problem_string= self.unstuffer.process_bytes(ba) - flags = self.unstuffer.flags - - if new_problem_string is not None: - problem= decode_problem_string(new_problem_string, flags) - self.new_problem(json.dumps(problem)) - self.unstuffer.flags = '' - start_adv() def setup_adv(logger): """ @@ -111,7 +48,15 @@ def start_adv(logger,start=True): start_adv= "hcitool -i hci0 cmd 0x08 0x000a {}".format(start) os.system("sudo " +start_adv) +def process_rx(ba): + new_problem_string= self.unstuffer.process_bytes(ba) + flags = self.unstuffer.flags + if new_problem_string is not None: + problem= decode_problem_string(new_problem_string, flags) + #self.new_problem(json.dumps(problem)) + #self.unstuffer.flags = '' + #start_adv() def monitor_btmon(logger): @@ -128,7 +73,9 @@ def monitor_btmon(logger): if 'Data:' in line: data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') #self.process_rx(data) + t1 = bytearray.fromhex(data).decode() logger.info('New data '+ data) + logger.info('New data dec? '+ t1) def main(logger,adapter): From 9b3cab06fce14520cfbef87ccc0d40d2b1902ae3 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:39:42 +0100 Subject: [PATCH 176/240] fix --- ble/moon_ble_mqtt_proto.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index e64af48..3611661 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -80,7 +80,6 @@ def monitor_btmon(logger): def main(logger,adapter): logger.info("Bluetooth adapter: "+ str(adapter)) - app = MoonApplication() setup_adv(logger) start_adv(logger) From 1f14ba0f149803dc40b2b4489722fd52143e5ea1 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:40:33 +0100 Subject: [PATCH 177/240] re-insert outstream --- ble/moon_ble_mqtt_proto.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 3611661..ff4629d 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -21,6 +21,40 @@ LOCAL_NAME = 'Moonboard A' +class OutStream: # FIXME: simplify + def __init__(self, fileno): + self._fileno = fileno + self._buffer = b"" + + def read_lines(self): + try: + output = os.read(self._fileno, 1000) + except OSError as e: + if e.errno != errno.EIO: raise + output = b"" + lines = output.split(b"\n") + lines[0] = self._buffer + lines[0] # prepend previous + # non-finished line. + if output: + self._buffer = lines[-1] + finished_lines = lines[:-1] + readable = True + else: + self._buffer = b"" + if len(lines) == 1 and not lines[0]: + # We did not have buffer left, so no output at all. + lines = [] + finished_lines = lines + readable = False + + finished_lines = [line.rstrip(b"\r") + for line in finished_lines] + + return finished_lines, readable + + + + def setup_adv(logger): """ Setup Advertisinf""" From 1ac5a6ace4593fe5e70e19ff4c6e578538e62e4a Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:47:32 +0100 Subject: [PATCH 178/240] unstuffer hack --- ble/moon_ble_mqtt_proto.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index ff4629d..3cf0b58 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -82,18 +82,18 @@ def start_adv(logger,start=True): start_adv= "hcitool -i hci0 cmd 0x08 0x000a {}".format(start) os.system("sudo " +start_adv) -def process_rx(ba): - new_problem_string= self.unstuffer.process_bytes(ba) - flags = self.unstuffer.flags +def process_rx(unstuffer,logger,ba): + new_problem_string= unstuffer.process_bytes(ba) + flags = unstuffer.flags if new_problem_string is not None: problem= decode_problem_string(new_problem_string, flags) - #self.new_problem(json.dumps(problem)) - #self.unstuffer.flags = '' - #start_adv() + print(json.dumps(problem)) # FIXME + unstuffer.flags = '' + start_adv(logger) -def monitor_btmon(logger): +def monitor_btmon(logger,unstuffer): out_r, out_w = pty.openpty() cmd = ["sudo","btmon"] process = subprocess.Popen(cmd, stdout=out_w) @@ -106,7 +106,7 @@ def monitor_btmon(logger): line = line.decode() if 'Data:' in line: data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') - #self.process_rx(data) + self.process_rx(unstuffer,logger,data) t1 = bytearray.fromhex(data).decode() logger.info('New data '+ data) logger.info('New data dec? '+ t1) @@ -115,9 +115,11 @@ def monitor_btmon(logger): def main(logger,adapter): logger.info("Bluetooth adapter: "+ str(adapter)) + unstuffer= UnstuffSequence(logger) + setup_adv(logger) start_adv(logger) - monitor_btmon(logger) + monitor_btmon(logger,unstuffer) if __name__ == '__main__': From 51cac7d9c9df3fb1bd14a8e4e710c57350b9941e Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:47:54 +0100 Subject: [PATCH 179/240] fix --- ble/moon_ble_mqtt_proto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 3cf0b58..f7e3e72 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -106,7 +106,7 @@ def monitor_btmon(logger,unstuffer): line = line.decode() if 'Data:' in line: data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') - self.process_rx(unstuffer,logger,data) + process_rx(unstuffer,logger,data) t1 = bytearray.fromhex(data).decode() logger.info('New data '+ data) logger.info('New data dec? '+ t1) From 813ee20aae26200b5a5af01f5e722a23cc596340 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:52:59 +0100 Subject: [PATCH 180/240] class hack --- ble/moon_ble_mqtt_proto.py | 144 +++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 68 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index f7e3e72..8655685 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -6,11 +6,16 @@ import subprocess import logging from moonboard_app_protocol import UnstuffSequence, decode_problem_string +import paho.mqtt.client as paho # FIXME pip install import os import threading import pty +# FIXME: remove dead code +# FIXME: create a class, please +# FIXME: cleanup code & simplify(!) + BLUEZ_SERVICE_NAME = 'org.bluez' LE_ADVERTISING_MANAGER_IFACE = 'org.bluez.LEAdvertisingManager1' GATT_MANAGER_IFACE = 'org.bluez.GattManager1' @@ -52,74 +57,76 @@ def read_lines(self): return finished_lines, readable +class MoonboardBLE(): + def __init__(self): + return + + + def setup_adv(self,logger): + """ + Setup Advertisinf""" + logger.info('setup adv') + setup_adv = [ + "hcitool -i hci0 cmd 0x08 0x000a 00", + "hcitool -i hci0 cmd 0x08 0x0008 18 02 01 06 02 0a 00 11 07 9e ca dc 24 0e e5 a9 e0 93 f3 a3 b5 01 00 40 6e 00 00 00 00 00 00 00", + "hcitool -i hci0 cmd 0x08 0x0009 0d 0c 09 4d 6f 6f 6e 62 6f 61 72 64 20 41", + "hcitool -i hci0 cmd 0x08 0x0006 80 02 c0 03 00 00 00 00 00 00 00 00 00 07 00" + ] + for c in setup_adv: + os.system("sudo "+ c) + + + def start_adv(self,logger,start=True): + """ + Start Advertising + """ + if start: + start='01' + logger.info('start adv') + else: + start='00' + logger.info('stop adv') + start_adv= "hcitool -i hci0 cmd 0x08 0x000a {}".format(start) + os.system("sudo " +start_adv) + + def process_rx(self, unstuffer,logger,ba): + new_problem_string= unstuffer.process_bytes(ba) + flags = unstuffer.flags + + if new_problem_string is not None: + problem= decode_problem_string(new_problem_string, flags) + print(json.dumps(problem)) # FIXME + unstuffer.flags = '' + self.start_adv(logger) + + + def monitor_btmon(self, logger,unstuffer): + out_r, out_w = pty.openpty() + cmd = ["sudo","btmon"] + process = subprocess.Popen(cmd, stdout=out_w) + f = OutStream(out_r) + while True: + lines, readable = f.read_lines() + if not readable: break + for line in lines: + if line != '': + line = line.decode() + if 'Data:' in line: + data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') + self.process_rx(unstuffer,logger,data) + t1 = bytearray.fromhex(data).decode() + logger.info('New data '+ data) + logger.info('New data dec? '+ t1) + + + def main(self,logger,adapter): + logger.info("Bluetooth adapter: "+ str(adapter)) + + unstuffer= UnstuffSequence(logger) - - -def setup_adv(logger): - """ - Setup Advertisinf""" - logger.info('setup adv') - setup_adv = [ - "hcitool -i hci0 cmd 0x08 0x000a 00", - "hcitool -i hci0 cmd 0x08 0x0008 18 02 01 06 02 0a 00 11 07 9e ca dc 24 0e e5 a9 e0 93 f3 a3 b5 01 00 40 6e 00 00 00 00 00 00 00", - "hcitool -i hci0 cmd 0x08 0x0009 0d 0c 09 4d 6f 6f 6e 62 6f 61 72 64 20 41", - "hcitool -i hci0 cmd 0x08 0x0006 80 02 c0 03 00 00 00 00 00 00 00 00 00 07 00" - ] - for c in setup_adv: - os.system("sudo "+ c) - - -def start_adv(logger,start=True): - """ - Start Advertising - """ - if start: - start='01' - logger.info('start adv') - else: - start='00' - logger.info('stop adv') - start_adv= "hcitool -i hci0 cmd 0x08 0x000a {}".format(start) - os.system("sudo " +start_adv) - -def process_rx(unstuffer,logger,ba): - new_problem_string= unstuffer.process_bytes(ba) - flags = unstuffer.flags - - if new_problem_string is not None: - problem= decode_problem_string(new_problem_string, flags) - print(json.dumps(problem)) # FIXME - unstuffer.flags = '' - start_adv(logger) - - -def monitor_btmon(logger,unstuffer): - out_r, out_w = pty.openpty() - cmd = ["sudo","btmon"] - process = subprocess.Popen(cmd, stdout=out_w) - f = OutStream(out_r) - while True: - lines, readable = f.read_lines() - if not readable: break - for line in lines: - if line != '': - line = line.decode() - if 'Data:' in line: - data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') - process_rx(unstuffer,logger,data) - t1 = bytearray.fromhex(data).decode() - logger.info('New data '+ data) - logger.info('New data dec? '+ t1) - - -def main(logger,adapter): - logger.info("Bluetooth adapter: "+ str(adapter)) - - unstuffer= UnstuffSequence(logger) - - setup_adv(logger) - start_adv(logger) - monitor_btmon(logger,unstuffer) + self.setup_adv(logger) + self.start_adv(logger) + self.monitor_btmon(logger,unstuffer) if __name__ == '__main__': @@ -140,4 +147,5 @@ def main(logger,adapter): else: logger.setLevel(logging.INFO) - main(logger,adapter='/org/bluez/hci0') # FIXME: use configured adapter + mbble = MoonboardBLE() + mbble.main(logger,adapter='/org/bluez/hci0') # FIXME: use configured adapter From 5424ca07dba38f7ca7da03736cc12d1d28be3c49 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:56:48 +0100 Subject: [PATCH 181/240] mqtt stub --- ble/moon_ble_mqtt_proto.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 8655685..9d9fc55 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -6,14 +6,13 @@ import subprocess import logging from moonboard_app_protocol import UnstuffSequence, decode_problem_string -import paho.mqtt.client as paho # FIXME pip install +import paho.mqtt.client as mqtt import os import threading import pty # FIXME: remove dead code -# FIXME: create a class, please # FIXME: cleanup code & simplify(!) BLUEZ_SERVICE_NAME = 'org.bluez' @@ -61,7 +60,6 @@ class MoonboardBLE(): def __init__(self): return - def setup_adv(self,logger): """ Setup Advertisinf""" @@ -75,7 +73,6 @@ def setup_adv(self,logger): for c in setup_adv: os.system("sudo "+ c) - def start_adv(self,logger,start=True): """ Start Advertising @@ -99,8 +96,7 @@ def process_rx(self, unstuffer,logger,ba): unstuffer.flags = '' self.start_adv(logger) - - def monitor_btmon(self, logger,unstuffer): + def monitor_btmon(self, logger, unstuffer): out_r, out_w = pty.openpty() cmd = ["sudo","btmon"] process = subprocess.Popen(cmd, stdout=out_w) @@ -128,7 +124,19 @@ def main(self,logger,adapter): self.start_adv(logger) self.monitor_btmon(logger,unstuffer) + def _start_mqtt(self): + # Connect to MQTT + self._client = mqtt.Client() + self._client.connect(hostname, port,60) + self._sendmessage("/status", "Starting") + def _sendmessage(self, topic="/none", message="None"): + ttopic = "moonboard/ble/"+topic + mmessage = str(message) + #logging.debug("MQTT>: " + ttopic + " ###> " + mmessage) + self._client.publish(ttopic, mmessage) + + if __name__ == '__main__': import argparse From c24480217e3b70edbd8e70e9feac6404255f90ea Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 18:59:28 +0100 Subject: [PATCH 182/240] start mqtt --- ble/moon_ble_mqtt_proto.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 9d9fc55..91b935c 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -58,6 +58,7 @@ def read_lines(self): class MoonboardBLE(): def __init__(self): + self._start_mqtt() return def setup_adv(self,logger): @@ -93,6 +94,7 @@ def process_rx(self, unstuffer,logger,ba): if new_problem_string is not None: problem= decode_problem_string(new_problem_string, flags) print(json.dumps(problem)) # FIXME + self._sendmessage("/problem", json.dumps(problem)) # FIXME unstuffer.flags = '' self.start_adv(logger) @@ -126,6 +128,8 @@ def main(self,logger,adapter): def _start_mqtt(self): # Connect to MQTT + hostname = "raspi-moonboard" # FIXME + port = 1883 # FIXME self._client = mqtt.Client() self._client.connect(hostname, port,60) self._sendmessage("/status", "Starting") From 0b340d48425181773036225cb3934463fab1d1df Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 19:13:22 +0100 Subject: [PATCH 183/240] frontend proto --- ble/moon_ble_mqtt_proto.py | 4 +- run_proto_mqtt_frontend.py | 94 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 run_proto_mqtt_frontend.py diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 91b935c..7933b0e 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -24,6 +24,8 @@ UART_TX_CHARACTERISTIC_UUID = '6e400003-b5a3-f393-e0a9-e50e24dcca9e' LOCAL_NAME = 'Moonboard A' +# FIXME: on connection lost: error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 2: invalid start byte + class OutStream: # FIXME: simplify def __init__(self, fileno): @@ -135,7 +137,7 @@ def _start_mqtt(self): self._sendmessage("/status", "Starting") def _sendmessage(self, topic="/none", message="None"): - ttopic = "moonboard/ble/"+topic + ttopic = "moonboard/ble"+topic mmessage = str(message) #logging.debug("MQTT>: " + ttopic + " ###> " + mmessage) self._client.publish(ttopic, mmessage) diff --git a/run_proto_mqtt_frontend.py b/run_proto_mqtt_frontend.py new file mode 100644 index 0000000..31487b5 --- /dev/null +++ b/run_proto_mqtt_frontend.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +import argparse +from led.moonboard import MoonBoard +from functools import partial +import json +import RPi.GPIO as GPIO +import os +#import signal +import sys +import logging +import time +import paho.mqtt.client as paho # FIXME pip install +import math # floor + +# external power LED and power button +LED_GPIO = 26 +BUTTON_GPIO = 3 + + +import logging +logging.basicConfig(level=logging.DEBUG, + format='Display(%(threadName)-10s) %(message)s', + ) + +class Database(): + def __init__(self, driver_type="", led_layout=""): + self._MOONBOARD = MoonBoard(driver_type, led_layout) + + # Init timers + self._time_current = time.time() + self._time_last = self._time_current + self._update_interval = 1.0 #0.5 # Update interval for display in seconds + + + def _on_message(self, client, userdata, message): + logging.debug("Received message " + str(message.payload.decode("utf-8"))) + + msg = json.loads(message.payload.decode("utf-8")) + + #self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], color_1er_done) + #self._MOONBOARD.layout.push_to_driver() + + + + def _record_data(self, hostname="localhost",port=1883): + logging.debug("Start recording data from mqtt to database") + self._client= paho.Client("client-001") # FIXME + self._client.on_message=self._on_message + self._client.connect(hostname,port,60)#connect + + # FIXME: subscribe to all? + + self._client.subscribe("moonboard/ble/problem") + + + self._client.loop_forever() + +# Main stuff + +if __name__ == "__main__": + + parser = argparse.ArgumentParser(description='') + + parser.add_argument('--driver_type', + help='driver type, depends on leds and device controlling the led.', + choices=['PiWS281x', 'WS2801', 'SimPixel'], + default='PiWS281x') + + parser.add_argument('--brightness', default=100, type=int) + + parser.add_argument('--led_mapping', + type=str, + default='led_mapping.json', + ) + + parser.add_argument('--debug', action = "store_true") + + args = parser.parse_args() + argsd=vars(args) + logger = logging.getLogger('run') + logger.setLevel(logging.DEBUG) + logger.addHandler(logging.StreamHandler()) + + if args.debug: + logger.setLevel(logging.DEBUG) + else: + logger.setLevel(logging.INFO) + + #problems + led_layout = args.led_mapping + driver_type = args.driver_type + + d = Database(driver_type=driver_type, led_layout=led_layout) + d._record_data(hostname="raspi-hangboard") From d10685bf23f1ec58a7c7b6f1856728e6a0fc958d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 19:14:22 +0100 Subject: [PATCH 184/240] fix --- run_proto_mqtt_frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_proto_mqtt_frontend.py b/run_proto_mqtt_frontend.py index 31487b5..34ca6dd 100644 --- a/run_proto_mqtt_frontend.py +++ b/run_proto_mqtt_frontend.py @@ -91,4 +91,4 @@ def _record_data(self, hostname="localhost",port=1883): driver_type = args.driver_type d = Database(driver_type=driver_type, led_layout=led_layout) - d._record_data(hostname="raspi-hangboard") + d._record_data(hostname="raspi-moonboard") From fa698411d90fc74a64e82c301d11785d97425966 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 19:16:40 +0100 Subject: [PATCH 185/240] display hold --- run_proto_mqtt_frontend.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/run_proto_mqtt_frontend.py b/run_proto_mqtt_frontend.py index 34ca6dd..5f44417 100644 --- a/run_proto_mqtt_frontend.py +++ b/run_proto_mqtt_frontend.py @@ -34,11 +34,16 @@ def __init__(self, driver_type="", led_layout=""): def _on_message(self, client, userdata, message): logging.debug("Received message " + str(message.payload.decode("utf-8"))) - + mm = message.payload.decode("utf-8") msg = json.loads(message.payload.decode("utf-8")) + color_start = (0,255,0) + self._MOONBOARD.clear() + for s in mm["START"]: + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[s], color_start) + #self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], color_1er_done) - #self._MOONBOARD.layout.push_to_driver() + self._MOONBOARD.layout.push_to_driver() From 7dad35dcc089a96ddfb14af7f590aaddceeecdca Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 19:17:42 +0100 Subject: [PATCH 186/240] checkup --- run_proto_mqtt_frontend.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/run_proto_mqtt_frontend.py b/run_proto_mqtt_frontend.py index 5f44417..ecb99ce 100644 --- a/run_proto_mqtt_frontend.py +++ b/run_proto_mqtt_frontend.py @@ -38,12 +38,12 @@ def _on_message(self, client, userdata, message): msg = json.loads(message.payload.decode("utf-8")) color_start = (0,255,0) - self._MOONBOARD.clear() - for s in mm["START"]: - self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[s], color_start) + #self._MOONBOARD.clear() + #for s in mm["START"]: + # self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[s], color_start) #self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], color_1er_done) - self._MOONBOARD.layout.push_to_driver() + #self._MOONBOARD.layout.push_to_driver() From 18a027824714b89410c2bed865e789228f8f3e77 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 19:18:38 +0100 Subject: [PATCH 187/240] fix --- run_proto_mqtt_frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_proto_mqtt_frontend.py b/run_proto_mqtt_frontend.py index ecb99ce..699c167 100644 --- a/run_proto_mqtt_frontend.py +++ b/run_proto_mqtt_frontend.py @@ -34,7 +34,7 @@ def __init__(self, driver_type="", led_layout=""): def _on_message(self, client, userdata, message): logging.debug("Received message " + str(message.payload.decode("utf-8"))) - mm = message.payload.decode("utf-8") + #mm = message.payload.decode("utf-8") msg = json.loads(message.payload.decode("utf-8")) color_start = (0,255,0) From 4d3771ef8ad55f4cb94d6931a18d166244af6578 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 19:21:31 +0100 Subject: [PATCH 188/240] display on --- run_proto_mqtt_frontend.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/run_proto_mqtt_frontend.py b/run_proto_mqtt_frontend.py index 699c167..5f44417 100644 --- a/run_proto_mqtt_frontend.py +++ b/run_proto_mqtt_frontend.py @@ -34,16 +34,16 @@ def __init__(self, driver_type="", led_layout=""): def _on_message(self, client, userdata, message): logging.debug("Received message " + str(message.payload.decode("utf-8"))) - #mm = message.payload.decode("utf-8") + mm = message.payload.decode("utf-8") msg = json.loads(message.payload.decode("utf-8")) color_start = (0,255,0) - #self._MOONBOARD.clear() - #for s in mm["START"]: - # self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[s], color_start) + self._MOONBOARD.clear() + for s in mm["START"]: + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[s], color_start) #self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], color_1er_done) - #self._MOONBOARD.layout.push_to_driver() + self._MOONBOARD.layout.push_to_driver() From 27dffe63a4d864eb7ad6e2e62fec70fe05f1b6bd Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 19:23:00 +0100 Subject: [PATCH 189/240] fix --- run_proto_mqtt_frontend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_proto_mqtt_frontend.py b/run_proto_mqtt_frontend.py index 5f44417..a862037 100644 --- a/run_proto_mqtt_frontend.py +++ b/run_proto_mqtt_frontend.py @@ -34,12 +34,12 @@ def __init__(self, driver_type="", led_layout=""): def _on_message(self, client, userdata, message): logging.debug("Received message " + str(message.payload.decode("utf-8"))) - mm = message.payload.decode("utf-8") + #mm = message.payload.decode("utf-8") msg = json.loads(message.payload.decode("utf-8")) color_start = (0,255,0) self._MOONBOARD.clear() - for s in mm["START"]: + for s in msg["START"]: self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[s], color_start) #self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], color_1er_done) From 0054cb3e83927e026668b44ce0561f9a9a2d94d0 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 19:24:30 +0100 Subject: [PATCH 190/240] all holds --- run_proto_mqtt_frontend.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/run_proto_mqtt_frontend.py b/run_proto_mqtt_frontend.py index a862037..0cc637d 100644 --- a/run_proto_mqtt_frontend.py +++ b/run_proto_mqtt_frontend.py @@ -38,10 +38,15 @@ def _on_message(self, client, userdata, message): msg = json.loads(message.payload.decode("utf-8")) color_start = (0,255,0) + color_moves = (0,0,255) + color_top = (255,0,0) self._MOONBOARD.clear() for s in msg["START"]: self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[s], color_start) - + for m in msg["START"]: + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[m], color_moves) + for t in msg["TOP"]: + self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[t], color_top) #self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[ihold], color_1er_done) self._MOONBOARD.layout.push_to_driver() From 50868375d8ff688260b3671e0f11d9e286b2dcd9 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 19:25:24 +0100 Subject: [PATCH 191/240] fix --- run_proto_mqtt_frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_proto_mqtt_frontend.py b/run_proto_mqtt_frontend.py index 0cc637d..38af3ec 100644 --- a/run_proto_mqtt_frontend.py +++ b/run_proto_mqtt_frontend.py @@ -43,7 +43,7 @@ def _on_message(self, client, userdata, message): self._MOONBOARD.clear() for s in msg["START"]: self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[s], color_start) - for m in msg["START"]: + for m in msg["MOVES"]: self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[m], color_moves) for t in msg["TOP"]: self._MOONBOARD.layout.set(self._MOONBOARD.MAPPING[t], color_top) From d9611a5126f2e9d42c3f1a6faf25fd5f696f90ea Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 20:47:19 +0100 Subject: [PATCH 192/240] error reconnect ble traced! --- ble/ERROR-RECONNECT.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ble/ERROR-RECONNECT.md diff --git a/ble/ERROR-RECONNECT.md b/ble/ERROR-RECONNECT.md new file mode 100644 index 0000000..690fafe --- /dev/null +++ b/ble/ERROR-RECONNECT.md @@ -0,0 +1,22 @@ +{"START": ["E4", "H3"], "MOVES": ["E8", "B13", "A16", "A11"], "TOP": ["D18"], "FLAGS": [""]} +start adv +< HCI Command: ogf 0x08, ocf 0x000a, plen 1 + 01 +> HCI Event: 0x0e plen 4 + 01 0A 20 0C +New data 31352c5031302c45353423 +New data dec? 15,P10,E54# + + +Traceback (most recent call last): + File "moon_ble_mqtt_proto.py", line 165, in + mbble.main(logger,adapter='/org/bluez/hci0') # FIXME: use configured adapter + File "moon_ble_mqtt_proto.py", line 129, in main + self.monitor_btmon(logger,unstuffer) + File "moon_ble_mqtt_proto.py", line 116, in monitor_btmon + self.process_rx(unstuffer,logger,data) + File "moon_ble_mqtt_proto.py", line 93, in process_rx + new_problem_string= unstuffer.process_bytes(ba) + File "/home/pi/moonboard/ble/moonboard_app_protocol.py", line 54, in process_bytes + s = bytearray.fromhex(ba).decode() +UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 2: invalid start byte From f21317772651fa8c3e88c6c7244e5ffb64be5348 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 20:52:19 +0100 Subject: [PATCH 193/240] try fix encoding --- ble/moon_ble_mqtt_proto.py | 2 +- ble/moonboard_app_protocol.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 7933b0e..3c1a56f 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -114,7 +114,7 @@ def monitor_btmon(self, logger, unstuffer): if 'Data:' in line: data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') self.process_rx(unstuffer,logger,data) - t1 = bytearray.fromhex(data).decode() + t1 = bytearray.fromhex(data).decode("utf-16") logger.info('New data '+ data) logger.info('New data dec? '+ t1) diff --git a/ble/moonboard_app_protocol.py b/ble/moonboard_app_protocol.py index 71152e6..76e2b1a 100755 --- a/ble/moonboard_app_protocol.py +++ b/ble/moonboard_app_protocol.py @@ -51,7 +51,7 @@ def process_bytes(self, ba): handle some error due to multiple connected devices sending simoultaneously. """ - s = bytearray.fromhex(ba).decode() + s = bytearray.fromhex(ba).decode("utf-16") self.logger.debug("incoming bytes:"+str(s)) if s[0] == '~' and s[-1] == '*': From 0aaaf5a0dd0a1211d5947921d2e99e830cf2173a Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 20:53:18 +0100 Subject: [PATCH 194/240] utf-16 does not work --- ble/moon_ble_mqtt_proto.py | 2 +- ble/moonboard_app_protocol.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 3c1a56f..7933b0e 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -114,7 +114,7 @@ def monitor_btmon(self, logger, unstuffer): if 'Data:' in line: data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') self.process_rx(unstuffer,logger,data) - t1 = bytearray.fromhex(data).decode("utf-16") + t1 = bytearray.fromhex(data).decode() logger.info('New data '+ data) logger.info('New data dec? '+ t1) diff --git a/ble/moonboard_app_protocol.py b/ble/moonboard_app_protocol.py index 76e2b1a..71152e6 100755 --- a/ble/moonboard_app_protocol.py +++ b/ble/moonboard_app_protocol.py @@ -51,7 +51,7 @@ def process_bytes(self, ba): handle some error due to multiple connected devices sending simoultaneously. """ - s = bytearray.fromhex(ba).decode("utf-16") + s = bytearray.fromhex(ba).decode() self.logger.debug("incoming bytes:"+str(s)) if s[0] == '~' and s[-1] == '*': From 4fac854f92e6550447848e1a73850945ac6fc21a Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 20:57:25 +0100 Subject: [PATCH 195/240] fix try ignore errors --- ble/moon_ble_mqtt_proto.py | 2 +- ble/moonboard_app_protocol.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 7933b0e..435bf4b 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -114,7 +114,7 @@ def monitor_btmon(self, logger, unstuffer): if 'Data:' in line: data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') self.process_rx(unstuffer,logger,data) - t1 = bytearray.fromhex(data).decode() + t1 = bytearray.fromhex(data).decode(errors="ignore") logger.info('New data '+ data) logger.info('New data dec? '+ t1) diff --git a/ble/moonboard_app_protocol.py b/ble/moonboard_app_protocol.py index 71152e6..8c3dcc2 100755 --- a/ble/moonboard_app_protocol.py +++ b/ble/moonboard_app_protocol.py @@ -51,7 +51,7 @@ def process_bytes(self, ba): handle some error due to multiple connected devices sending simoultaneously. """ - s = bytearray.fromhex(ba).decode() + s = bytearray.fromhex(ba).decode(errors="ignore") self.logger.debug("incoming bytes:"+str(s)) if s[0] == '~' and s[-1] == '*': From 2a199bb95ce90bc05eefa4cab3ebf97fc1620430 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:14:25 +0100 Subject: [PATCH 196/240] debug --- ble/moon_ble_mqtt_proto.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_mqtt_proto.py index 435bf4b..14634fa 100755 --- a/ble/moon_ble_mqtt_proto.py +++ b/ble/moon_ble_mqtt_proto.py @@ -115,8 +115,7 @@ def monitor_btmon(self, logger, unstuffer): data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') self.process_rx(unstuffer,logger,data) t1 = bytearray.fromhex(data).decode(errors="ignore") - logger.info('New data '+ data) - logger.info('New data dec? '+ t1) + logger.info('New data '+ data+ 'and decoded '+t1) def main(self,logger,adapter): From e0861387a7ea926adb407a9645f5c20bc58c5472 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:21:14 +0100 Subject: [PATCH 197/240] install new service --- ble/Makefile | 11 + ble/com.moonboard.conf | 18 -- ble/com.moonboard.service | 17 -- ..._ble_mqtt_proto.py => moon_ble_service.py} | 0 ble/moonboard_BLE_service.py | 251 ------------------ ble/moonboard_ble.service | 13 + ble/simple_client.py | 31 --- services/moonboard.service | 13 - 8 files changed, 24 insertions(+), 330 deletions(-) create mode 100644 ble/Makefile delete mode 100755 ble/com.moonboard.conf delete mode 100755 ble/com.moonboard.service rename ble/{moon_ble_mqtt_proto.py => moon_ble_service.py} (100%) delete mode 100755 ble/moonboard_BLE_service.py create mode 100755 ble/moonboard_ble.service delete mode 100755 ble/simple_client.py delete mode 100755 services/moonboard.service diff --git a/ble/Makefile b/ble/Makefile new file mode 100644 index 0000000..1cc335c --- /dev/null +++ b/ble/Makefile @@ -0,0 +1,11 @@ +#api-doc: +# docker run --rm -it -v $(PWD)/ble_api.yaml:/app/asyncapi.yml -v $(PWD)/api:/app/output asyncapi/generator -o /app/output /app/asyncapi.yml @asyncapi/html-template --force-write + +install: + service="moonboard_ble.service" + echo "Install moonboard service for: moonboard_ble.service" + sudo cp ./moonboard_ble.service /lib/systemd/system/ + sudo chmod 644 /lib/systemd/system/moonboard_ble.service + sudo systemctl daemon-reload + sudo systemctl enable moonboard_ble.service + sudo systemctl restart moonboard_ble.service diff --git a/ble/com.moonboard.conf b/ble/com.moonboard.conf deleted file mode 100755 index a503c6c..0000000 --- a/ble/com.moonboard.conf +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ble/com.moonboard.service b/ble/com.moonboard.service deleted file mode 100755 index 6723244..0000000 --- a/ble/com.moonboard.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Moonboard BLE DBUS Service -After=multi-user.target bluetooth.service dbus.service hciuart.service -SystemdService=dbus-org.com.moonbooard.service -# FIXME: SystemdService not known - -[Service] -Type=dbus -BusName=com.moonboard -ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_BLE_service.py -User=root -StandardOutput=file:/var/log/moonboard_ble_stdout.log -StandardError=file:/var/log/moonboard_ble_stderr.log - -[Install] -WantedBy=multi-user.target - diff --git a/ble/moon_ble_mqtt_proto.py b/ble/moon_ble_service.py similarity index 100% rename from ble/moon_ble_mqtt_proto.py rename to ble/moon_ble_service.py diff --git a/ble/moonboard_BLE_service.py b/ble/moonboard_BLE_service.py deleted file mode 100755 index d4ffc42..0000000 --- a/ble/moonboard_BLE_service.py +++ /dev/null @@ -1,251 +0,0 @@ -import sys -import dbus, dbus.mainloop.glib -from gi.repository import GLib -from gatt_base.gatt_lib_advertisement import Advertisement -from gatt_base.gatt_lib_characteristic import Characteristic -from gatt_base.gatt_lib_service import Service -import string,json -import subprocess -import logging -from moonboard_app_protocol import UnstuffSequence, decode_problem_string - -import os -import threading -import pty - -BLUEZ_SERVICE_NAME = 'org.bluez' -DBUS_OM_IFACE = 'org.freedesktop.DBus.ObjectManager' -LE_ADVERTISING_MANAGER_IFACE = 'org.bluez.LEAdvertisingManager1' -GATT_MANAGER_IFACE = 'org.bluez.GattManager1' -GATT_CHRC_IFACE = 'org.bluez.GattCharacteristic1' -UART_SERVICE_UUID = '6e400001-b5a3-f393-e0a9-e50e24dcca9e' -UART_RX_CHARACTERISTIC_UUID = '6e400002-b5a3-f393-e0a9-e50e24dcca9e' -UART_TX_CHARACTERISTIC_UUID = '6e400003-b5a3-f393-e0a9-e50e24dcca9e' -LOCAL_NAME = 'Moonboard A' -SERVICE_NAME= 'com.moonboard' -mainloop = None - -class RxCharacteristic(Characteristic): - def __init__(self, bus, index, service, process_rx): - Characteristic.__init__(self, bus, index, UART_RX_CHARACTERISTIC_UUID, - ['write'], service) - self.process_rx=process_rx - - def WriteValue(self, value, options): - pass - #self.process_rx(value) - -class UartService(Service): - def __init__(self, bus,path, index, process_rx): - Service.__init__(self, bus,path, index, UART_SERVICE_UUID, True) - self.add_characteristic(RxCharacteristic(bus, 1, self, process_rx)) - -class OutStream: - def __init__(self, fileno): - self._fileno = fileno - self._buffer = b"" - - def read_lines(self): - try: - output = os.read(self._fileno, 1000) - except OSError as e: - if e.errno != errno.EIO: raise - output = b"" - lines = output.split(b"\n") - lines[0] = self._buffer + lines[0] # prepend previous - # non-finished line. - if output: - self._buffer = lines[-1] - finished_lines = lines[:-1] - readable = True - else: - self._buffer = b"" - if len(lines) == 1 and not lines[0]: - # We did not have buffer left, so no output at all. - lines = [] - finished_lines = lines - readable = False - - finished_lines = [line.rstrip(b"\r") - for line in finished_lines] - - return finished_lines, readable - - -class MoonApplication(dbus.service.Object): - IFACE = "com.moonboard.method" - def __init__(self, bus, socket,logger): - self.path = '/com/moonboard' - self.services = [] - self.logger=logger - self.unstuffer= UnstuffSequence(self.logger) - dbus.service.Object.__init__(self, bus, self.path) - self.add_service(UartService(bus,self.get_path(), 0, self.process_rx)) - - monitor_thread = threading.Thread(target=self.monitor_btmon) - monitor_thread.start() - - def monitor_btmon(self): - out_r, out_w = pty.openpty() - cmd = ["sudo","btmon"] - process = subprocess.Popen(cmd, stdout=out_w) - f = OutStream(out_r) - while True: - lines, readable = f.read_lines() - if not readable: break - for line in lines: - if line != '': - line = line.decode() - if 'Data:' in line: - data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') - self.process_rx(data) - self.logger.info('New data '+ data) - - def process_rx(self,ba): - new_problem_string= self.unstuffer.process_bytes(ba) - flags = self.unstuffer.flags - - if new_problem_string is not None: - problem= decode_problem_string(new_problem_string, flags) - self.new_problem(json.dumps(problem)) - self.unstuffer.flags = '' - start_adv(self.logger) - - @dbus.service.signal(dbus_interface="com.moonboard", - signature="s") - def new_problem(self, problem): - self.logger.info('Signal new problem: '+ str(problem)) - - def get_path(self): - return dbus.ObjectPath(self.path) - - def add_service(self, service): - self.services.append(service) - - @dbus.service.method(DBUS_OM_IFACE, out_signature='a{oa{sa{sv}}}') - def GetManagedObjects(self): - response = {} - for service in self.services: - response[service.get_path()] = service.get_properties() - chrcs = service.get_characteristics() - for chrc in chrcs: - response[chrc.get_path()] = chrc.get_properties() - return response - -def register_app_cb(): - print('GATT application registered') - - -def register_app_error_cb(error): - print('Failed to register application: ' + str(error)) - mainloop.quit() - - -def run(*popenargs, **kwargs): - input = kwargs.pop("input", None) - check = kwargs.pop("handle", False) - - if input is not None: - if 'stdin' in kwargs: - raise ValueError('stdin and input arguments may not both be used.') - kwargs['stdin'] = subprocess.PIPE - - process = subprocess.Popen(*popenargs, **kwargs) - try: - stdout, stderr = process.communicate(input) - except: - process.kill() - process.wait() - raise - retcode = process.poll() - if check and retcode: - raise subprocess.CalledProcessError( - retcode, process.args, output=stdout, stderr=stderr) - return retcode, stdout, stderr - - -def setup_adv(logger): - logger.info('setup adv') - setup_adv = [ - "hcitool -i hci0 cmd 0x08 0x000a 00", - "hcitool -i hci0 cmd 0x08 0x0008 18 02 01 06 02 0a 00 11 07 9e ca dc 24 0e e5 a9 e0 93 f3 a3 b5 01 00 40 6e 00 00 00 00 00 00 00", - "hcitool -i hci0 cmd 0x08 0x0009 0d 0c 09 4d 6f 6f 6e 62 6f 61 72 64 20 41", - "hcitool -i hci0 cmd 0x08 0x0006 80 02 c0 03 00 00 00 00 00 00 00 00 00 07 00" - ] - for c in setup_adv: - run("sudo "+ c, shell=True) - - -def start_adv(logger,start=True): - if start: - start='01' - logger.info('start adv') - else: - start='00' - logger.info('stop adv') - start_adv= "hcitool -i hci0 cmd 0x08 0x000a {}".format(start) - run("sudo " +start_adv, shell=True) - -def main(logger,adapter): - global mainloop - - logger.info("Bluetooth adapter: "+ str(adapter)) - - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - bus = dbus.SystemBus() - - try: - bus_name = dbus.service.BusName(SERVICE_NAME, - bus=bus, - do_not_queue=True) - except dbus.exceptions.NameExistsException: - sys.exit(1) - - app = MoonApplication(bus_name,None,logger) - - service_manager = dbus.Interface( - bus.get_object(BLUEZ_SERVICE_NAME, adapter), - GATT_MANAGER_IFACE) - - - loop = GLib.MainLoop() - - logger.info('app path: '+ app.get_path()) - - service_manager.RegisterApplication(app.get_path(), {}, - reply_handler=register_app_cb, - error_handler=register_app_error_cb) - - setup_adv(logger) - start_adv(logger) - - # Run the loop - try: - loop.run() - except KeyboardInterrupt: - print("keyboard interrupt received") - except Exception as e: - print("Unexpected exception occurred: '{}'".format(str(e))) - finally: - loop.quit() - - -if __name__ == '__main__': - - import argparse - parser = argparse.ArgumentParser(description='Moonboard bluetooth service') - parser.add_argument('--debug', action = "store_true") - - args = parser.parse_args() - argsd=vars(args) - - logger = logging.getLogger('moonboard.ble') - logger.setLevel(logging.DEBUG) - logger.addHandler(logging.StreamHandler()) - - if args.debug: - logger.setLevel(logging.DEBUG) - else: - logger.setLevel(logging.INFO) - - main(logger,adapter='/org/bluez/hci0') diff --git a/ble/moonboard_ble.service b/ble/moonboard_ble.service new file mode 100755 index 0000000..44f0aea --- /dev/null +++ b/ble/moonboard_ble.service @@ -0,0 +1,13 @@ +[Unit] +Description=Moonboard BLE Service +After=multi-user.target bluetooth.service hciuart.service + +[Service] +ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_service.py +Type=idle +User=root +StandardOutput=file:/var/log/moonboard_ble_stdout.log +StandardError=file:/var/log/moonboard_ble_stderr.log + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/ble/simple_client.py b/ble/simple_client.py deleted file mode 100755 index 185629e..0000000 --- a/ble/simple_client.py +++ /dev/null @@ -1,31 +0,0 @@ -# FIXME: delete, when port to MQTT done -from gi.repository import GLib -import dbus -from dbus.mainloop.glib import DBusGMainLoop - - -def handle_notification(s): - print('New Problem: '+s) - - -if __name__ == '__main__': - - dbml = DBusGMainLoop(set_as_default=True) - - bus = dbus.SystemBus() - proxy = bus.get_object('com.moonboard','/com/moonboard') - - proxy.connect_to_signal('new_problem', handle_notification) - loop = GLib.MainLoop() - - dbus.set_default_main_loop(dbml) - - # Run the loop - try: - loop.run() - except KeyboardInterrupt: - print("keyboard interrupt received") - except Exception as e: - print("Unexpected exception occurred: '{}'".format(str(e))) - finally: - loop.quit() \ No newline at end of file diff --git a/services/moonboard.service b/services/moonboard.service deleted file mode 100755 index db7084a..0000000 --- a/services/moonboard.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Moonboad App Service -After=com.moonboard.service dbus.service multi-user.target - -[Service] -User=root -Type=idle -ExecStart=/usr/bin/python3 /home/pi/moonboard/run.py --debug --driver PiWS281x -StandardOutput=file:/var/log/moonboard_stdout.log -StandardError=file:/var/log/moonboard_stderr.log - -[Install] -WantedBy=multi-user.target \ No newline at end of file From 5646a60c8403466dbb60ab3f8d12fb9965829ac7 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:22:16 +0100 Subject: [PATCH 198/240] user pi enough --- ble/moonboard_ble.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble/moonboard_ble.service b/ble/moonboard_ble.service index 44f0aea..bf56d97 100755 --- a/ble/moonboard_ble.service +++ b/ble/moonboard_ble.service @@ -5,7 +5,7 @@ After=multi-user.target bluetooth.service hciuart.service [Service] ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_service.py Type=idle -User=root +User=pi StandardOutput=file:/var/log/moonboard_ble_stdout.log StandardError=file:/var/log/moonboard_ble_stderr.log From 2b029b31634b0da4efbe1d5dbf54de03bc1c539e Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:23:31 +0100 Subject: [PATCH 199/240] correct dir --- ble/moonboard_ble.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble/moonboard_ble.service b/ble/moonboard_ble.service index bf56d97..4b58668 100755 --- a/ble/moonboard_ble.service +++ b/ble/moonboard_ble.service @@ -3,7 +3,7 @@ Description=Moonboard BLE Service After=multi-user.target bluetooth.service hciuart.service [Service] -ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_service.py +ExecStart=cd /home/pi/moonboard/ble/; /usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_service.py Type=idle User=pi StandardOutput=file:/var/log/moonboard_ble_stdout.log From 640c9e9c00ebc2e2b3fb6b2da1e5a24f79f27a81 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:27:12 +0100 Subject: [PATCH 200/240] workdir --- ble/moonboard_ble.service | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ble/moonboard_ble.service b/ble/moonboard_ble.service index 4b58668..59c485d 100755 --- a/ble/moonboard_ble.service +++ b/ble/moonboard_ble.service @@ -3,7 +3,8 @@ Description=Moonboard BLE Service After=multi-user.target bluetooth.service hciuart.service [Service] -ExecStart=cd /home/pi/moonboard/ble/; /usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_service.py +WorkingDirectory=/home/pi/moonboard/ble/ +ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_service.py Type=idle User=pi StandardOutput=file:/var/log/moonboard_ble_stdout.log From 8447d6b8009ed02de6ddc709d7d919273c072e1d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:28:36 +0100 Subject: [PATCH 201/240] rename fix --- ble/{moon_ble_service.py => moonboard_ble_service.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ble/{moon_ble_service.py => moonboard_ble_service.py} (100%) diff --git a/ble/moon_ble_service.py b/ble/moonboard_ble_service.py similarity index 100% rename from ble/moon_ble_service.py rename to ble/moonboard_ble_service.py From c990093f543d4eab26eca71174ef1f94f1c1fb8f Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:30:06 +0100 Subject: [PATCH 202/240] add service deps --- ble/moonboard_ble.service | 2 +- led/moonboard_led.service | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 led/moonboard_led.service diff --git a/ble/moonboard_ble.service b/ble/moonboard_ble.service index 59c485d..7ff762a 100755 --- a/ble/moonboard_ble.service +++ b/ble/moonboard_ble.service @@ -1,6 +1,6 @@ [Unit] Description=Moonboard BLE Service -After=multi-user.target bluetooth.service hciuart.service +After=multi-user.target bluetooth.service hciuart.service mosquitto.service [Service] WorkingDirectory=/home/pi/moonboard/ble/ diff --git a/led/moonboard_led.service b/led/moonboard_led.service new file mode 100644 index 0000000..81fa594 --- /dev/null +++ b/led/moonboard_led.service @@ -0,0 +1,14 @@ +[Unit] +Description=Moonboard LED Service +After=multi-user.target mosquitto.service + +[Service] +WorkingDirectory=/home/pi/moonboard/ble/ +ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_service.py +Type=idle +User=pi +StandardOutput=file:/var/log/moonboard_ble_stdout.log +StandardError=file:/var/log/moonboard_ble_stderr.log + +[Install] +WantedBy=multi-user.target \ No newline at end of file From e40c9359da4ddeaaf0c4a36862ba69ce49a13d12 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:31:07 +0100 Subject: [PATCH 203/240] doc --- ble/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ble/README.md b/ble/README.md index 3eed2dd..8039c48 100755 --- a/ble/README.md +++ b/ble/README.md @@ -107,4 +107,10 @@ See Bluetooth specification 5.0 (Core_v5.0.pdf), 7.8.5 LE Set Advertising Parame ## Bluez DBUS [Good introduction](http://smartspacestuff.blogspot.com/2016/02/i-got-figurin-out-dbus-bluez.html) -[API](https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc) \ No newline at end of file +[API](https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc) + + +# MQTT Interface +## Debugging ++ Status of service `systemctl status moonboard_ble.service` ++ Check for received events `mosquitto_sub -h raspi-moonboard -t "moonboard/ble/problem"` \ No newline at end of file From f084ebbfb4a4af49cbfa9c1802e201a3a01e216d Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:33:50 +0100 Subject: [PATCH 204/240] led service --- led/Makefile | 11 +++++++++++ led/moonboard_led.service | 10 +++++----- .../moonboard_led_service.py | 0 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 led/Makefile rename run_proto_mqtt_frontend.py => led/moonboard_led_service.py (100%) diff --git a/led/Makefile b/led/Makefile new file mode 100644 index 0000000..7209976 --- /dev/null +++ b/led/Makefile @@ -0,0 +1,11 @@ +#api-doc: +# docker run --rm -it -v $(PWD)/ble_api.yaml:/app/asyncapi.yml -v $(PWD)/api:/app/output asyncapi/generator -o /app/output /app/asyncapi.yml @asyncapi/html-template --force-write + +install: + service="moonboard_led.service" + echo "Install moonboard service for: moonboard_led.service" + sudo cp ./moonboard_led.service /lib/systemd/system/ + sudo chmod 644 /lib/systemd/system/moonboard_led.service + sudo systemctl daemon-reload + sudo systemctl enable moonboard_led.service + sudo systemctl restart moonboard_led.service diff --git a/led/moonboard_led.service b/led/moonboard_led.service index 81fa594..33ea6bd 100644 --- a/led/moonboard_led.service +++ b/led/moonboard_led.service @@ -3,12 +3,12 @@ Description=Moonboard LED Service After=multi-user.target mosquitto.service [Service] -WorkingDirectory=/home/pi/moonboard/ble/ -ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_service.py +WorkingDirectory=/home/pi/moonboard/led/ +ExecStart=/usr/bin/python3 /home/pi/moonboard/led/moonboard_led_service.py Type=idle -User=pi -StandardOutput=file:/var/log/moonboard_ble_stdout.log -StandardError=file:/var/log/moonboard_ble_stderr.log +User=root +StandardOutput=file:/var/log/moonboard_led_stdout.log +StandardError=file:/var/log/moonboard_led_stderr.log [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/run_proto_mqtt_frontend.py b/led/moonboard_led_service.py similarity index 100% rename from run_proto_mqtt_frontend.py rename to led/moonboard_led_service.py From 8c5fdf2cadf6c91dcb0195c4803336f6a4289015 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:34:55 +0100 Subject: [PATCH 205/240] dir fix --- led/moonboard_led_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led/moonboard_led_service.py b/led/moonboard_led_service.py index 38af3ec..eaec441 100644 --- a/led/moonboard_led_service.py +++ b/led/moonboard_led_service.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import argparse -from led.moonboard import MoonBoard +from moonboard import MoonBoard from functools import partial import json import RPi.GPIO as GPIO From 8404bb86b067d3c79a7c0121e96935956b76ca42 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:35:47 +0100 Subject: [PATCH 206/240] doc --- led/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 led/README.md diff --git a/led/README.md b/led/README.md new file mode 100644 index 0000000..25c5bde --- /dev/null +++ b/led/README.md @@ -0,0 +1,3 @@ +# MQTT Interface +## Debugging ++ Status of service `sudo systemctl status moonboard_led.service ` \ No newline at end of file From 46af3be10d4bcdaabf1333d9b1305237c6429ed5 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:39:19 +0100 Subject: [PATCH 207/240] cleanup dirs --- .../run_testing_interface_hangboard.py | 2 +- run.py | 108 ------------------ scripts/fix_startup.sh | 9 +- scripts/reset.sh | 8 -- scripts/run.sh | 8 -- 5 files changed, 4 insertions(+), 131 deletions(-) rename run_testing_interface_hangboard.py => led/run_testing_interface_hangboard.py (99%) delete mode 100755 run.py delete mode 100755 scripts/reset.sh delete mode 100755 scripts/run.sh diff --git a/run_testing_interface_hangboard.py b/led/run_testing_interface_hangboard.py similarity index 99% rename from run_testing_interface_hangboard.py rename to led/run_testing_interface_hangboard.py index ad69d00..0697951 100644 --- a/run_testing_interface_hangboard.py +++ b/led/run_testing_interface_hangboard.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import argparse -from led.moonboard import MoonBoard +from moonboard import MoonBoard from functools import partial import json import RPi.GPIO as GPIO diff --git a/run.py b/run.py deleted file mode 100755 index 020d154..0000000 --- a/run.py +++ /dev/null @@ -1,108 +0,0 @@ -# -*- coding: utf-8 -*- -import argparse -from led.moonboard import MoonBoard -from gi.repository import GLib -import dbus -from dbus.mainloop.glib import DBusGMainLoop -from functools import partial -import json -import json -import RPi.GPIO as GPIO -import os -#import signal -import sys -import logging - - - -# external power LED and power button -LED_GPIO = 26 -BUTTON_GPIO = 3 - - -# Button function -def button_pressed_callback(channel): - print("Button pressed") - MOONBOARD.clear() - #print('Shutting down') - #os.system("sudo shutdown -h now") - - -def new_problem_cb(mb,holds_string): - holds = json.loads(holds_string) - mb.show_problem(holds) - logger.debug('new_problem: '+holds_string) - -if __name__ == "__main__": - - # Comment out button stuff - yet... - # # BUTTON + LED setup - # GPIO.setmode(GPIO.BCM) - # GPIO.setwarnings(False) - # GPIO.setup(LED_GPIO, GPIO.OUT) - # GPIO.output(LED_GPIO,1) - # GPIO.setup(BUTTON_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP) - # # interupt handling for the power button - # GPIO.add_event_detect(BUTTON_GPIO, GPIO.RISING, - # callback=button_pressed_callback, bouncetime=300) - - # #signal.signal(signal.SIGINT, signal_handler) - # #signal.pause() - - parser = argparse.ArgumentParser(description='') - - parser.add_argument('--driver_type', - help='driver type, depends on leds and device controlling the led.', - choices=['PiWS281x', 'WS2801', 'SimPixel'], - default='PiWS281x') - - parser.add_argument('--brightness', default=100, type=int) - - parser.add_argument('--led_mapping', - type=str, - default='led_mapping.json', - ) - - parser.add_argument('--debug', action = "store_true") - - - args = parser.parse_args() - argsd=vars(args) - logger = logging.getLogger('run') - logger.setLevel(logging.DEBUG) - logger.addHandler(logging.StreamHandler()) - - if args.debug: - logger.setLevel(logging.DEBUG) - else: - logger.setLevel(logging.INFO) - - MOONBOARD = MoonBoard( - args.driver_type, - args.led_mapping) - - print(f"Led mapping:{args.led_mapping}") - print(f"Driver type:{args.driver_type}") - - MOONBOARD.clear() - - # connect to dbus signal new problem - dbml = DBusGMainLoop(set_as_default=True) - - bus = dbus.SystemBus() - proxy = bus.get_object('com.moonboard','/com/moonboard') - - proxy.connect_to_signal('new_problem', partial(new_problem_cb, MOONBOARD)) - loop = GLib.MainLoop() - - dbus.set_default_main_loop(dbml) - - # Run the loop - try: - loop.run() - except KeyboardInterrupt: - print("keyboard interrupt received") - except Exception as e: - print("Unexpected exception occurred: '{}'".format(str(e))) - finally: - loop.quit() diff --git a/scripts/fix_startup.sh b/scripts/fix_startup.sh index 4c0150d..412aa59 100755 --- a/scripts/fix_startup.sh +++ b/scripts/fix_startup.sh @@ -1,7 +1,4 @@ #!/bin/bash -sudo systemctl stop moonboard -sudo systemctl stop com.moonboard - -# startup in correct order -sudo systemctl restart com.moonboard -sudo systemctl restart moonboard +for s in moonboard_led.service moonboard_ble.service; +sudo systemctl restart $service +done diff --git a/scripts/reset.sh b/scripts/reset.sh deleted file mode 100755 index 20158c0..0000000 --- a/scripts/reset.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -sudo systemctl restart dbus - -sudo systemctl restart com.moonboard - -sudo systemctl restart moonboard - diff --git a/scripts/run.sh b/scripts/run.sh deleted file mode 100755 index c22aee1..0000000 --- a/scripts/run.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -o errexit -LOG_FILE=/var/log/moonboard - -exec 1>$LOG_FILE -exec 2>&1 - -sudo /usr/bin/python3 /home/pi/moonboard/run.py --debug $1 \ No newline at end of file From afe61dbff1808c2caacb42f6a35776dc796730ef Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:41:23 +0100 Subject: [PATCH 208/240] cleanup --- TODO.md | 4 ---- install/install.sh | 20 -------------------- 2 files changed, 24 deletions(-) diff --git a/TODO.md b/TODO.md index 8b8cd22..b4ad90f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,3 @@ - -# Redesign TBD: -- Use MQTT instead of DBUS - # Minor stuff - uninstaller for services diff --git a/install/install.sh b/install/install.sh index 269e45e..f81ec65 100755 --- a/install/install.sh +++ b/install/install.sh @@ -28,26 +28,6 @@ sudo pip3 install -r install/requirements.txt echo "Install service" # FIXME -cd /home/pi/moonboard/services -sudo ./install_service.sh moonboard.service -cd /home/pi/moonboard - - -echo "Install DBUS service" # FIXME - script install_service can be used or removed -sudo cp /home/pi/moonboard/ble/com.moonboard.conf /etc/dbus-1/system.d -sudo cp /home/pi/moonboard/ble/com.moonboard.service /usr/share/dbus-1/system-services/ -cd /home/pi/moonboard/ble -sudo /home/pi/moonboard/services/install_service.sh com.moonboard.service > /tmp/moonboard-service-install.log - - -sudo systemctl enable com.moonboard -sudo systemctl enable moonboard.service - -# FIXME Update scripts with logfile information -echo "Prepare logfiles" -sudo touch /var/log/moonboard -sudo chown pi:pi /var/log/moonboard -sudo chown pi:pi /var/log/moonboard #printf " Restarting" # FIXME From d5652c362d8aea0bc1a44104be6dab6e3a702a13 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:41:52 +0100 Subject: [PATCH 209/240] installer --- {testing => doc}/TESTING.md | 0 install/install.sh | 8 +- testing/BLE-TESTING_OUTPUTS.md | 197 --------------------------------- 3 files changed, 7 insertions(+), 198 deletions(-) rename {testing => doc}/TESTING.md (100%) delete mode 100644 testing/BLE-TESTING_OUTPUTS.md diff --git a/testing/TESTING.md b/doc/TESTING.md similarity index 100% rename from testing/TESTING.md rename to doc/TESTING.md diff --git a/install/install.sh b/install/install.sh index f81ec65..d7cca06 100755 --- a/install/install.sh +++ b/install/install.sh @@ -27,7 +27,13 @@ sudo pip3 install -r install/requirements.txt # pip3 uninstall -y -r install/requirements.txt # uninstall -echo "Install service" # FIXME +echo "Install services" # FIXME +cd ble +make install +cd .. +cd led +make install +cd .. #printf " Restarting" # FIXME diff --git a/testing/BLE-TESTING_OUTPUTS.md b/testing/BLE-TESTING_OUTPUTS.md deleted file mode 100644 index 3f625f6..0000000 --- a/testing/BLE-TESTING_OUTPUTS.md +++ /dev/null @@ -1,197 +0,0 @@ -# Bluetooth monitoring - -```ssh -lpi raspi-moonboard sudo btmon``` - -## Example -sudo btmon -Bluetooth monitor ver 5.50 -= Note: Linux version 5.10.63+ (armv6l) 0.749830 -= Note: Bluetooth subsystem version 2.22 0.749846 -= New Index: B8:27:EB:78:4B:E9 (Primary,UART,hci0) [hci0] 0.749853 -= Open Index: B8:27:EB:78:4B:E9 [hci0] 0.749858 -= Index Info: B8:27:EB:78:4B:E9 (Broadcom Corporation) [hci0] 0.749862 -@ MGMT Open: btmon (privileged) version 1.18 {0x0002} 0.749868 -@ MGMT Open: bluetoothd (privileged) version 1.18 {0x0001} 0.749873 -@ MGMT Open: btmon (privileged) version 1.18 {0x0003} 0.750001 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #1 [hci0] 3.977273 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c23533138332c533133392c5039392c5038372c -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #2 [hci0] 3.988939 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #3 [hci0] 4.037460 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 5038342c5037382c50332c5032352c503136342c -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #4 [hci0] 4.048985 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 12 #5 [hci0] 4.097163 - ATT: Write Request (0x12) len 7 - Handle: 0x000c - Data: 4531363223 -> HCI Event: Number of Completed Packets (0x13) plen 5 #6 [hci0] 4.097906 - Num handles: 1 - Handle: 64 - Count: 2 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #7 [hci0] 4.107769 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #8 [hci0] 4.351125 - Num handles: 1 - Handle: 64 - Count: 1 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #9 [hci0] 5.777284 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c235333322c5036312c5035372c503130302c45 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #10 [hci0] 5.784852 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 10 #11 [hci0] 5.837187 - ATT: Write Request (0x12) len 5 - Handle: 0x000c - Data: 353423 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #12 [hci0] 5.847927 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #13 [hci0] 5.897103 - Num handles: 1 - Handle: 64 - Count: 2 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #14 [hci0] 6.917365 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c235333342c5037392c5036302c5033302c5031 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #15 [hci0] 6.928987 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 25 #16 [hci0] 6.977342 - ATT: Write Request (0x12) len 20 - Handle: 0x000c - Data: 38372c503135362c503132372c4531393723 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #17 [hci0] 6.988511 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #18 [hci0] 7.037108 - Num handles: 1 - Handle: 64 - Count: 2 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #19 [hci0] 8.327395 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c2353332c533130392c5036342c5036312c5031 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #20 [hci0] 8.338614 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 19 #21 [hci0] 8.387308 - ATT: Write Request (0x12) len 14 - Handle: 0x000c - Data: 37302c503136362c45393023 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #22 [hci0] 8.396136 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #23 [hci0] 8.447137 - Num handles: 1 - Handle: 64 - Count: 2 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #24 [hci0] 9.227406 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c2353342c5333392c5039382c5032382c503137 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #25 [hci0] 9.239194 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #26 [hci0] 9.287598 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 362c503136392c503136342c503133302c503131 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #27 [hci0] 9.297212 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #28 [hci0] 9.347156 - Num handles: 1 - Handle: 64 - Count: 2 -> ACL Data RX: Handle 64 flags 0x02 dlen 13 #29 [hci0] 9.407244 - ATT: Write Request (0x12) len 8 - Handle: 0x000c - Data: 352c45393023 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #30 [hci0] 9.418438 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #31 [hci0] 9.601239 - Num handles: 1 - Handle: 64 - Count: 1 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #32 [hci0] 10.937405 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c23533138322c533137362c503139352c503138 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #33 [hci0] 10.945771 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #34 [hci0] 10.997617 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 372c503135352c503133352c503133302c453132 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #35 [hci0] 11.005984 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #36 [hci0] 11.087199 - Num handles: 1 - Handle: 64 - Count: 2 -> ACL Data RX: Handle 64 flags 0x02 dlen 9 #37 [hci0] 11.117202 - ATT: Write Request (0x12) len 4 - Handle: 0x000c - Data: 3623 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #38 [hci0] 11.124590 - ATT: Write Response (0x13) len 0 -> HCI Event: Number of Completed Packets (0x13) plen 5 #39 [hci0] 11.351131 - Num handles: 1 - Handle: 64 - Count: 1 -> HCI Event: LE Meta Event (0x3e) plen 10 #40 [hci0] 12.002693 - LE Connection Update Complete (0x03) - Status: Success (0x00) - Handle: 64 - Connection interval: 30.00 msec (0x0018) - Connection latency: 0 (0x0000) - Supervision timeout: 720 msec (0x0048) -> ACL Data RX: Handle 64 flags 0x02 dlen 27 #41 [hci0] 13.892482 - ATT: Write Request (0x12) len 22 - Handle: 0x000c - Data: 6c235333392c533131332c5039312c5036342c50 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #42 [hci0] 13.905726 - ATT: Write Response (0x13) len 0 -> ACL Data RX: Handle 64 flags 0x02 dlen 19 #43 [hci0] 13.982417 - ATT: Write Request (0x12) len 14 - Handle: 0x000c - Data: 35382c503133322c45313823 -< ACL Data TX: Handle 64 flags 0x00 dlen 5 #44 [hci0] 13.993446 - ATT: Write Response (0x13) len 0 - - -# DBUS Monitoring -```ssh -lpi raspi-moonboard sudo dbus-monitor --system|less``` - -## Example - -signal time=1638195833.267233 sender=org.freedesktop.DBus -> destination=:1.105 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired - string ":1.105" -signal time=1638195833.270379 sender=org.freedesktop.DBus -> destination=:1.105 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost - string ":1.105" -method call time=1638195834.405055 sender=:1.13 -> destination=:1.34 serial=191 path=/com/moonboard/service0/char1; interface=org.bluez.GattCharacteristic1; member=WriteValue - array of bytes "l#S3,S105,P60,P28,P1" - array [ - dict entry( - string "device" - variant object path "/org/bluez/hci0/dev_F0_A3_5A_A4_70_7F" - ) - dict entry( - string "link" - variant string "LE" - ) - ] -method return time=1638195834.417610 sender=:1.34 -> destination=:1.13 serial=108 reply_serial=191 -method call time=1638195834.463586 sender=:1.13 -> destination=:1.34 serial=192 path=/com/moonboard/service0/char1; interface=org.bluez.GattCharacteristic1; member=WriteValue - array of bytes "4,E90#" - array [ - dict entry( - string "device" - variant object path "/org/bluez/hci0/dev_F0_A3_5A_A4_70_7F" - ) - dict entry( - string "link" - variant string "LE" - ) - ] -method return time=1638195834.471207 sender=:1.34 -> destination=:1.13 serial=109 reply_serial=192 \ No newline at end of file From 6f068daffcf209509b800188766e50d7e072dc03 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:42:55 +0100 Subject: [PATCH 210/240] cleanup --- install/10-prepare-raspi.sh | 3 ++- install/install.sh | 20 ++++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/install/10-prepare-raspi.sh b/install/10-prepare-raspi.sh index a307389..0c6e32b 100755 --- a/install/10-prepare-raspi.sh +++ b/install/10-prepare-raspi.sh @@ -16,4 +16,5 @@ sudo apt-get upgrade echo "Install + build led drivers" sudo apt-get -y install git vim python3-pip python3-rpi.gpio gcc make build-essential sudo apt-get -y install libatlas-base-dev -sudo apt-get -y install python-dev swig scons # for building WS2811 drivers \ No newline at end of file +sudo apt-get -y install python-dev swig scons # for building WS2811 drivers + diff --git a/install/install.sh b/install/install.sh index d7cca06..5e7a061 100755 --- a/install/install.sh +++ b/install/install.sh @@ -5,20 +5,12 @@ #./10-prepare-raspi.sh # FIXME #./20-prepare-python.sh # FIXME -# Install dependencies -echo "Install dependencies" -sudo apt-get update -sudo apt-get upgrade - -echo "Install + build led drivers" -sudo apt-get -y install git vim python3-pip python3-rpi.gpio gcc make build-essential -sudo apt-get -y install libatlas-base-dev -sudo apt-get -y install python-dev swig scons # for building WS2811 drivers - -echo "Install application" -test -d moonboard || git clone https://github.com/8cH9azbsFifZ/moonboard.git -cd moonboard -git pull + + +#echo "Install application" +#test -d moonboard || git clone https://github.com/8cH9azbsFifZ/moonboard.git +#cd moonboard +#git pull # Installing python dependencies echo "Installing python dependencies" From a0de1acbcd2ebb2cdb8a3f87aebc941062059081 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:44:12 +0100 Subject: [PATCH 211/240] services --- install/install.sh | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/install/install.sh b/install/install.sh index 5e7a061..e3546ab 100755 --- a/install/install.sh +++ b/install/install.sh @@ -4,6 +4,7 @@ #./10-prepare-raspi.sh # FIXME #./20-prepare-python.sh # FIXME +#./30-install-services.sh # FIXME @@ -12,20 +13,6 @@ #cd moonboard #git pull -# Installing python dependencies -echo "Installing python dependencies" -pip3 install -r install/requirements.txt -sudo pip3 install -r install/requirements.txt -# pip3 uninstall -y -r install/requirements.txt # uninstall - - -echo "Install services" # FIXME -cd ble -make install -cd .. -cd led -make install -cd .. #printf " Restarting" # FIXME From 5a069237a5927c77e24178f4a2356b754d530f28 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:44:37 +0100 Subject: [PATCH 212/240] services --- install/30-install-services.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 install/30-install-services.sh diff --git a/install/30-install-services.sh b/install/30-install-services.sh new file mode 100755 index 0000000..7756f96 --- /dev/null +++ b/install/30-install-services.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +echo "Install services" # FIXME +cd ble +make install +cd .. + +cd led +make install +cd .. From fde84574d6f20507061b0f056f06053898430be8 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:45:17 +0100 Subject: [PATCH 213/240] fix dir --- install/30-install-services.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/30-install-services.sh b/install/30-install-services.sh index 7756f96..fdc07f2 100755 --- a/install/30-install-services.sh +++ b/install/30-install-services.sh @@ -1,10 +1,10 @@ #!/bin/bash echo "Install services" # FIXME -cd ble +cd /home/pi/moonboard/ble make install cd .. -cd led +cd /home/pi/moonboard/led make install cd .. From 35cda83fd9bd3b8ba14036a8dbbddb0b81fe36a0 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:48:00 +0100 Subject: [PATCH 214/240] mqtt version --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8453a3..f8b31f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- v0.32 Removed DBUS backend, new MQTT backend and corresponding services - v0.31 Animations and prototyped mqtt linkage to hangboard - v0.30 simplified installation procedure, fix service logging and installtion collisions - v0.28 merged moonboard mini protocol From 1eb59268305c1c368e96e068483a16f2ab02ddd8 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 21:57:09 +0100 Subject: [PATCH 215/240] priv mode --- ble/moonboard_ble.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble/moonboard_ble.service b/ble/moonboard_ble.service index 7ff762a..c190f9e 100755 --- a/ble/moonboard_ble.service +++ b/ble/moonboard_ble.service @@ -6,7 +6,7 @@ After=multi-user.target bluetooth.service hciuart.service mosquitto.service WorkingDirectory=/home/pi/moonboard/ble/ ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_service.py Type=idle -User=pi +User=root StandardOutput=file:/var/log/moonboard_ble_stdout.log StandardError=file:/var/log/moonboard_ble_stderr.log From d1f26aabebbdfb4665e58c0d25a07d3c07007661 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 22:00:56 +0100 Subject: [PATCH 216/240] wip --- ble/moonboard_ble_service.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ble/moonboard_ble_service.py b/ble/moonboard_ble_service.py index 14634fa..5e8fc42 100755 --- a/ble/moonboard_ble_service.py +++ b/ble/moonboard_ble_service.py @@ -16,6 +16,7 @@ # FIXME: cleanup code & simplify(!) BLUEZ_SERVICE_NAME = 'org.bluez' +DBUS_OM_IFACE = 'org.freedesktop.DBus.ObjectManager' LE_ADVERTISING_MANAGER_IFACE = 'org.bluez.LEAdvertisingManager1' GATT_MANAGER_IFACE = 'org.bluez.GattManager1' GATT_CHRC_IFACE = 'org.bluez.GattCharacteristic1' @@ -23,9 +24,25 @@ UART_RX_CHARACTERISTIC_UUID = '6e400002-b5a3-f393-e0a9-e50e24dcca9e' UART_TX_CHARACTERISTIC_UUID = '6e400003-b5a3-f393-e0a9-e50e24dcca9e' LOCAL_NAME = 'Moonboard A' +SERVICE_NAME= 'com.moonboard' # FIXME: on connection lost: error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 2: invalid start byte +class RxCharacteristic(Characteristic): + def __init__(self, bus, index, service, process_rx): + Characteristic.__init__(self, bus, index, UART_RX_CHARACTERISTIC_UUID, + ['write'], service) + self.process_rx=process_rx + + def WriteValue(self, value, options): + pass + #self.process_rx(value) + +class UartService(Service): + def __init__(self, bus,path, index, process_rx): + Service.__init__(self, bus,path, index, UART_SERVICE_UUID, True) + self.add_characteristic(RxCharacteristic(bus, 1, self, process_rx)) + class OutStream: # FIXME: simplify def __init__(self, fileno): From 2c4abad676a565118ebceb3e922176ff458d645c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 22:09:51 +0100 Subject: [PATCH 217/240] dbus reinsert --- ble/com.moonboard.conf | 18 +++ ble/com.moonboard.service | 17 ++ ble/moonboard_ble_dbus_service.py | 251 ++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+) create mode 100644 ble/com.moonboard.conf create mode 100644 ble/com.moonboard.service create mode 100644 ble/moonboard_ble_dbus_service.py diff --git a/ble/com.moonboard.conf b/ble/com.moonboard.conf new file mode 100644 index 0000000..a503c6c --- /dev/null +++ b/ble/com.moonboard.conf @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ble/com.moonboard.service b/ble/com.moonboard.service new file mode 100644 index 0000000..00e79a0 --- /dev/null +++ b/ble/com.moonboard.service @@ -0,0 +1,17 @@ +[Unit] +Description=Moonboard BLE DBUS Service +After=multi-user.target bluetooth.service dbus.service hciuart.service +SystemdService=dbus-org.com.moonbooard.service +# FIXME: SystemdService not known + +[Service] +Type=dbus +BusName=com.moonboard +ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_dbus_service.py +User=root +StandardOutput=file:/var/log/moonboard_ble_stdout.log +StandardError=file:/var/log/moonboard_ble_stderr.log + +[Install] +WantedBy=multi-user.target + diff --git a/ble/moonboard_ble_dbus_service.py b/ble/moonboard_ble_dbus_service.py new file mode 100644 index 0000000..d4ffc42 --- /dev/null +++ b/ble/moonboard_ble_dbus_service.py @@ -0,0 +1,251 @@ +import sys +import dbus, dbus.mainloop.glib +from gi.repository import GLib +from gatt_base.gatt_lib_advertisement import Advertisement +from gatt_base.gatt_lib_characteristic import Characteristic +from gatt_base.gatt_lib_service import Service +import string,json +import subprocess +import logging +from moonboard_app_protocol import UnstuffSequence, decode_problem_string + +import os +import threading +import pty + +BLUEZ_SERVICE_NAME = 'org.bluez' +DBUS_OM_IFACE = 'org.freedesktop.DBus.ObjectManager' +LE_ADVERTISING_MANAGER_IFACE = 'org.bluez.LEAdvertisingManager1' +GATT_MANAGER_IFACE = 'org.bluez.GattManager1' +GATT_CHRC_IFACE = 'org.bluez.GattCharacteristic1' +UART_SERVICE_UUID = '6e400001-b5a3-f393-e0a9-e50e24dcca9e' +UART_RX_CHARACTERISTIC_UUID = '6e400002-b5a3-f393-e0a9-e50e24dcca9e' +UART_TX_CHARACTERISTIC_UUID = '6e400003-b5a3-f393-e0a9-e50e24dcca9e' +LOCAL_NAME = 'Moonboard A' +SERVICE_NAME= 'com.moonboard' +mainloop = None + +class RxCharacteristic(Characteristic): + def __init__(self, bus, index, service, process_rx): + Characteristic.__init__(self, bus, index, UART_RX_CHARACTERISTIC_UUID, + ['write'], service) + self.process_rx=process_rx + + def WriteValue(self, value, options): + pass + #self.process_rx(value) + +class UartService(Service): + def __init__(self, bus,path, index, process_rx): + Service.__init__(self, bus,path, index, UART_SERVICE_UUID, True) + self.add_characteristic(RxCharacteristic(bus, 1, self, process_rx)) + +class OutStream: + def __init__(self, fileno): + self._fileno = fileno + self._buffer = b"" + + def read_lines(self): + try: + output = os.read(self._fileno, 1000) + except OSError as e: + if e.errno != errno.EIO: raise + output = b"" + lines = output.split(b"\n") + lines[0] = self._buffer + lines[0] # prepend previous + # non-finished line. + if output: + self._buffer = lines[-1] + finished_lines = lines[:-1] + readable = True + else: + self._buffer = b"" + if len(lines) == 1 and not lines[0]: + # We did not have buffer left, so no output at all. + lines = [] + finished_lines = lines + readable = False + + finished_lines = [line.rstrip(b"\r") + for line in finished_lines] + + return finished_lines, readable + + +class MoonApplication(dbus.service.Object): + IFACE = "com.moonboard.method" + def __init__(self, bus, socket,logger): + self.path = '/com/moonboard' + self.services = [] + self.logger=logger + self.unstuffer= UnstuffSequence(self.logger) + dbus.service.Object.__init__(self, bus, self.path) + self.add_service(UartService(bus,self.get_path(), 0, self.process_rx)) + + monitor_thread = threading.Thread(target=self.monitor_btmon) + monitor_thread.start() + + def monitor_btmon(self): + out_r, out_w = pty.openpty() + cmd = ["sudo","btmon"] + process = subprocess.Popen(cmd, stdout=out_w) + f = OutStream(out_r) + while True: + lines, readable = f.read_lines() + if not readable: break + for line in lines: + if line != '': + line = line.decode() + if 'Data:' in line: + data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') + self.process_rx(data) + self.logger.info('New data '+ data) + + def process_rx(self,ba): + new_problem_string= self.unstuffer.process_bytes(ba) + flags = self.unstuffer.flags + + if new_problem_string is not None: + problem= decode_problem_string(new_problem_string, flags) + self.new_problem(json.dumps(problem)) + self.unstuffer.flags = '' + start_adv(self.logger) + + @dbus.service.signal(dbus_interface="com.moonboard", + signature="s") + def new_problem(self, problem): + self.logger.info('Signal new problem: '+ str(problem)) + + def get_path(self): + return dbus.ObjectPath(self.path) + + def add_service(self, service): + self.services.append(service) + + @dbus.service.method(DBUS_OM_IFACE, out_signature='a{oa{sa{sv}}}') + def GetManagedObjects(self): + response = {} + for service in self.services: + response[service.get_path()] = service.get_properties() + chrcs = service.get_characteristics() + for chrc in chrcs: + response[chrc.get_path()] = chrc.get_properties() + return response + +def register_app_cb(): + print('GATT application registered') + + +def register_app_error_cb(error): + print('Failed to register application: ' + str(error)) + mainloop.quit() + + +def run(*popenargs, **kwargs): + input = kwargs.pop("input", None) + check = kwargs.pop("handle", False) + + if input is not None: + if 'stdin' in kwargs: + raise ValueError('stdin and input arguments may not both be used.') + kwargs['stdin'] = subprocess.PIPE + + process = subprocess.Popen(*popenargs, **kwargs) + try: + stdout, stderr = process.communicate(input) + except: + process.kill() + process.wait() + raise + retcode = process.poll() + if check and retcode: + raise subprocess.CalledProcessError( + retcode, process.args, output=stdout, stderr=stderr) + return retcode, stdout, stderr + + +def setup_adv(logger): + logger.info('setup adv') + setup_adv = [ + "hcitool -i hci0 cmd 0x08 0x000a 00", + "hcitool -i hci0 cmd 0x08 0x0008 18 02 01 06 02 0a 00 11 07 9e ca dc 24 0e e5 a9 e0 93 f3 a3 b5 01 00 40 6e 00 00 00 00 00 00 00", + "hcitool -i hci0 cmd 0x08 0x0009 0d 0c 09 4d 6f 6f 6e 62 6f 61 72 64 20 41", + "hcitool -i hci0 cmd 0x08 0x0006 80 02 c0 03 00 00 00 00 00 00 00 00 00 07 00" + ] + for c in setup_adv: + run("sudo "+ c, shell=True) + + +def start_adv(logger,start=True): + if start: + start='01' + logger.info('start adv') + else: + start='00' + logger.info('stop adv') + start_adv= "hcitool -i hci0 cmd 0x08 0x000a {}".format(start) + run("sudo " +start_adv, shell=True) + +def main(logger,adapter): + global mainloop + + logger.info("Bluetooth adapter: "+ str(adapter)) + + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + bus = dbus.SystemBus() + + try: + bus_name = dbus.service.BusName(SERVICE_NAME, + bus=bus, + do_not_queue=True) + except dbus.exceptions.NameExistsException: + sys.exit(1) + + app = MoonApplication(bus_name,None,logger) + + service_manager = dbus.Interface( + bus.get_object(BLUEZ_SERVICE_NAME, adapter), + GATT_MANAGER_IFACE) + + + loop = GLib.MainLoop() + + logger.info('app path: '+ app.get_path()) + + service_manager.RegisterApplication(app.get_path(), {}, + reply_handler=register_app_cb, + error_handler=register_app_error_cb) + + setup_adv(logger) + start_adv(logger) + + # Run the loop + try: + loop.run() + except KeyboardInterrupt: + print("keyboard interrupt received") + except Exception as e: + print("Unexpected exception occurred: '{}'".format(str(e))) + finally: + loop.quit() + + +if __name__ == '__main__': + + import argparse + parser = argparse.ArgumentParser(description='Moonboard bluetooth service') + parser.add_argument('--debug', action = "store_true") + + args = parser.parse_args() + argsd=vars(args) + + logger = logging.getLogger('moonboard.ble') + logger.setLevel(logging.DEBUG) + logger.addHandler(logging.StreamHandler()) + + if args.debug: + logger.setLevel(logging.DEBUG) + else: + logger.setLevel(logging.INFO) + + main(logger,adapter='/org/bluez/hci0') From 8a57da2ce3fcc94156940cde478ea297565f360c Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 22:11:20 +0100 Subject: [PATCH 218/240] install dbus --- ble/Makefile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ble/Makefile b/ble/Makefile index 1cc335c..7df539d 100644 --- a/ble/Makefile +++ b/ble/Makefile @@ -9,3 +9,13 @@ install: sudo systemctl daemon-reload sudo systemctl enable moonboard_ble.service sudo systemctl restart moonboard_ble.service + +install-dbus: + service="moonboard_ble_dbus.service" + echo "Install moonboard service for: moonboard_ble_dbus.service" + sudo cp ./moonboard_ble_dbus.service /lib/systemd/system/ + sudo chmod 644 /lib/systemd/system/moonboard_ble_dbus.service + sudo cp com.moonboard.conf /etc/dbus-1/system.d/com.moonboard.conf + sudo systemctl daemon-reload + sudo systemctl enable moonboard_ble_dbus.service + sudo systemctl restart moonboard_ble_dbus.service \ No newline at end of file From 69fc6bacbdb530d43032b081499824b1cef56334 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 22:12:36 +0100 Subject: [PATCH 219/240] fix name --- ble/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ble/Makefile b/ble/Makefile index 7df539d..92c6655 100644 --- a/ble/Makefile +++ b/ble/Makefile @@ -11,11 +11,11 @@ install: sudo systemctl restart moonboard_ble.service install-dbus: - service="moonboard_ble_dbus.service" - echo "Install moonboard service for: moonboard_ble_dbus.service" - sudo cp ./moonboard_ble_dbus.service /lib/systemd/system/ - sudo chmod 644 /lib/systemd/system/moonboard_ble_dbus.service + service="com.moonboard.service" + echo "Install moonboard service for: com.moonboard.service" + sudo cp ./com.moonboard.service /lib/systemd/system/ + sudo chmod 644 /lib/systemd/system/com.moonboard.service sudo cp com.moonboard.conf /etc/dbus-1/system.d/com.moonboard.conf sudo systemctl daemon-reload - sudo systemctl enable moonboard_ble_dbus.service - sudo systemctl restart moonboard_ble_dbus.service \ No newline at end of file + sudo systemctl enable com.moonboard.service + sudo systemctl restart com.moonboard.service \ No newline at end of file From a564486162894c4b0b2b142f9f3762a8c89b4ba3 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 22:18:30 +0100 Subject: [PATCH 220/240] doc --- CHANGELOG.md | 2 +- ble/Makefile | 3 ++- ble/README.md | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8b31f5..efc1591 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -- v0.32 Removed DBUS backend, new MQTT backend and corresponding services +- v0.32 Removed DBUS backend for LED, new MQTT backend and corresponding services - v0.31 Animations and prototyped mqtt linkage to hangboard - v0.30 simplified installation procedure, fix service logging and installtion collisions - v0.28 merged moonboard mini protocol diff --git a/ble/Makefile b/ble/Makefile index 92c6655..b651bae 100644 --- a/ble/Makefile +++ b/ble/Makefile @@ -18,4 +18,5 @@ install-dbus: sudo cp com.moonboard.conf /etc/dbus-1/system.d/com.moonboard.conf sudo systemctl daemon-reload sudo systemctl enable com.moonboard.service - sudo systemctl restart com.moonboard.service \ No newline at end of file + sudo systemctl restart com.moonboard.service + sudo systemctl restart dbus diff --git a/ble/README.md b/ble/README.md index 8039c48..e9869af 100755 --- a/ble/README.md +++ b/ble/README.md @@ -113,4 +113,5 @@ See Bluetooth specification 5.0 (Core_v5.0.pdf), 7.8.5 LE Set Advertising Parame # MQTT Interface ## Debugging + Status of service `systemctl status moonboard_ble.service` -+ Check for received events `mosquitto_sub -h raspi-moonboard -t "moonboard/ble/problem"` \ No newline at end of file ++ Check for received events `mosquitto_sub -h raspi-moonboard -t "moonboard/ble/problem"` ++ Status of DBUS backend: `sudo systemctl status com.moonboard.service` \ No newline at end of file From 5141e89bed11df558d8006ebd2441d5559caa74a Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Sun, 2 Jan 2022 22:20:36 +0100 Subject: [PATCH 221/240] autorestart --- ble/moonboard_ble.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ble/moonboard_ble.service b/ble/moonboard_ble.service index c190f9e..31d2933 100755 --- a/ble/moonboard_ble.service +++ b/ble/moonboard_ble.service @@ -7,6 +7,8 @@ WorkingDirectory=/home/pi/moonboard/ble/ ExecStart=/usr/bin/python3 /home/pi/moonboard/ble/moonboard_ble_service.py Type=idle User=root +Restart=on-failure +RestartSec=5s StandardOutput=file:/var/log/moonboard_ble_stdout.log StandardError=file:/var/log/moonboard_ble_stderr.log From 816fbe7efd7681a397d7b6aedfaf7d102cf2ef96 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 12 Mar 2022 00:58:34 +0000 Subject: [PATCH 222/240] Bump pillow from 8.3.2 to 9.0.1 in /install Bumps [pillow](https://github.com/python-pillow/Pillow) from 8.3.2 to 9.0.1. - [Release notes](https://github.com/python-pillow/Pillow/releases) - [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst) - [Commits](https://github.com/python-pillow/Pillow/compare/8.3.2...9.0.1) --- updated-dependencies: - dependency-name: pillow dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index 2773a46..4410712 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -21,7 +21,7 @@ MarkupSafe==1.1.1 mccabe==0.6.1 numpy==1.16.3 olefile==0.46 -Pillow==8.3.2 +Pillow==9.0.1 pylint==2.3.1 pyserial==3.4 python-dateutil==2.8.0 From f917a64c8d293d4b322fb572df600b87003ae496 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 8 May 2022 10:35:51 +0000 Subject: [PATCH 223/240] Bump numpy from 1.16.3 to 1.21.0 in /install Bumps [numpy](https://github.com/numpy/numpy) from 1.16.3 to 1.21.0. - [Release notes](https://github.com/numpy/numpy/releases) - [Changelog](https://github.com/numpy/numpy/blob/main/doc/HOWTO_RELEASE.rst.txt) - [Commits](https://github.com/numpy/numpy/compare/v1.16.3...v1.21.0) --- updated-dependencies: - dependency-name: numpy dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index 4410712..9e1756c 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -19,7 +19,7 @@ lazy-object-proxy==1.3.1 loady==1.8.10 MarkupSafe==1.1.1 mccabe==0.6.1 -numpy==1.16.3 +numpy==1.21.0 olefile==0.46 Pillow==9.0.1 pylint==2.3.1 From 6deafdad9829308cccfc5601ace9658c4062e4e8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Jun 2022 05:08:43 +0000 Subject: [PATCH 224/240] Bump numpy from 1.21.0 to 1.22.0 in /install Bumps [numpy](https://github.com/numpy/numpy) from 1.21.0 to 1.22.0. - [Release notes](https://github.com/numpy/numpy/releases) - [Changelog](https://github.com/numpy/numpy/blob/main/doc/HOWTO_RELEASE.rst) - [Commits](https://github.com/numpy/numpy/compare/v1.21.0...v1.22.0) --- updated-dependencies: - dependency-name: numpy dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index 9e1756c..cb24a17 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -19,7 +19,7 @@ lazy-object-proxy==1.3.1 loady==1.8.10 MarkupSafe==1.1.1 mccabe==0.6.1 -numpy==1.21.0 +numpy==1.22.0 olefile==0.46 Pillow==9.0.1 pylint==2.3.1 From 122f2572ddc842a7fb15cebd1094a6edb9cb3871 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Nov 2022 10:33:46 +0000 Subject: [PATCH 225/240] Bump pillow from 9.0.1 to 9.3.0 in /install Bumps [pillow](https://github.com/python-pillow/Pillow) from 9.0.1 to 9.3.0. - [Release notes](https://github.com/python-pillow/Pillow/releases) - [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst) - [Commits](https://github.com/python-pillow/Pillow/compare/9.0.1...9.3.0) --- updated-dependencies: - dependency-name: pillow dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index 9e1756c..4b03894 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -21,7 +21,7 @@ MarkupSafe==1.1.1 mccabe==0.6.1 numpy==1.21.0 olefile==0.46 -Pillow==9.0.1 +Pillow==9.3.0 pylint==2.3.1 pyserial==3.4 python-dateutil==2.8.0 From fd61f1c268db5a63bd7d691801641b541ed160cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Dec 2022 05:37:16 +0000 Subject: [PATCH 226/240] Bump certifi from 2019.3.9 to 2022.12.7 in /install Bumps [certifi](https://github.com/certifi/python-certifi) from 2019.3.9 to 2022.12.7. - [Release notes](https://github.com/certifi/python-certifi/releases) - [Commits](https://github.com/certifi/python-certifi/compare/2019.03.09...2022.12.07) --- updated-dependencies: - dependency-name: certifi dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index 9e1756c..8184619 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -4,7 +4,7 @@ beautifulsoup4==4.7.1 BiblioPixel==3.4.46 BiblioPixelAnimations==3.20190410.153508 BiblioPixelTriggers==1.0.2 -certifi==2019.3.9 +certifi==2022.12.7 chardet==3.0.4 Click==7.0 croniter==0.3.30 From 21031a401c53c5aa09e9872b403afc581695a09c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 Feb 2023 21:44:39 +0000 Subject: [PATCH 227/240] Bump werkzeug from 0.15.3 to 2.2.3 in /install Bumps [werkzeug](https://github.com/pallets/werkzeug) from 0.15.3 to 2.2.3. - [Release notes](https://github.com/pallets/werkzeug/releases) - [Changelog](https://github.com/pallets/werkzeug/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/werkzeug/compare/0.15.3...2.2.3) --- updated-dependencies: - dependency-name: werkzeug dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index 2df1ed4..c44e52b 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -32,7 +32,7 @@ smmap2==2.0.5 soupsieve==1.9.1 urllib3==1.26.5 websockets==9.1 -Werkzeug==0.15.3 +Werkzeug==2.2.3 wrapt==1.11.1 spidev python-periphery From 86f068e64e6dd85072933378ff4e63b07e803234 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 May 2023 20:51:04 +0000 Subject: [PATCH 228/240] Bump flask from 1.0.2 to 2.3.2 in /install Bumps [flask](https://github.com/pallets/flask) from 1.0.2 to 2.3.2. - [Release notes](https://github.com/pallets/flask/releases) - [Changelog](https://github.com/pallets/flask/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/flask/compare/1.0.2...2.3.2) --- updated-dependencies: - dependency-name: flask dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index 2df1ed4..b84ba88 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -8,7 +8,7 @@ certifi==2022.12.7 chardet==3.0.4 Click==7.0 croniter==0.3.30 -Flask==1.0.2 +Flask==2.3.2 gitdb2==2.0.5 GitPython==2.1.11 idna==2.8 From 59ace4d241ea1cd07e7fef70b4ca23b86e60a7ba Mon Sep 17 00:00:00 2001 From: Reinarrow <75931652+reinarrow@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:54:09 +0100 Subject: [PATCH 229/240] Update moonboard_app_protocol.py for new app Adding support for new kind of holds: - 'P': Old Progress hold - 'R': Right hold - 'L': Left hold - 'M': Match hold - 'F': Foot hold --- ble/moonboard_app_protocol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ble/moonboard_app_protocol.py b/ble/moonboard_app_protocol.py index cce8cea..b463ca1 100644 --- a/ble/moonboard_app_protocol.py +++ b/ble/moonboard_app_protocol.py @@ -17,7 +17,7 @@ def decode_problem_string(s): t,p = h[0],position_trans(int(h[1:])) if t=='S': holds['START'].append(p) - if t=='P': + if t=='P' || t == 'R' || t == 'L' || t == 'M' || t =='F': holds['MOVES'].append(p) if t=='E': holds['TOP'].append(p) @@ -67,4 +67,4 @@ def process_bytes(self, ba): self.logger.debug('error: not started') self.s= '' else: - self.s+=s \ No newline at end of file + self.s+=s From 3884cfef97cb3196f70f89abe430f3e61cc573cf Mon Sep 17 00:00:00 2001 From: Reinarrow <75931652+reinarrow@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:06:10 +0100 Subject: [PATCH 230/240] Hotfix with correct 'or' implementation --- ble/moonboard_app_protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ble/moonboard_app_protocol.py b/ble/moonboard_app_protocol.py index b463ca1..0178fa8 100644 --- a/ble/moonboard_app_protocol.py +++ b/ble/moonboard_app_protocol.py @@ -17,7 +17,7 @@ def decode_problem_string(s): t,p = h[0],position_trans(int(h[1:])) if t=='S': holds['START'].append(p) - if t=='P' || t == 'R' || t == 'L' || t == 'M' || t =='F': + if t=='P' or t == 'R' or t == 'L' or t == 'M' or t =='F': holds['MOVES'].append(p) if t=='E': holds['TOP'].append(p) From c147d82ae0d73df7826f0a6f1fac401e337cbaba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:42:20 +0000 Subject: [PATCH 231/240] Bump werkzeug from 2.2.3 to 3.0.6 in /install Bumps [werkzeug](https://github.com/pallets/werkzeug) from 2.2.3 to 3.0.6. - [Release notes](https://github.com/pallets/werkzeug/releases) - [Changelog](https://github.com/pallets/werkzeug/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/werkzeug/compare/2.2.3...3.0.6) --- updated-dependencies: - dependency-name: werkzeug dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index ff52c0f..3564cb6 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -32,7 +32,7 @@ smmap2==2.0.5 soupsieve==1.9.1 urllib3==1.26.5 websockets==9.1 -Werkzeug==2.2.3 +Werkzeug==3.0.6 wrapt==1.11.1 spidev python-periphery From e7e417e4fc9a70555137d568ede754318e5a61e9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:42:21 +0000 Subject: [PATCH 232/240] Bump urllib3 from 1.26.5 to 1.26.19 in /install Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.26.5 to 1.26.19. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/1.26.5...1.26.19) --- updated-dependencies: - dependency-name: urllib3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index ff52c0f..504aae3 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -30,7 +30,7 @@ requests==2.21.0 six==1.12.0 smmap2==2.0.5 soupsieve==1.9.1 -urllib3==1.26.5 +urllib3==1.26.19 websockets==9.1 Werkzeug==2.2.3 wrapt==1.11.1 From 60d026466ce31c5e21108aad197683bd085a88ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:42:21 +0000 Subject: [PATCH 233/240] Bump certifi from 2022.12.7 to 2024.7.4 in /install Bumps [certifi](https://github.com/certifi/python-certifi) from 2022.12.7 to 2024.7.4. - [Commits](https://github.com/certifi/python-certifi/compare/2022.12.07...2024.07.04) --- updated-dependencies: - dependency-name: certifi dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index ff52c0f..1e88f6d 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -4,7 +4,7 @@ beautifulsoup4==4.7.1 BiblioPixel==3.4.46 BiblioPixelAnimations==3.20190410.153508 BiblioPixelTriggers==1.0.2 -certifi==2022.12.7 +certifi==2024.7.4 chardet==3.0.4 Click==7.0 croniter==0.3.30 From f658ab76753fb650b1e9d011be68845b4f8a7210 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:42:22 +0000 Subject: [PATCH 234/240] Bump gitpython from 2.1.11 to 3.1.41 in /install Bumps [gitpython](https://github.com/gitpython-developers/GitPython) from 2.1.11 to 3.1.41. - [Release notes](https://github.com/gitpython-developers/GitPython/releases) - [Changelog](https://github.com/gitpython-developers/GitPython/blob/main/CHANGES) - [Commits](https://github.com/gitpython-developers/GitPython/compare/2.1.11...3.1.41) --- updated-dependencies: - dependency-name: gitpython dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index ff52c0f..b31124b 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -10,7 +10,7 @@ Click==7.0 croniter==0.3.30 Flask==2.3.2 gitdb2==2.0.5 -GitPython==2.1.11 +GitPython==3.1.41 idna==2.8 isort==4.3.17 itsdangerous==1.1.0 From 2b3fb2740a78e11699db04a1af48a57b2980117e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:42:23 +0000 Subject: [PATCH 235/240] Bump requests from 2.21.0 to 2.32.2 in /install Bumps [requests](https://github.com/psf/requests) from 2.21.0 to 2.32.2. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.21.0...v2.32.2) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index ff52c0f..bef759d 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -26,7 +26,7 @@ pylint==2.3.1 pyserial==3.4 python-dateutil==2.8.0 PyYAML==5.4 -requests==2.21.0 +requests==2.32.2 six==1.12.0 smmap2==2.0.5 soupsieve==1.9.1 From 1be90e94345e8af63617ac09b060ac8f625eb374 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:42:24 +0000 Subject: [PATCH 236/240] Bump jinja2 from 2.11.3 to 3.1.6 in /install Bumps [jinja2](https://github.com/pallets/jinja) from 2.11.3 to 3.1.6. - [Release notes](https://github.com/pallets/jinja/releases) - [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/jinja/compare/2.11.3...3.1.6) --- updated-dependencies: - dependency-name: jinja2 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index ff52c0f..ab9294c 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -14,7 +14,7 @@ GitPython==2.1.11 idna==2.8 isort==4.3.17 itsdangerous==1.1.0 -Jinja2==2.11.3 +Jinja2==3.1.6 lazy-object-proxy==1.3.1 loady==1.8.10 MarkupSafe==1.1.1 From 720632e37a73352ea23794e752d2fd9654a3baa2 Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Sun, 9 Mar 2025 12:57:51 +0100 Subject: [PATCH 237/240] flask no specific version --- install/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements.txt b/install/requirements.txt index 59f2a81..cf3ef21 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -8,7 +8,7 @@ certifi==2024.7.4 chardet==3.0.4 Click==7.0 croniter==0.3.30 -Flask==2.3.2 +Flask gitdb2==2.0.5 GitPython==3.1.41 idna==2.8 From b605c312aca8ae2c274079c2d15c0e39394e0336 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Feb 2026 11:21:55 +0000 Subject: [PATCH 238/240] Fix BLE stability: auto-restart btmon and re-advertise on disconnect Two critical issues caused the need for manual restarts: 1. btmon subprocess was never restarted when it exited - the service kept running but silently stopped receiving BLE data. Now btmon is monitored in a loop with exponential backoff (2s-30s) and automatically restarted on exit. 2. After an iPhone disconnected, BLE advertising was never restarted, making the Moonboard invisible for reconnection. Now "Disconnect Complete" events from btmon are detected and advertising is automatically re-setup and started. Also fixes: proper fd cleanup, decode error handling, daemon thread. https://claude.ai/code/session_01ARBx1xkrRnWGBYsSb3y4Zg --- ble/moonboard_ble_dbus_service.py | 90 +++++++++++++++++++++++++------ ble/moonboard_ble_service.py | 86 +++++++++++++++++++++++------ 2 files changed, 146 insertions(+), 30 deletions(-) diff --git a/ble/moonboard_ble_dbus_service.py b/ble/moonboard_ble_dbus_service.py index d4ffc42..55c0d96 100644 --- a/ble/moonboard_ble_dbus_service.py +++ b/ble/moonboard_ble_dbus_service.py @@ -10,6 +10,8 @@ from moonboard_app_protocol import UnstuffSequence, decode_problem_string import os +import errno +import time import threading import pty @@ -82,24 +84,82 @@ def __init__(self, bus, socket,logger): dbus.service.Object.__init__(self, bus, self.path) self.add_service(UartService(bus,self.get_path(), 0, self.process_rx)) - monitor_thread = threading.Thread(target=self.monitor_btmon) + monitor_thread = threading.Thread(target=self.monitor_btmon, daemon=True) monitor_thread.start() - def monitor_btmon(self): - out_r, out_w = pty.openpty() - cmd = ["sudo","btmon"] - process = subprocess.Popen(cmd, stdout=out_w) - f = OutStream(out_r) + def _restart_advertising(self): + """Re-setup and start BLE advertising after a disconnect.""" + self.logger.info('Client disconnected, restarting advertising...') + try: + setup_adv(self.logger) + start_adv(self.logger) + self.logger.info('Advertising restarted successfully') + except Exception as e: + self.logger.error('Failed to restart advertising: ' + str(e)) + + def monitor_btmon(self): + restart_delay = 2 + max_restart_delay = 30 + while True: - lines, readable = f.read_lines() - if not readable: break - for line in lines: - if line != '': - line = line.decode() - if 'Data:' in line: - data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') - self.process_rx(data) - self.logger.info('New data '+ data) + out_r, out_w = pty.openpty() + cmd = ["sudo", "btmon"] + try: + process = subprocess.Popen(cmd, stdout=out_w) + self.logger.info('btmon started (pid %d)', process.pid) + except Exception as e: + self.logger.error('Failed to start btmon: ' + str(e)) + os.close(out_r) + os.close(out_w) + time.sleep(restart_delay) + restart_delay = min(restart_delay * 2, max_restart_delay) + continue + + f = OutStream(out_r) + restart_delay = 2 # reset backoff on successful start + + try: + while True: + lines, readable = f.read_lines() + if not readable: + break + for line in lines: + if line != b'': + try: + line = line.decode(errors='ignore') + except Exception: + continue + if 'Disconnect Complete' in line: + self._restart_advertising() + elif 'Data:' in line: + data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') + self.process_rx(data) + self.logger.info('New data '+ data) + except Exception as e: + self.logger.error('btmon monitoring error: ' + str(e)) + + # Cleanup + try: + process.terminate() + process.wait(timeout=5) + except Exception: + try: + process.kill() + process.wait(timeout=5) + except Exception: + pass + try: + os.close(out_r) + except OSError: + pass + try: + os.close(out_w) + except OSError: + pass + + self.logger.warning('btmon exited, restarting in %ds...', restart_delay) + time.sleep(restart_delay) + restart_delay = min(restart_delay * 2, max_restart_delay) def process_rx(self,ba): new_problem_string= self.unstuffer.process_bytes(ba) diff --git a/ble/moonboard_ble_service.py b/ble/moonboard_ble_service.py index 5e8fc42..162c7fd 100755 --- a/ble/moonboard_ble_service.py +++ b/ble/moonboard_ble_service.py @@ -9,6 +9,8 @@ import paho.mqtt.client as mqtt import os +import errno +import time import threading import pty @@ -117,22 +119,76 @@ def process_rx(self, unstuffer,logger,ba): unstuffer.flags = '' self.start_adv(logger) - def monitor_btmon(self, logger, unstuffer): - out_r, out_w = pty.openpty() - cmd = ["sudo","btmon"] - process = subprocess.Popen(cmd, stdout=out_w) - f = OutStream(out_r) + def monitor_btmon(self, logger, unstuffer): + restart_delay = 2 + max_restart_delay = 30 + while True: - lines, readable = f.read_lines() - if not readable: break - for line in lines: - if line != '': - line = line.decode() - if 'Data:' in line: - data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') - self.process_rx(unstuffer,logger,data) - t1 = bytearray.fromhex(data).decode(errors="ignore") - logger.info('New data '+ data+ 'and decoded '+t1) + out_r, out_w = pty.openpty() + cmd = ["sudo", "btmon"] + try: + process = subprocess.Popen(cmd, stdout=out_w) + logger.info('btmon started (pid %d)', process.pid) + except Exception as e: + logger.error('Failed to start btmon: ' + str(e)) + os.close(out_r) + os.close(out_w) + time.sleep(restart_delay) + restart_delay = min(restart_delay * 2, max_restart_delay) + continue + + f = OutStream(out_r) + restart_delay = 2 # reset backoff on successful start + + try: + while True: + lines, readable = f.read_lines() + if not readable: + break + for line in lines: + if line != b'': + try: + line = line.decode(errors='ignore') + except Exception: + continue + if 'Disconnect Complete' in line: + logger.info('Client disconnected, restarting advertising...') + try: + self.setup_adv(logger) + self.start_adv(logger) + logger.info('Advertising restarted successfully') + except Exception as e: + logger.error('Failed to restart advertising: ' + str(e)) + elif 'Data:' in line: + data = line.replace(' ','').replace('\x1b','').replace('[0m','').replace('Data:','') + self.process_rx(unstuffer, logger, data) + t1 = bytearray.fromhex(data).decode(errors="ignore") + logger.info('New data '+ data + ' and decoded ' + t1) + except Exception as e: + logger.error('btmon monitoring error: ' + str(e)) + + # Cleanup + try: + process.terminate() + process.wait(timeout=5) + except Exception: + try: + process.kill() + process.wait(timeout=5) + except Exception: + pass + try: + os.close(out_r) + except OSError: + pass + try: + os.close(out_w) + except OSError: + pass + + logger.warning('btmon exited, restarting in %ds...', restart_delay) + time.sleep(restart_delay) + restart_delay = min(restart_delay * 2, max_restart_delay) def main(self,logger,adapter): From a318b32e2df2a3f15a6198ebe649d8c9b96f220b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Feb 2026 11:33:09 +0000 Subject: [PATCH 239/240] Add update script and fix broken fix_startup.sh - scripts/update.sh: pulls latest code from a given branch and restarts all installed moonboard services - scripts/fix_startup.sh: fix syntax error (wrong variable name in for loop) https://claude.ai/code/session_01ARBx1xkrRnWGBYsSb3y4Zg --- scripts/fix_startup.sh | 4 ++-- scripts/update.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100755 scripts/update.sh diff --git a/scripts/fix_startup.sh b/scripts/fix_startup.sh index 412aa59..4fe5f93 100755 --- a/scripts/fix_startup.sh +++ b/scripts/fix_startup.sh @@ -1,4 +1,4 @@ #!/bin/bash -for s in moonboard_led.service moonboard_ble.service; -sudo systemctl restart $service +for service in moonboard_led.service moonboard_ble.service; do + sudo systemctl restart "$service" done diff --git a/scripts/update.sh b/scripts/update.sh new file mode 100755 index 0000000..1f8ac36 --- /dev/null +++ b/scripts/update.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)" +BRANCH="${1:-main}" + +echo "=== Moonboard Update ===" +echo "Repo: $REPO_DIR" +echo "Branch: $BRANCH" + +# Pull latest code +echo "" +echo "Pulling latest changes..." +cd "$REPO_DIR" +git fetch origin "$BRANCH" +git checkout "$BRANCH" +git pull origin "$BRANCH" + +# Restart services +echo "" +echo "Restarting services..." +for service in moonboard_ble moonboard_led; do + if systemctl is-enabled "${service}.service" &>/dev/null; then + echo " Restarting ${service}..." + sudo systemctl restart "${service}.service" + echo " ${service}: $(systemctl is-active ${service}.service)" + else + echo " ${service}: not installed, skipping" + fi +done + +echo "" +echo "Update complete." From b8d9e2c1170b46c7c730cd17e5083dda09c68e23 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Feb 2026 15:00:39 +0000 Subject: [PATCH 240/240] Resolve merge conflict in led_mapping.json (use 3-LED spacing) The file had unresolved git merge conflict markers which caused the LED service to crash with a JSON parse error on startup. Resolved to the WS2801 variant with 3-LED spacing per hold. https://claude.ai/code/session_01ARBx1xkrRnWGBYsSb3y4Zg --- led/led_mapping.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/led/led_mapping.json b/led/led_mapping.json index dbf79c2..7211e33 100755 --- a/led/led_mapping.json +++ b/led/led_mapping.json @@ -1,5 +1 @@ -<<<<<<< HEAD {"A1": 0, "A2": 3, "A3": 6, "A4": 9, "A5": 12, "A6": 15, "A7": 18, "A8": 21, "A9": 24, "A10": 27, "A11": 30, "A12": 33, "A13": 36, "A14": 39, "A15": 42, "A16": 45, "A17": 48, "A18": 51, "B18": 54, "B17": 57, "B16": 60, "B15": 63, "B14": 66, "B13": 69, "B12": 72, "B11": 75, "B10": 78, "B9": 81, "B8": 84, "B7": 87, "B6": 90, "B5": 93, "B4": 96, "B3": 99, "B2": 102, "B1": 105, "C1": 108, "C2": 111, "C3": 114, "C4": 117, "C5": 120, "C6": 123, "C7": 126, "C8": 129, "C9": 132, "C10": 135, "C11": 138, "C12": 141, "C13": 144, "C14": 147, "C15": 150, "C16": 153, "C17": 156, "C18": 159, "D18": 162, "D17": 165, "D16": 168, "D15": 171, "D14": 174, "D13": 177, "D12": 180, "D11": 183, "D10": 186, "D9": 189, "D8": 192, "D7": 195, "D6": 198, "D5": 201, "D4": 204, "D3": 207, "D2": 210, "D1": 213, "E1": 216, "E2": 219, "E3": 222, "E4": 225, "E5": 228, "E6": 231, "E7": 234, "E8": 237, "E9": 240, "E10": 243, "E11": 246, "E12": 249, "E13": 252, "E14": 256, "E15": 259, "E16": 262, "E17": 265, "E18": 268, "F18": 271, "F17": 274, "F16": 277, "F15": 280, "F14": 283, "F13": 286, "F12": 289, "F11": 292, "F10": 295, "F9": 298, "F8": 301, "F7": 304, "F6": 307, "F5": 310, "F4": 313, "F3": 316, "F2": 319, "F1": 322, "G1": 325, "G2": 328, "G3": 331, "G4": 334, "G5": 337, "G6": 340, "G7": 343, "G8": 346, "G9": 349, "G10": 352, "G11": 355, "G12": 358, "G13": 361, "G14": 364, "G15": 367, "G16": 370, "G17": 373, "G18": 376, "H18": 379, "H17": 382, "H16": 385, "H15": 388, "H14": 391, "H13": 394, "H12": 397, "H11": 400, "H10": 403, "H9": 406, "H8": 409, "H7": 412, "H6": 415, "H5": 418, "H4": 421, "H3": 424, "H2": 427, "H1": 430, "I1": 433, "I2": 436, "I3": 439, "I4": 442, "I5": 445, "I6": 448, "I7": 451, "I8": 454, "I9": 457, "I10": 461, "I11": 464, "I12": 467, "I13": 470, "I14": 473, "I15": 476, "I16": 479, "I17": 482, "I18": 485, "J18": 488, "J17": 491, "J16": 494, "J15": 497, "J14": 500, "J13": 503, "J12": 506, "J11": 509, "J10": 512, "J9": 515, "J8": 518, "J7": 521, "J6": 524, "J5": 527, "J4": 530, "J3": 533, "J2": 536, "J1": 539, "K1": 542, "K2": 545, "K3": 548, "K4": 551, "K5": 554, "K6": 557, "K7": 560, "K8": 563, "K9": 566, "K10": 569, "K11": 572, "K12": 575, "K13": 578, "K14": 581, "K15": 584, "K16": 587, "K17": 590, "K18": 593} -======= -{"A1": 0, "A2": 1, "A3": 2, "A4": 3, "A5": 4, "A6": 5, "A7": 6, "A8": 7, "A9": 8, "A10": 9, "A11": 10, "A12": 11, "A13": 12, "A14": 13, "A15": 14, "A16": 15, "A17": 16, "A18": 17, "B18": 18, "B17": 19, "B16": 20, "B15": 21, "B14": 22, "B13": 23, "B12": 24, "B11": 25, "B10": 26, "B9": 27, "B8": 28, "B7": 29, "B6": 30, "B5": 31, "B4": 32, "B3": 33, "B2": 34, "B1": 35, "C1": 36, "C2": 37, "C3": 38, "C4": 39, "C5": 40, "C6": 41, "C7": 42, "C8": 43, "C9": 44, "C10": 45, "C11": 46, "C12": 47, "C13": 48, "C14": 49, "C15": 50, "C16": 51, "C17": 52, "C18": 53, "D18": 54, "D17": 55, "D16": 56, "D15": 57, "D14": 58, "D13": 59, "D12": 60, "D11": 61, "D10": 62, "D9": 63, "D8": 64, "D7": 65, "D6": 66, "D5": 67, "D4": 68, "D3": 69, "D2": 70, "D1": 71, "E1": 72, "E2": 73, "E3": 74, "E4": 75, "E5": 76, "E6": 77, "E7": 78, "E8": 79, "E9": 80, "E10": 81, "E11": 82, "E12": 83, "E13": 84, "E14": 85, "E15": 86, "E16": 87, "E17": 88, "E18": 89, "F18": 90, "F17": 91, "F16": 92, "F15": 93, "F14": 94, "F13": 95, "F12": 96, "F11": 97, "F10": 98, "F9": 99, "F8": 100, "F7": 101, "F6": 102, "F5": 103, "F4": 104, "F3": 105, "F2": 106, "F1": 107, "G1": 108, "G2": 109, "G3": 110, "G4": 111, "G5": 112, "G6": 113, "G7": 114, "G8": 115, "G9": 116, "G10": 117, "G11": 118, "G12": 119, "G13": 120, "G14": 121, "G15": 122, "G16": 123, "G17": 124, "G18": 125, "H18": 126, "H17": 127, "H16": 128, "H15": 129, "H14": 130, "H13": 131, "H12": 132, "H11": 133, "H10": 134, "H9": 135, "H8": 136, "H7": 137, "H6": 138, "H5": 139, "H4": 140, "H3": 141, "H2": 142, "H1": 143, "I1": 144, "I2": 145, "I3": 146, "I4": 147, "I5": 148, "I6": 149, "I7": 150, "I8": 151, "I9": 152, "I10": 153, "I11": 154, "I12": 155, "I13": 156, "I14": 157, "I15": 158, "I16": 159, "I17": 160, "I18": 161, "J18": 162, "J17": 163, "J16": 164, "J15": 165, "J14": 166, "J13": 167, "J12": 168, "J11": 169, "J10": 170, "J9": 171, "J8": 172, "J7": 173, "J6": 174, "J5": 175, "J4": 176, "J3": 177, "J2": 178, "J1": 179, "K1": 180, "K2": 181, "K3": 182, "K4": 183, "K5": 184, "K6": 185, "K7": 186, "K8": 187, "K9": 188, "K10": 189, "K11": 190, "K12": 191, "K13": 192, "K14": 193, "K15": 194, "K16": 195, "K17": 196, "K18": 197} ->>>>>>> 3884cfef97cb3196f70f89abe430f3e61cc573cf