EV3-G API: touch sensor add is_released#367
EV3-G API: touch sensor add is_released#367dwalton76 merged 7 commits intoev3dev:developfrom dwalton76:ev3g-api-touch-sensor
Conversation
|
So I added this for TouchSensor and was about to start on On our call the other night we kicked around the idea of life without the templates and autogen. I wasn't around when it was written but it sounds like things were changing often enough back then to make it worth it. Today though it doesn't feel worth it to me, the reasons being:
The only thing we have to do to move away from it in ev3dev-lang-python is
It could still be used for other ev3dev-lang-XYZ repos if they wish to use it. Thoughts? Objections? +1s? :) |
|
Making sure @ddemidov @dlech @WasabiFan @ensonic see this |
|
I am ok with this, just make sure to run the autogen one last time before you strip it off (I think your stretch-related commits in ev3dev-lang have not yet been applied). |
|
I think @dwalton76 was having issues running the script and I haven't sat down to debug it yet. |
|
I just tried to do this myself and noticed that @dwalton76 already did this :). Sorry for the noise. |
|
cool, removal of ev3dev-lang and autogen via PR #368 |
…thon into ev3g-api-touch-sensor
|
Am holding off on merging this in...will implement the following this weekend |
|
|
||
| #: Button state | ||
| MODE_TOUCH = 'TOUCH' | ||
| MODES = ('TOUCH',) |
There was a problem hiding this comment.
Also, can we use the other constant as the value here?
There was a problem hiding this comment.
The trailing comma is needed for single entry tuples
>>> MODES = ('TOUCH',)
>>> MODES[0]
'TOUCH'
>>>
>>> MODES = ('TOUCH')
>>> MODES[0]
'T'
>>>
There was a problem hiding this comment.
Will change it to MODES = (MODE_TOUCH,)
There was a problem hiding this comment.
😒 Python is... a special language.
| while True: | ||
| self._poll.poll(timeout_ms) | ||
|
|
||
| if wait_for_press: |
There was a problem hiding this comment.
Can we reduce this to a single Boolean expression?
There was a problem hiding this comment.
Meaning if (wait_for_press and self.is_pressed) or (not wait_for_press and self.is_released)? I could go either way but I think the current layout is a tiny bit easier to read.
There was a problem hiding this comment.
wait_for_press ^ self.is_released or self.is_pressed == wait_for_press? I think either should work, feel free to switch inversions for readability if that's useful.
There was a problem hiding this comment.
ah I follow you now, fixed.
| start_time = time.time() | ||
|
|
||
| if self.wait_for_pressed(timeout_ms): | ||
| timeout_ms -= int((time.time() - start_time) * 1000) |
There was a problem hiding this comment.
What happens here is timeout_ms is None? I think something like:
>>> None - 4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'There was a problem hiding this comment.
yep, good catch! Fixed now
|
ok I think that is everything from the code review comments so am going to merge this one and we can do any further tweaking here via a new PR/issue. This is for issue #361 |
No description provided.