Hi, and thanks for taking the time to look at this,
I guess after 50+ views before this edit and not even a "your doing it all wrong", I needed to go about this differently, So let me start with, I am not looking for somebody to do all the work for me where is the satisfaction in that, I would just like some advice/direction/guidance and I apologize if my original post did not give that impression. so here goes, I basically found some code that allows me to sync my xbox 360 wireless controllers to my raspberry pi whilst using a recycled RF module from a xbox 360 as a receiver , this code works great if I only want to sync 1 controller but so far when I needed to sync another I've had to stop the program and restart it, where ideally I want to be able to sync as many controllers as I want in 1 session, So I started to look at the code to see if I could work out how to make it reset automatically, Now this isn't my first attempt at at doing this I tried a few years ago for my pc but failed to even sync a controller and left it alone, until I got my RPi and started again this time being able to sync a controller and use it, but apart from the sync reset issue I decided I wanted to Include a few other things I had acquired in my research into the code, so that's what I'm trying to do some of it seems straight forward in theory but not having any sort of programming background I'm looking for some advice and guidance on how to proceed, I tried to do it alone just reading tutorials and forums for clues and answers but got lost as to which way was best for me to get the results I wanted, and not actually realizing this was all in c# and trying to search for how to do it in c++ hasn't helped me.
The original code can be found here: http://pastebin.com/AiAiWYdh
Q1) Solved - my mistake this does reset itself you just have to give it enough time.
Q2) Relates to Q1 in a way, but this time it will be to add a pin that when the button is pressed, it sends the command to Remotely shuts down controllers, what I want to know is if just adding this as a while loop after the sync process will work or do I need to set up pins specifically for this command to work ? until I can get the pins to reset, I see this loop being useless if I have to sync a controller during use, but will work fine I if sync isn't used with the code the way it is now and my while loop added, am i right in thinking this?
| while(1) { | ||
| // Wait For Event in power btn | ||
| wait_for(pwr_pin, 0); | ||
| send_cmd(ctrl_off); | ||
| } |
obviously I will add these lines of code in where necessary::
#define pwr_pin 0 // => physical pin 11 - bcm pin 17 ==>RF Module pin 5.
unsigned char ctrl_off[10] = {0,0,0,0,0,0,1,0,0,1}; //Shuts Down Controllers.
pinMode(pwr_pin, INPUT);
I guess my real question is will be adding my button really be as easy as it looks?
Q3) Is just a branch off from Q2, I want to be able to issue the command to console telling the RPi to start safe shut down 10secs after the ctrl_off cmd, will adding these to lines into the above while loop work?
delay(1000);
std::system("sudo shutdown -h now")
Q4) Now here is where I really over complicated things for myself, whilst using my controller I noticed that the Ring Of Light leds on the RF Module did not illuminate but somehow xboxdrv was issuing the command to light up the correct ROL leds on the controllers, I had the commands to illuminate the leds but no way to automatically identify which controller/s were connected and issue the commands, so after hours of rummaging around files on my RPi and a few tests I realized that xboxdrv was storing info in /etc on a file called rc.local, I became aware that parts of the info changed automatically when more controllers were added but if there were no controllers that line would be left empty, so I got it into my head that variables was the route forward, I knew what info was getting changed so I could create commands based on that info.
This is the first part of the line that it stores in the file which is all I think I need to identify the how many controllers are connected:
xboxdrv --daemon --id 0
my question is what is the best way for me to extract that info into a int, array or string etc,and save it as ctrl_id and then use in a boolean condition to match it up with these commands:
unsigned char ply1_led[10] = {0,0,1,0,1,0,0,1,0,0}; //Illuminates RF Module Controller 1 LED ==> Lower Left
unsigned char ply2_led[10] = {0,0,1,0,1,0,0,0,0,1}; //Illuminates RF Module Controller 2 LED ==> Upper Left
unsigned char ply3_led[10] = {0,0,1,0,1,0,0,0,1,0}; //Illuminates RF Module Controller 3 LED ==> Upper Right
unsigned char ply4_led[10] = {0,0,1,0,1,0,1,0,0,0}; //Illuminates RF Module Controller 4 LED ==> Lower Right
unsigned char ctrl_err[10} = {0,0,1,1,0,1,0,0,0,1}; //Illuminates RF Module 4 Flashing RED LED'S ==> No Controller Warning.
which would be triggered by these these:
ctrl_one = {xboxdrv --daemon --id 0 };
ctrl_two = {xboxdrv --daemon --id 1 };
ctrl_three = {xboxdrv --daemon --id 2 };
ctrl_four = {xboxdrv --daemon --id 3 };
or something similar.
in this:
// check the boolean condition
if( ctlr_id == ctrl_one )
{
// if condition is true
send_cmd(ply1_cmd);
}
else if( ctrl_id == ctrl_two )
{
// if else if condition is true
send_cmd(ply1_cmd,ply2_cmd);
}
else if( ctlr_id == ctrl_three )
{
// if else if condition is true
send_cmd(ply1_cmd,ply2_cmd,ply3_cmd);
}
else if( ctrl_id == ctrl_four )
{
// if else if condition is true
send_cmd(ply1_cmd,ply2_cmd,ply3_cmd,ply4_cmd);
}
else
{
// if none of the conditions is true
send_cmd(ctrl_err);
}
And if possible how would I go about getting it to repeat this process regularly for changes so it can adjust accordingly, some advice in this area would be greatly appreciated, not even sure I'm heading in the right direction, or if it can be done, all seemed so easy in my head but the theory has me stumped.
Many thanks for taking the time to read this, especially if you read it the first time.
Mark.
Message was edited by: Mark Nicholson, to reword and better explain my questions, I rewrote my whole post after getting views but no reply and realizing my questions needed to be asked in a better way.




