Skip to content

Add functionality to set the Real-Time Playback value #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 9, 2023
Merged

Add functionality to set the Real-Time Playback value #34

merged 5 commits into from
Mar 9, 2023

Conversation

kriswilk
Copy link
Contributor

@kriswilk kriswilk commented Mar 7, 2023

This PR adds the ability to set the output value in Real-Time Playback mode. A port of this function from the DRV2605(L) Arduino library.

Closes #33

@tekktrik tekktrik requested a review from a team March 8, 2023 15:57
@jposada202020
Copy link
Contributor

Hello :) first, thank you for the add!!. Hopefully, I would be able to test over the weekend. However, in the meantime, just one comment. As you would need to put the device in RTP mode before using this function, I think it would be a good idea to document it either in the documentation and/or with an example, maybe something equivalent to this?

.. code-block:: python
# Getting the effect stored in a slot
slot_0_effect = drv.sequence[0]
# Setting an Effect in the first sequence slot
drv.sequence[0] = Effect(88)
"""
return self._sequence

Also, it would be good to create it as a property, so users could do something like
real_time_value = xxxxx

Let me know thanks :)

@kriswilk
Copy link
Contributor Author

kriswilk commented Mar 9, 2023

Thanks for the input. Both are good suggestions. I reworked the PR accordingly.

One change that may need explanation is allowing input values from -127 to 255. I did so since:

  • by default, the device treats the register value as a signed 8-bit integer (-127 to 127).
  • if the user sets the internal DATA_FORMAT_RTP bit to 1, the device treats the register value as unsigned (0 to 255)

Oddness occurs if the user READS a value outside 0-127 since the register is always read as unsigned. Without complicating the reading routine by also reading and checking the DATA_FORMAT_RTP bit, I don't see a way around this. I don't know if the overhead is worth it.

@jposada202020
Copy link
Contributor

Thanks for the changes. I agree with you, it is indeed difficult to take into account all the corner cases, I think we are covering the default behaviour, verifying the value. and the note do a good job both explaining and refering to the datasheet for more information. will test probably probably later, just want to test the change on hardware :)

Copy link
Contributor

@jposada202020 jposada202020 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks 👍🏼

Test

tested with Adafruit CircuitPython 8.0.2 on 2023-02-14; Adafruit Feather RP2040 with rp2040
and the following test script

import time
import board
import adafruit_drv2605


# Initialize I2C bus and DRV2605 module.
i2c = board.I2C()
drv = adafruit_drv2605.DRV2605(i2c)

print("Start real-time playback")
print("Mode value before:", drv.mode)
print("real time value before:", drv.realtime_value)
drv.realtime_value = 0
print("real time value after:", drv.realtime_value)
drv.mode = adafruit_drv2605.MODE_REALTIME
print("Mode value after:", drv.mode)

print("Buzz the motor briefly at 50% and 100% amplitude")
print("real time value before:", drv.realtime_value)
drv.realtime_value = 64
print("real time value after:", drv.realtime_value)
time.sleep(0.5)
print("real time value before:", drv.realtime_value)
drv.realtime_value = 127
print("real time value after:", drv.realtime_value)
time.sleep(0.5)

print("Stop real-time playback")
drv.realtime_value = 0
print("Mode value before:", drv.mode)
drv.mode = adafruit_drv2605.MODE_INTTRIG
print("Mode value after:", drv.mode)

Results

Start real-time playback
Mode value before: 0
real time value before: 0
real time value after: 0
Mode value after: 5
Buzz the motor briefly at 50% and 100% amplitude
real time value before: 0
real time value after: 64
real time value before: 64
real time value after: 127
Stop real-time playback
Mode value before: 5
Mode value after: 0

@jposada202020 jposada202020 merged commit 18eb504 into adafruit:main Mar 9, 2023
@kriswilk kriswilk deleted the patch-1 branch March 9, 2023 17:54
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 13, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_BNO08X to 1.1.10 from 1.1.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_BNO08x#39 from xenomorpheus/main
  > Add upload url to release action
  > Add .venv to .gitignore

Updating https://github.com/adafruit/Adafruit_CircuitPython_DRV2605 to 1.3.0 from 1.2.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_DRV2605#34 from kriswilk/patch-1
  > Add upload url to release action
  > Add .venv to .gitignore

Updating https://github.com/adafruit/Adafruit_CircuitPython_LC709203F to 2.2.11 from 2.2.10:
  > Merge pull request adafruit/Adafruit_CircuitPython_LC709203F#23 from edanidzerda/main
  > Add upload url to release action

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 9.0.2 from 9.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#183 from brentyi/main
  > Add upload url to release action
  > Add .venv to .gitignore

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.26.0 from 2.24.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#184 from Neradoc/fix-multiple-lines-in-bitmaplabel
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#186 from Neradoc/fix-bitmap-label-anchored-position

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_GFX

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function "setRealtimeValue()" is missing in the CircuitPython implementation
2 participants