element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Raspberry Pi XBOX 360 RF Module c# Programming Questions ??? please read again!! rewritten.
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 5 replies
  • Answers 1 answer
  • Subscribers 674 subscribers
  • Views 1113 views
  • Users 0 members are here
  • 360
  • xbox
  • controller
  • raspi
  • programming
  • c#
  • rf
Related

Raspberry Pi XBOX 360 RF Module c# Programming Questions ??? please read again!! rewritten.

CrazyFace
CrazyFace over 10 years ago

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.

  • Sign in to reply
  • Cancel
Parents
  • shabaz
    0 shabaz over 10 years ago

    Your questions [and title] were so specific (xbox 360, RF module and some ring of lights? controller) that anyone without these items would have a hard time following what you meant.

    There may be 50+ views, but probably none of the 50 viewers have this combination of products, so it helps to make the question(s) easier to follow for those who won't have your

    specific scenario/hardware.

    .

    I don't have an xbox or RF module or ring of light controller, and I've read Q4 multiple times and I'm still unsure what you mean.

     

    I *think* (not sure) that your Question 4 is saying, that you have a file which contains some content, and you wish your program (which is written in C or C++) to place that content (or a part of it) into a variable.

     

    That being the case, you can achieve your aim using the file I/O tutorial here. It will allow you to read a line into a string. Then, you can perform manipulation using the string library and perform

    a string compare (strcmp) for your condition checks.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Reply
  • shabaz
    0 shabaz over 10 years ago

    Your questions [and title] were so specific (xbox 360, RF module and some ring of lights? controller) that anyone without these items would have a hard time following what you meant.

    There may be 50+ views, but probably none of the 50 viewers have this combination of products, so it helps to make the question(s) easier to follow for those who won't have your

    specific scenario/hardware.

    .

    I don't have an xbox or RF module or ring of light controller, and I've read Q4 multiple times and I'm still unsure what you mean.

     

    I *think* (not sure) that your Question 4 is saying, that you have a file which contains some content, and you wish your program (which is written in C or C++) to place that content (or a part of it) into a variable.

     

    That being the case, you can achieve your aim using the file I/O tutorial here. It will allow you to read a line into a string. Then, you can perform manipulation using the string library and perform

    a string compare (strcmp) for your condition checks.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube