Giter Site home page Giter Site logo

Comments (8)

joperezr avatar joperezr commented on September 2, 2024

I suppose that the motivation around this is to be able to write a software-based SPI, I2C or PWM protocol?

from iot.

shaggygi avatar shaggygi commented on September 2, 2024

This could benefit within for the bit-banging and protocols, as well. I initialing was thinking for areas like registers, latches, etc. where you sometimes need a to just clock a few times. This would help instead of having to create a bunch of for loops in the future.

An example, that comes to mind... in my senior college project, I interfaced a microcontroller to pull button status out of an N64 controller. The interface was set up in a way where there were X number of bytes somewhere within a range of bytes. The only way to get the info was by an individual data pin. So instead of have to for loop High/Low (or Low/High based on pin state) a number times... I could just say .Clock(1, X) to get me to where the bits started showing up on the data pin.

from iot.

joperezr avatar joperezr commented on September 2, 2024

What does X and 1 stand for in your example? In my mind, this method should take in a pinNumber, a double of frequency, and perhaps the number of cycles you want to send the signal.

from iot.

shaggygi avatar shaggygi commented on September 2, 2024

See original comment above for entire example. 1 represented the clkPin and X represents the number of times to clock.

I agree with you on the state issue (from #107) so the signature of method would have to change. Maybe something like...

int clkPin = 1;
int numberOfClocks = 5;
PinValue idlePinValue = PinValue.High;
controller.Clock(clkPin, numberOfClocks, idlePinValue);

One problem with this is the clkPin Value would already have to be at idlePinValue before calling as it could (1) miss the initial transition or (2) accidentally create an addition clock signal.

from iot.

joperezr avatar joperezr commented on September 2, 2024

Won't you also need some sort of parameter to define frequency in case the clock signals have to have some sort of delay between each other?

from iot.

shaggygi avatar shaggygi commented on September 2, 2024

Yup, that was for question 1.

  1. Should there be a time interval argument to toggle state (understanding this isn't going to be accurate)?

So the Clock method would be something like below. NOTE: I just threw in the frequency/delay argument, but more thinking is needed (e.g. Optional, default value, etc.).

public void Clock(int clkPin, int numberOfClocks, PinValue idlePinValue, int clockDelay)
{
    for(int clockCnt = 0; clockCnt < numberOfClocks; clockCnt++)
    {
        Thread.Sleep(clockDelay);

        if(idlePinValue == PinValue.Low)
        {
            _controller.Write(clkPin, PinValue.High);            
        }
        else
        {
            _controller.Write(clkPin, PinValue.Low);
        }

        Thread.Sleep(clockDelay);
        _controller.Write(clkPin, idlePinValue);  // Go back to initial idle value.
    }
}

from iot.

joperezr avatar joperezr commented on September 2, 2024

I'm not sure this would have enough value in order to have it on our main library API. On the other hand, if more than one device binding needs this, I would be ok if a method like this lives under src/devices/Common and have those bindings that need it to optionally call into this method. If we do want that, this could live in a class like GpioControllerExtensions.cs which looked something like:

public static class GpioControllerExtensions
{
  public static void Clock(this IGpioController controller, int clckPin, int numberOfClocks, PinValue idlePinValue, int clockDelay);
}

from iot.

shaggygi avatar shaggygi commented on September 2, 2024

This is another one of those "nice to haves", but not needed. I've only come up with one binding that would need and that small amount of code could reside in its own API. I'll close for now.

from iot.

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.