View unanswered posts | View active topics It is currently Thu Jun 21, 2018 10:28 am






Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Way to Tell if SMUX is Not Responding? Battery Level? 
Author Message
Rookie

Joined: Mon Dec 15, 2014 12:46 am
Posts: 19
Post Way to Tell if SMUX is Not Responding? Battery Level?
Hello again,
Is there a way to tell whether or not the SMUX is connected? I have looked through the SMUX driver, but it is a little more complicated to me than the joystick driver....

Also, is there a way to read the battery level?

_________________
FTC 7104 - The Synergists


Sun Jan 11, 2015 8:12 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
I am not familiar with the inner working of the sensor mux. Xander is probably a better person to answer this but in theory you probably could try sending an I2C command to the MUX and see if returns an error. I don't know what is a valid MUX command you can see though.
Regarding the battery level of the MUX, unfortunately I don't think that's possible. I would love to be able to do it too since you can't tell if that battery is running low and needs replacement. So we tend to replace to a fresh battery on competition day.


Mon Jan 12, 2015 3:05 am
Profile
Rookie

Joined: Mon Dec 15, 2014 12:46 am
Posts: 19
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
Ok. I might play around with it, but it is not a high priority....

That's too bad...no battery info! :(

_________________
FTC 7104 - The Synergists


Tue Jan 13, 2015 12:54 am
Profile
Novice

Joined: Tue Dec 16, 2014 10:25 am
Posts: 81
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
Let me know because this would be useful to have at competitions where it could beep or something if you forgot to turn on the mux

_________________
Thanks!


Wed Jan 14, 2015 1:07 am
Profile
Novice

Joined: Tue Dec 16, 2014 10:25 am
Posts: 81
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
Ok so I was looking around and xanders driver has functions for low battery check and levels of battery. Do you guys know how to use them in a program?http://botbench.com/driversuite/group__htsmux.html#gadf42695ce182bb940e3cf966c82d4403

_________________
Thanks!


Wed Jan 14, 2015 1:13 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
akash329dsouza wrote:
Ok so I was looking around and xanders driver has functions for low battery check and levels of battery. Do you guys know how to use them in a program?http://botbench.com/driversuite/group__htsmux.html#gadf42695ce182bb940e3cf966c82d4403

All this info is actually extracted from Xander's source code. What made you think there is functionality to check for low battery? I don't see any.


Wed Jan 14, 2015 2:09 am
Profile
Novice

Joined: Tue Dec 16, 2014 10:25 am
Posts: 81
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
Well on that page it showed a function to check for low batteries. That is built into the drivers.

_________________
Thanks!


Wed Jan 14, 2015 9:03 am
Profile
Rookie

Joined: Mon Dec 15, 2014 12:46 am
Posts: 19
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
It actually is just a bool which means true or false. I was thinking of using one of those functions or bools, but I have to wait for electrical placement to be finalized and Saturday to write and test. I did write this to make sure that I can access the values of a bool, int. This will be the basis for MUX checking.

Code:
bool returnFalse()
{
   return true;
}

int valueRandom()
{
   return rand();
}

task main()
{
   clearDebugStream();
   if(returnFalse() == false)
   {
      writeDebugStreamLine("Returned FALSE");
   }
   else
   {
      writeDebugStreamLine("Returned TRUE");
   }

   if(valueRandom() > 5000)
   {
      writeDebugStreamLine("Returned Greater than 5000 at %d", valueRandom());
   }
   else
   {
      writeDebugStreamLine("Returned Less than 5000 at %d", valueRandom());
   }

}

_________________
FTC 7104 - The Synergists


Wed Jan 14, 2015 3:17 pm
Profile
Rookie

Joined: Tue Jan 13, 2015 10:48 pm
Posts: 23
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
This is the function to read the battery level:

Code:
bool HTSMUXreadPowerStatus(tSensors link);


It will return true if the battery level is low and false if it isn't.

To check if the SMUX is connected, use the following code that I just parsed together:
Code:
bool HTSMUXVerify(tSensors link){
memset(HTSMUX_I2CRequest, 0, sizeof(tByteArray));
HTSMUX_I2CRequest[0] = 2; //2 bytes in this message
HTSMUX_I2CRequest[1] = HTSMUX_I2C_ADDR;
HTSMUX_I2CRequest[2] = 0x10; //Sensor type address

writeI2C(link, HTSMUX_I2CRequest, HTSMUX_I2CReply, 8 /* Expected message return size*/);

//Blah Blah Blah check if it is the Sensor Mux
    return true;

return false;
}


I will send you some actual code instead of that pseudo code once I test it out for myself tomorrow, as Hi-Technic has not said what the sensor type field should contain.


Thu Jan 15, 2015 2:14 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
Ah, I stand corrected. The functions indeed exist. That's good to know.


Thu Jan 15, 2015 2:30 am
Profile
Rookie

Joined: Tue Jan 13, 2015 10:48 pm
Posts: 23
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
I tested checking code today and found its sensor type ID.

Use the following code to check if the SMUX is connected to the correct port.

Code:
#define HTSMUX_SENSORTYPE   0x10

bool HTSMUXVerifyType(tSensors link){
    memset(HTSMUX_I2CRequest, 0, sizeof(tByteArray));
    HTSMUX_I2CRequest[0] = 2;
    HTSMUX_I2CRequest[1] = HTSMUX_I2C_ADDR;
    HTSMUX_I2CRequest[2] = HTSMUX_SENSORTYPE;

    if(!writeI2C(link, HTSMUX_I2CRequest, HTSMUX_I2CReply, 8))
        return false;

    if((char)HTSMUX_I2CReply[0] == 'S' && (char)HTSMUX_I2CReply[1] == 'e' &&
       (char)HTSMUX_I2CReply[2] == 'n' && (char)HTSMUX_I2CReply[3] == 's' &&
       (char)HTSMUX_I2CReply[4] == 'r' && (char)HTSMUX_I2CReply[5] == 'M' &&
       (char)HTSMUX_I2CReply[6] == 'U' && (char)HTSMUX_I2CReply[7] == 'X')

        return true;
   
    return false;
}


Thu Jan 15, 2015 7:49 pm
Profile
Novice

Joined: Tue Dec 16, 2014 10:25 am
Posts: 81
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
Is that code complete? There isn't any {} for the if statements. Also could you give a example of using the fiction. Just want to make sure im setting it up right

_________________
Thanks!


Thu Jan 15, 2015 11:40 pm
Profile
Rookie

Joined: Tue Jan 13, 2015 10:48 pm
Posts: 23
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
Yes, the function is set up correctly.
Code:
#define HTSMUX_SENSORTYPE     0x10

Should be included at the beginning of your code, directly after your #pragma initializations.

An example usage with the sensor port name set as "SMUX" would be:
Code:
if(HTSMUXVerifyType(SMUX) == false){
     hogCPU();
     playSound(soundBeepBeep);
     displayString(3, "ERROR: SMUX not connected");
     sleep(1000);
     stopAllTasks();
}


There aren't any brackets for the if statements because if you are only using one line (function/command) that is related to an if function, the curly brackets are unnecessary; if your if statement contains two or more functions, use curly brackets ({}).


Fri Jan 16, 2015 12:26 am
Profile
Novice

Joined: Tue Dec 16, 2014 10:25 am
Posts: 81
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
How do you set the port name for the MUX? And thanks this is really helpful

_________________
Thanks!


Fri Jan 16, 2015 1:26 am
Profile
Rookie

Joined: Tue Jan 13, 2015 10:48 pm
Posts: 23
Post Re: Way to Tell if SMUX is Not Responding? Battery Level?
You would use the same name that you plug in to all of the other SMUX functions. It is the name that you use when you set up motors and sensors.
Code:
#pragma config(Sensor, S1,     SMUX,         sensorI2CCustom)


Fri Jan 16, 2015 1:37 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 17 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.