Skip to content

EV3-G API: touch sensor add is_released#367

Merged
dwalton76 merged 7 commits intoev3dev:developfrom
dwalton76:ev3g-api-touch-sensor
Sep 23, 2017
Merged

EV3-G API: touch sensor add is_released#367
dwalton76 merged 7 commits intoev3dev:developfrom
dwalton76:ev3g-api-touch-sensor

Conversation

@dwalton76
Copy link
Copy Markdown
Collaborator

No description provided.

@dwalton76
Copy link
Copy Markdown
Collaborator Author

So I added this for TouchSensor and was about to start on wait_for_pressed() and wait_for_released() (because those would be handy) but then noticed that a huge chunk of the sensors code is autogenerated from the templates...so the code in this PR will be over-written the next time some uses the templates to build core.py.

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:

  • There have only been 5 commits to it all year, a good indication that things are not churning at nearly the rate that they used to
  • I find it difficult to use. I tried running it again today and it failed despite there not being any checkins since the last time I ran it and it worked.
  • It clutters the code base with # ~autogen generic-class classes.motor>currentClass and # ~autogen comments
  • It makes it way more complicated than it needs to be to add code like I have in this PR

The only thing we have to do to move away from it in ev3dev-lang-python is

  • remove the # ~autogen lines
  • remove the ev3dev-lang submodule

It could still be used for other ev3dev-lang-XYZ repos if they wish to use it.

Thoughts? Objections? +1s? :)

@dwalton76
Copy link
Copy Markdown
Collaborator Author

Making sure @ddemidov @dlech @WasabiFan @ensonic see this

@ddemidov
Copy link
Copy Markdown
Member

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).

@WasabiFan
Copy link
Copy Markdown
Member

I think @dwalton76 was having issues running the script and I haven't sat down to debug it yet.

@ddemidov
Copy link
Copy Markdown
Member

I just tried to do this myself and noticed that @dwalton76 already did this :). Sorry for the noise.

@dwalton76
Copy link
Copy Markdown
Collaborator Author

cool, removal of ev3dev-lang and autogen via PR #368

@dwalton76
Copy link
Copy Markdown
Collaborator Author

Am holding off on merging this in...will implement the following this weekend

wait_for_pressed()
wait_for_released()
wait_for_bumped()

Comment thread ev3dev/core.py Outdated

#: Button state
MODE_TOUCH = 'TOUCH'
MODES = ('TOUCH',)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove trailing comma

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, can we use the other constant as the value here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The trailing comma is needed for single entry tuples

>>> MODES = ('TOUCH',)
>>> MODES[0]
'TOUCH'
>>> 
>>> MODES = ('TOUCH')
>>> MODES[0]
'T'
>>> 

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Will change it to MODES = (MODE_TOUCH,)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

😒 Python is... a special language.

Comment thread ev3dev/core.py Outdated
while True:
self._poll.poll(timeout_ms)

if wait_for_press:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we reduce this to a single Boolean expression?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ah I follow you now, fixed.

Comment thread ev3dev/core.py Outdated
start_time = time.time()

if self.wait_for_pressed(timeout_ms):
timeout_ms -= int((time.time() - start_time) * 1000)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yep, good catch! Fixed now

@dwalton76
Copy link
Copy Markdown
Collaborator Author

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

@dwalton76 dwalton76 merged commit 4974253 into ev3dev:develop Sep 23, 2017
@dwalton76 dwalton76 deleted the ev3g-api-touch-sensor branch September 23, 2017 12:26
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.

3 participants