Search Results

Search found 4 results on 1 pages for 'aquanar'.

Page 1/1 | 1 

  • How is joystick axis information formatted from a USB Joystick?

    - by aquanar
    I actually just have a rather small question, but I have had the HARDEST time finding information about it. For the application I am programming for, there will be a 3-axis joystick being connected via USB to a Windows XP computer, and it is being handled by directx. That information will then be sent elsewhere to an embedded controller. I don't need to know too much of the intricacies of how directx handles it, but I want to know, how is the data for the axes formatted? Nearest I can tell, most joysticks nowadays have 12 bits of resolution, so is the data output as a 12-bit 2's compliment number? And after that, is it represented as a signed 16-bit integer when it is captured from directx? I'd like to know this so I know how I will work with the data at the embedded platform side, such as how to format the packets sending data to the embedded side, as well ashow to use the information once it is on the embedded side.

    Read the article

  • How can multiple variables be passed to a function cleanly in C?

    - by aquanar
    I am working on an embedded system that has different output capabilities (digital out, serial, analog, etc). I am trying to figure out a clean way to pass many of the variables that will control those functions. I don't need to pass ALL of them too often, but I was hoping to have a function that would read the input data (in this case from a TCP network), and then parse the data (IE, the 3rd byte contains the states of 8 of the digital outputs (according to which bit in that byte is high or low)), and put that into a variable where I can then use elsewhere in the program. I wanted that function to be separate from the main() function, but to do so would require passing pointers to some 20 or so variables that it would be writing to. I know I could make the variables global, but I am trying to make it easier to debug by making it obvious when a function is allowed to edit that variable, by passing it to the function. My best idea was a struct, and just pass a pointer to it, but wasn't sure if there was a more efficient way, especially since there is only really 1 function that would need to access all of them at once, while most others only require parts of the information that will be stored in this bunch of state variables. So anyway, is there a clean way to send many variables between functions at once that need to be edited?

    Read the article

  • How do you return a string from a function correctly in Dynamic C?

    - by aquanar
    I have a program I am trying to debug, but Dynamic C apparently treats strings differently than normal C does (well, character arrays, anyway). I have a function that I made to make an 8 character long (well, 10 to include the \0 ) string of 0s and 1s to show me the contents of an 8-bit char variable. (IE, I give it the number 13, it returns the string "0001101\0" ) When I use the code below, it prints out !{happy face] 6 times (well, the second one is the happy face alone for some reason), each return comes back as 0xDEAE or "!\x02. I thought it would dereference it and return the appropriate string, but it appears to just be sending the pointer and attempting to parse it. This may seem silly, but my experience was actually in C++ and Java, so going back to C brings up a few issues that were dealt with in later programming languages that I'm not entirely sure how to deal with (like the lack of string variables). How could I fix this code, or how would be a better way to do what I am trying to do (I thought maybe sending in a pointer to a character array and working on it from the function might work, but I thought I should ask to see if maybe I'm just trying to reinvent the wheel). Currently I have it set up like this: this is an excerpt from the main() display[0] = '\0'; for(i=0;i<6;i++) { sprintf(s, "%s ", *char_to_bits(buffer[i])); strcat(display, s); } DispStr(8,5, display); and this is the offending function: char *char_to_bits(char x) { char bits[16]; strcpy(bits,"00000000\0"); if (x & 0x01) bits[7]='1'; if (x & 0x02) bits[6]='1'; if (x & 0x04) bits[5]='1'; if (x & 0x08) bits[4]='1'; if (x & 0x10) bits[3]='1'; if (x & 0x20) bits[2]='1'; if (x & 0x40) bits[1]='1'; if (x & 0x80) bits[0]='1'; return bits; } and just for the sake of completion, the other function is used to output to the stdio window at a specific location: void DispStr(int x, int y, char *s) { x += 0x20; y += 0x20; printf ("\x1B=%c%c%s", x, y, s); }

    Read the article

  • Calculating with a variable outside of its bounds in C

    - by aquanar
    If I make a calculation with a variable where an intermediate part of the calculation goes higher then the bounds of that variable type, is there any hazard that some platforms may not like? This is an example of what I'm asking: int a, b; a=30000; b=(a*32000)/32767; I have compiled this, and it does give the correct answer of 29297 (well, within truncating error, anyway). But the part that worries me is that 30,000*32,000 = 960,000,000, which is a 30-bit number, and thus cannot be stored in a 16-bit int. The end result is well within the bounds of an int, but I was expecting that whatever working part of memory would have the same size allocated as the largest source variables did, so an overflow error would occur. This is just a small example to show my problem, I am trying to avoid using floating points by making the fraction be a fraction of the max amount able to be stored in that variable (in this case, a signed integer, so 32767 on the positive side), because the embedded system I'm using I believe does not have an FPU. So how do most processors handle calculations out of the bounds of the source and destination variables?

    Read the article

1