Git Product home page Git Product logo

Comments (4)

martinohanlon avatar martinohanlon commented on September 26, 2024 1

This sounds like issue #11 ?

from bluedot.

martinohanlon avatar martinohanlon commented on September 26, 2024 1

I have created a POC - https://github.com/martinohanlon/BlueDot/blob/dev/examples/click_wheel.py

It seems to work quite well, it needs some refinement, but its 90% there.

It works by splitting the dot into segments, when you pass from 1 segment to the next it is considered to have been rotated.

Im thinking a when_rotated property which will call a function and pass a BlueDotRotation object (similar to when_pressed, when_swiped).

BlueDotRotation will have properties such as:

  • .value - -1 for anti-clockwise, 1 for clockwise
  • anti_clockwise - True if rotated anti clockwise
  • clockwise - True if rotated clockwise
  • previous_segment - no between 1 & no_of_segments which returns where the position has moved from
  • current_segment - no between 1 & no_of_segments which returns where the position has moved too
  • anything else I think of at the time.

from bluedot.

ukBaz avatar ukBaz commented on September 26, 2024

I have been looking at this a little more this morning. Not sure where you are with implementing the click wheel functionality so I thought I would share where I am with it.

What I have not been able to implement is switching between modes. i.e. when is it a swipe/click versus drawing a circle.
What I have been able to do is implement a function that returns a negative number for anticlockwise and positive for clockwise. The function assumes you haven't moved more than 180 degrees between readings. In my tests I couldn't move that fast so it might be an OK assumption.

My function is:

def calc_rotation(prev, current):
    delta = current - prev
    if -180 < delta <= 180:
        pass
    elif delta > 180:
        delta = delta - 360
    elif delta <= -180:
        delta = delta + 360
    return delta

An example use is:

from bluedot import BlueDot
from signal import pause

bd = BlueDot()
prev_angle = 0


def calc_rotation(prev, current):
    delta = current - prev
    if -180 < delta <= 180:
        pass
    elif delta > 180:
        delta = delta - 360
    elif delta <= -180:
        delta = delta + 360
    return delta


def move(pos):
    global prev_angle
    current_angle = pos.angle
    turn = calc_rotation(prev_angle, current_angle)
    print('Moved ', turn)
    prev_angle = current_angle

bd.when_moved = move

pause()

I did some tests as I was developing it:

import unittest
from click_wheel.click_wheel import calc_rotation


class GetRotation(unittest.TestCase):
    def test_anti_clk(self):
        self.assertEqual(calc_rotation(120, 100),
                         -20)

    def test_clkwise(self):
        self.assertEqual(calc_rotation(100, 120),
                         20)

    def test_bndry_anti_clk(self):
        self.assertEqual(calc_rotation(10, -10),
                         -20)

    def test_bndry_clkwise(self):
        self.assertEqual(calc_rotation(-10, 10),
                         20)

    def test_south_bndry_anti_clk(self):
        self.assertEqual(calc_rotation(-170, 170),
                         -20)

    def test_south_bndry_clkwse(self):
        self.assertEqual(calc_rotation(170, -170),
                         20)


if __name__ == '__main__':
    unittest.main()

I hope this helps move this issue forward in some way.

Thanks

from bluedot.

martinohanlon avatar martinohanlon commented on September 26, 2024

Included in v1.2.0

from bluedot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.