I don't know if this was asked before, but I'm trying to make something with c for the ti 84 plus ce calculator. I'm learning how to get key input from user. I see that there are two things, os_getcsc and keypadc. I looked at the example program for keypadc.h it looked confusing. But the os_getcsc seemed to function like getKey→K in basic. If anyone is familiar with using c toolchain, can you give me example code? Ex: I want to wait until user types key, then check what key it is. I think I can do that with

Code:

while(!(os_getcsc() = key)){
    //some stuff
}
If you plan on using os_GetCSC, I think this would a good way of both setting a variable and waiting for input, since os_GetCSC returns null when no key is pressed.

Code:

do {
    key = os_GetCSC();
} while(!key);


The keypadc example would likely be longer, but keypadc is overall better for receiving user input ( faster, more versatile, etc.). I recommend reading this page for help learning to use it. Smile
I can't remember where I heard this or if I accidently found it in some benchmarks, but os_GetCSC() is really really slow. The docs Zaalane linked mentioned it too, and you should definitely stick to using the bits inside the kb_Data[] array. It's not confusing, just mildly annoying since some of the registers aren't actually used (there's 8 unused bits and therefore a whole 8 bit integer that could be used, but that's just me being nitpicky). The way it works is that the keypbad controller reads the keys as individual bits, and you can read them with bitwise logic and the kb_Data pointer. The only reason it's an array is because there's more than 8 keys citation needed and therefore a value bigger than your average integer. Take this:
Code:
do{
     kb_Scan();
} while (!(kb_Data[6] & kb_Clear))
[list]
-kb_Scan() updates the key states
-kb_Data[6] reads 48 bits from the start
-kb_Clear is actually a defined variable for (1<<6), which when used with "&" means it reads the sixth bit, which is the one the clear key is updating.

If you can't remember which keys are in which group, just check the docs or in keypad.h, a proper text editor can also show you where the define is, like "Go to definition" in VScode. Just don't use os functions in general, there's always better code than what TI wrote out there.
Quote:
If you can't remember which keys are in which group, just check the docs or in keypad.h, a proper text editor can also show you where the define is, like "Go to definition" in VScode.

You can also either use kb_IsDown, which handles the group for you, or something like this:

Code:
#define kb_GetGroup(x) ((x) >> 8)
kb_GetGroup(kb_KeyClear) /* 6 */
Ah thanks.

Code:

do{
     kb_Scan();
} while (!(kb_Data[6] & kb_Clear))


seems to be what I'm looking for. I understand how to read the kb_Data. I just wanted a better example and someone to confirm that os functions are indeed slower (I had suspicions, but too lazy to benchmark), which you guys did provide.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
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 vote in polls in this forum

 

Advertisement