RELEASED: 3RD PARTY NXC DRIVER SUITE V0.2

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

RELEASED: 3RD PARTY NXC DRIVER SUITE V0.2

Post by HaWe »

hi @ all :)

this is my HT Touch Mux Driver - straight forward and simple to use:

Code: Select all

// excerpt from drivers.h
char HTTouchMuxValue(char port, char muxport) {  // muxport= 0...3
    long switches, value;
    char muxtouch;

    value=1023-SensorRaw(port);
    switches=339*value;
    switches/=1023-value;
    switches+=5;
    switches/=10;
    
    return muxtouch=(switches & (1 << muxport))?1:0;
}
test program:

Code: Select all

 // excerpt from stdio.h
#define printf2( _x, _y, _format1, _format2, _value1, _value2) { \
  string sval1 = FormatNum(_format1, _value1); \
  string sval2 = FormatNum(_format2, _value2); \
  string s =sval1+sval2; \
  TextOut(_x, _y, s); \
}

// excerpt from drivers.h
char HTTouchMuxValue(char port, char muxport) {  // muxport= 0...3
    long switches, value;
    char muxtouch;

    value=1023-SensorRaw(port);
    switches=339*value;
    switches/=1023-value;
    switches+=5;
    switches/=10;
    
    return muxtouch=(switches & (1 << muxport))?1:0;
}


task main(){
  char muxtouch;

  SetSensor(S2, SENSOR_TOUCH);

  while (true) {
    for (int i=0; i<4; ++i)  {
      muxtouch = HTTouchMuxValue(S2, i);
      printf2(0,40-(8*i), "switch%d="," %d", i+1, muxtouch);
      Wait(50);
    }
  }
}
share and enjoy :P


(... to be continued... )
Last edited by HaWe on 06 Jun 2012, 20:06, edited 4 times in total.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: RELEASED: 3RD PARTY NXC DRIVER SUITE V0.1

Post by mattallen37 »

What's wrong with John's official HT Touch mux support?

If you want the switch you're reading to be a number-indexed array, why not use array elements as the parameters? The way you set it up, you aren't even using an array (you're just number indexing a bit mask).

Also, how come you use "msk=(2<<muxport)/2;" instead of "msk = 1 << muxport;"? Is there any functional difference? I can't think of any, except execution time.

I must say, I am impressed that you programmed drivers for something :)
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: RELEASED: 3RD PARTY NXC DRIVER SUITE V0.2

Post by HaWe »

Arrays? I don't use arrays. Why should I use arrays?
I don't want to use arrays - I find my access to mux touchers much much easier:
access each single sensor by the nxt-port-number of the muxer and by its mux-port-number.
Any sensor at any muxer should be accessible by that scheme.

Also I don't find John's drivers if I search for them by pressing F1 or searching through the built-in help (also other people - at least in Germany - do neither).
Was there already a JH touch mux driver? I didn't find it so far.

msk = 1 << muxport is better, your right, my own formula was developed by trial and error.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: RELEASED: 3RD PARTY NXC DRIVER SUITE V0.2

Post by mattallen37 »

for (int i=0; i<4; ++i) {// that's why I prefer to use arrays...:

That's where I got the array idea from.

This is the official function > ReadSensorHTTouchMultiplexer
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: RELEASED: 3RD PARTY NXC DRIVER SUITE V0.2

Post by HaWe »

oh sh** that was part of a different piece of code of an older algorithm which I copied and pasted - forget it at this place...!
(I once had to access a set of variables counting through them in a loop, so then I would rather use an array than a couple of single values)

and - oh man:
mattallen37 wrote:What's wrong with John's official HT Touch mux support?
NXC API wrote:

Code: Select all

void ReadSensorHTTouchMultiplexer  ( const byte  port,  
  byte &  t1,    byte &  t2,    byte &  t3,    byte &  t4    )   [inline] 
Read HiTechnic touch multiplexer.

Read touch sensor values from the HiTechnic touch multiplexer device.

Parameters:
port The sensor port. See Input port constants.
t1 The value of touch sensor 1.
t2 The value of touch sensor 2.
t3 The value of touch sensor 3.
t4 The value of touch sensor 4.
I have to pass 4 sensor value variables by "reference" if I want to read just 1 sensor?
that's really hard stuff... ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest