Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 107 users online: 9 members, 71 guests and 27 bots. Members: Ashbad, critor, geekboy1011, HOMER-16, Link, tifreak8x, zeldaking. Bots: Spinn3r (1), Magpie Crawler (4), VoilaBot (2), Yahoo! Slurp (1), Googlebot (18), MSN/Bing (1).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
|
| Author |
Message |
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55736 Location: Earth, Sol, Milky Way
|
Posted: 19 Apr 2012 10:21:35 am Post subject: |
|
|
second is an integer, PrintXY expects a pointer to character (a string). You're creating a segfault. You have to use something like itoa to turn the number into a string. Pro-tip: When you see that reboot screen, just press [MENU]! No reboot required. _________________
 |
|
| Back to top |
|
|
AHelper

LONG LIVE COMICTECH

Joined: 30 Jan 2011 Posts: 1657 Location: Aufhelperstan, Utopian Republic
|
Posted: 19 Apr 2012 10:26:10 am Post subject: |
|
|
Code: while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
PrintXY(1, 1, second, 0, COLOR_BLACK);
GetKey(&key);
}
Should be... Code: while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
GetKey(&key);
}
Why the strcpy? The first two characters of the string must be non-zero garbage characters (but they might have hidden uses). itoa :: IntegerTOArray and is defined in CONVERT_syscalls.h _________________ °ᴥ° Get Lucky
<BrandonW> "You don't even want to know what TI Connect does when it's just detecting your calculator...It ACTUALLY ERASES THE SWAP SECTOR on every communication attempt...EVERY SINGLE ATTEMPT...Yes, TI Connect will kill your calculator..What do I have to do to get your attention?!....Such a bloated protocol." |
|
| Back to top |
|
|
flyingfisch

Super-Expert

Joined: 02 Feb 2012 Posts: 893 Location: Akron, OH
|
Posted: 19 Apr 2012 10:26:12 am Post subject: |
|
|
| KermMartian wrote: | | second is an integer, PrintXY expects a pointer to character (a string). You're creating a segfault. You have to use something like itoa to turn the number into a string. Pro-tip: When you see that reboot screen, just press [MENU]! No reboot required. |
Thank you for the tip!
One problem: itoa is included in stdlib.h, but prizmSDK doesn't use that. so is there a PrizmSDK-compatible function that converts integers to strings?
EDIT: never mind, ahelper ninja'd  _________________

 

Last edited by flyingfisch on 19 Apr 2012 10:31:01 am; edited 2 times in total |
|
| Back to top |
|
|
AHelper

LONG LIVE COMICTECH

Joined: 30 Jan 2011 Posts: 1657 Location: Aufhelperstan, Utopian Republic
|
Posted: 19 Apr 2012 10:29:27 am Post subject: |
|
|
ninja'd
Hope that helps. _________________ °ᴥ° Get Lucky
<BrandonW> "You don't even want to know what TI Connect does when it's just detecting your calculator...It ACTUALLY ERASES THE SWAP SECTOR on every communication attempt...EVERY SINGLE ATTEMPT...Yes, TI Connect will kill your calculator..What do I have to do to get your attention?!....Such a bloated protocol." |
|
| Back to top |
|
|
flyingfisch

Super-Expert

Joined: 02 Feb 2012 Posts: 893 Location: Akron, OH
|
Posted: 19 Apr 2012 10:31:10 am Post subject: |
|
|
I still get a reboot screen with this code:
Code: #include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int main(void) {
int key;
int hour, minute, second, ms;
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, second, 0, COLOR_BLACK);
GetKey(&key);
}
return;
}
_________________

 
 |
|
| Back to top |
|
|
AHelper

LONG LIVE COMICTECH

Joined: 30 Jan 2011 Posts: 1657 Location: Aufhelperstan, Utopian Republic
|
Posted: 19 Apr 2012 10:32:42 am Post subject: |
|
|
Code: while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
GetKey(&key);
}
You missed the change in PrintXY(1, 1, buffer, 0, COLOR_BLACK); _________________ °ᴥ° Get Lucky
<BrandonW> "You don't even want to know what TI Connect does when it's just detecting your calculator...It ACTUALLY ERASES THE SWAP SECTOR on every communication attempt...EVERY SINGLE ATTEMPT...Yes, TI Connect will kill your calculator..What do I have to do to get your attention?!....Such a bloated protocol." |
|
| Back to top |
|
|
flyingfisch

Super-Expert

Joined: 02 Feb 2012 Posts: 893 Location: Akron, OH
|
Posted: 19 Apr 2012 10:36:46 am Post subject: |
|
|
Ok, fixed.
Question: why do the numbers only refresh when I press a button other than [menu]? _________________

 
 |
|
| Back to top |
|
|
AHelper

LONG LIVE COMICTECH

Joined: 30 Jan 2011 Posts: 1657 Location: Aufhelperstan, Utopian Republic
|
Posted: 19 Apr 2012 10:38:57 am Post subject: |
|
|
GetKey is a blocking function. Look at the prizm wiki for how using PRGM_GetKey, which is nonblocking _________________ °ᴥ° Get Lucky
<BrandonW> "You don't even want to know what TI Connect does when it's just detecting your calculator...It ACTUALLY ERASES THE SWAP SECTOR on every communication attempt...EVERY SINGLE ATTEMPT...Yes, TI Connect will kill your calculator..What do I have to do to get your attention?!....Such a bloated protocol." |
|
| Back to top |
|
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55736 Location: Earth, Sol, Milky Way
|
|
| Back to top |
|
|
flyingfisch

Super-Expert

Joined: 02 Feb 2012 Posts: 893 Location: Akron, OH
|
Posted: 19 Apr 2012 10:50:31 am Post subject: |
|
|
Ok, using this code freezes my calc at the menu screen...
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int PRGRM_Getkey(void);
int main(void) {
int key;
int hour, minute, second, ms;
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
PRGM_GetKey(&key);
switch(key) {
case KEY_PRGM_MENU:
break;
}
}
return;
}
int PRGM_GetKey(void) {
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
WHY?!!! _________________

 

Last edited by flyingfisch on 19 Apr 2012 11:05:48 am; edited 1 time in total |
|
| Back to top |
|
|
AHelper

LONG LIVE COMICTECH

Joined: 30 Jan 2011 Posts: 1657 Location: Aufhelperstan, Utopian Republic
|
|
| Back to top |
|
|
flyingfisch

Super-Expert

Joined: 02 Feb 2012 Posts: 893 Location: Akron, OH
|
Posted: 19 Apr 2012 12:13:03 pm Post subject: |
|
|
OK, I found out is was an incorrect prototype. And I think I am using PRGRM_GetKey incorrectly. If you guys could help me, that would be great
My code:
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int PRGM_GetKey(void);
int main(void) {
int key;
int hour, minute, second, ms;
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
PRGM_GetKey() = key;
switch(key) {
case KEY_PRGM_MENU:
break;
}
}
return 0;
}
int PRGM_GetKey(void) {
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
My error:
Code:
flyingfisch@flyingfisch-Office-Computer:~/Desktop/PrizmSDK-0.3/projects/chess-timer$ make
/usr/local/cross/bin/sh3eb-elf-gcc -MMD -MP -MF /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/build/chess-timer.d -Os -Wall -mb -m4a-nofpu -mhitachi -nostdlib -I/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/build -I/home/flyingfisch/Desktop/PrizmSDK-0.3/include -std=c99 -c /home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c -o chess-timer.o
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c: In function 'main':
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:19:3: warning: pointer targets in passing argument 1 of 'RTC_GetTime' differ in signedness [-Wpointer-sign]
/home/flyingfisch/Desktop/PrizmSDK-0.3/include/RTC_syscalls.h:4:6: note: expected 'unsigned int *' but argument is of type 'int *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:19:3: warning: pointer targets in passing argument 2 of 'RTC_GetTime' differ in signedness [-Wpointer-sign]
/home/flyingfisch/Desktop/PrizmSDK-0.3/include/RTC_syscalls.h:4:6: note: expected 'unsigned int *' but argument is of type 'int *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:19:3: warning: pointer targets in passing argument 3 of 'RTC_GetTime' differ in signedness [-Wpointer-sign]
/home/flyingfisch/Desktop/PrizmSDK-0.3/include/RTC_syscalls.h:4:6: note: expected 'unsigned int *' but argument is of type 'int *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:19:3: warning: pointer targets in passing argument 4 of 'RTC_GetTime' differ in signedness [-Wpointer-sign]
/home/flyingfisch/Desktop/PrizmSDK-0.3/include/RTC_syscalls.h:4:6: note: expected 'unsigned int *' but argument is of type 'int *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:21:3: warning: implicit declaration of function 'strcpy' [-Wimplicit-function-declaration]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:21:3: warning: incompatible implicit declaration of built-in function 'strcpy' [enabled by default]
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:22:3: warning: pointer targets in passing argument 2 of 'itoa' differ in signedness [-Wpointer-sign]
/home/flyingfisch/Desktop/PrizmSDK-0.3/include/CONVERT_syscalls.h:6:6: note: expected 'unsigned char *' but argument is of type 'char *'
/home/flyingfisch/Desktop/PrizmSDK-0.3/projects/chess-timer/src/chess-timer.c:24:17: error: lvalue required as left operand of assignment
make[1]: *** [chess-timer.o] Error 1
make: *** [build] Error 2
EDIT:
Ok, I changed my code:
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int PRGM_GetKey(void);
int main(void) {
int key;
int hour, minute, second, ms;
while (1) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
key = PRGM_GetKey();
switch(key) {
case KEY_PRGM_MENU:
break;
}
}
return 0;
}
int PRGM_GetKey(void) {
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
but what happens is I get the pink and white loading symbol inthe corner of the main menu and I cannot get out of it. I thought that
Code:
KEY_PRGM_MENU:
break;
would end the program when I pressed [MENU], but apparently it doesn't? _________________

 
 |
|
| Back to top |
|
|
Eiyeron

Member

Joined: 12 Dec 2011 Posts: 158
|
Posted: 19 Apr 2012 12:59:34 pm Post subject: |
|
|
PRGM_GetKey() = key;
Should be key= PRGM_GetKey() _________________
  |
|
| Back to top |
|
|
flyingfisch

Super-Expert

Joined: 02 Feb 2012 Posts: 893 Location: Akron, OH
|
Posted: 19 Apr 2012 01:00:18 pm Post subject: |
|
|
| Eiyeron wrote: | PRGM_GetKey() = key;
Should be key= PRGM_GetKey() |
Yes I know, look at my edited code  _________________

 
 |
|
| Back to top |
|
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55736 Location: Earth, Sol, Milky Way
|
Posted: 19 Apr 2012 01:29:27 pm Post subject: |
|
|
I don't think you think break means what it actually means. All that break does is break out of the switch/case statement to continue running code directly after the closing brace } closing the brace-pair that began at switch() {. _________________
 |
|
| Back to top |
|
|
flyingfisch

Super-Expert

Joined: 02 Feb 2012 Posts: 893 Location: Akron, OH
|
Posted: 19 Apr 2012 01:32:32 pm Post subject: |
|
|
| KermMartian wrote: | | I don't think you think break means what it actually means. All that break does is break out of the switch/case statement to continue running code directly after the closing brace } closing the brace-pair that began at switch() {. |
Yes, eiyeron helped me figure that out. Now here is my code:
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include <display_syscalls.h>
#include <display.h>
#include <keyboard.hpp>
#include <color.h>
#include <RTC_syscalls.h>
#include <CONVERT_syscalls.h>
int PRGM_GetKey(void);
int main(void) {
int key;
int hour, minute, second, ms;
int done = 0;
while (!done) {
RTC_GetTime(&hour, &minute, &second, &ms);
char buffer[10];
strcpy(buffer," ");
itoa(second, buffer+2);
PrintXY(1, 1, buffer, 0, COLOR_BLACK);
Bdisp_PutDisp_DD;
key = PRGM_GetKey();
if (key == KEY_PRGM_MENU) {
done = 1;
}
}
return 0;
}
int PRGM_GetKey(void) {
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
It doesn't display anything though. _________________

 
 |
|
| Back to top |
|
|
Tari

Systems Integrator

Joined: 03 Jul 2006 Posts: 2106 Location: Always-winter, Michigan
|
|
| Back to top |
|
|
Ashbad

... I think redheaded girls are kind of cool

Joined: 01 Dec 2010 Posts: 2417 Location: Stomp Stomp Stomp, The Idiot Convention
|
Posted: 19 Apr 2012 02:46:14 pm Post subject: |
|
|
In addition to what Tari said, I have just a nitpicky thing: param 4 of PrintXY you have as '0', you should try using the actual definition, TEXT_MODE_NORMAL. And for param 5, you have "COLOR_BLACK", which you got luck on and is the same as "TEXT_COLOR_BLACK", however for the other colors if they start with "TEXT_COLOR" you should use them only with PrintXY's 5th argument, as they're 3 bit color defines; the ones that start with only "COLOR" are 16 bit defines, and besides "COLOR_BLACK" none of them will work for PrintXY. _________________ -Ashbad |
|
| Back to top |
|
|
flyingfisch

Super-Expert

Joined: 02 Feb 2012 Posts: 893 Location: Akron, OH
|
Posted: 20 Apr 2012 01:46:48 pm Post subject: |
|
|
| Ashbad wrote: | | In addition to what Tari said, I have just a nitpicky thing: param 4 of PrintXY you have as '0', you should try using the actual definition, TEXT_MODE_NORMAL. And for param 5, you have "COLOR_BLACK", which you got luck on and is the same as "TEXT_COLOR_BLACK", however for the other colors if they start with "TEXT_COLOR" you should use them only with PrintXY's 5th argument, as they're 3 bit color defines; the ones that start with only "COLOR" are 16 bit defines, and besides "COLOR_BLACK" none of them will work for PrintXY. |
OK, thank you for telling me that. I didn't know there was a difference.
EDIT:
OK, i got all my code fixed, now I have another question.
The program displays the numbers 0-9, 16-25, 32-41, 48-57, 64-69, 80-90. Why doesn't it display the numbers 1-60?
And what does RTC_GetTicks() do? _________________

 
 |
|
| Back to top |
|
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55736 Location: Earth, Sol, Milky Way
|
Posted: 20 Apr 2012 03:09:22 pm Post subject: |
|
|
RTC_GetTicks() returns the value of the tick timer, which goes up by 128 ticks every second. It's a good way to make delays (or bits of code) last a precise amount of wall-clock time without guessing. It's also robust to things like overclocking. _________________
 |
|
| Back to top |
|
|
|
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
|
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
|
© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.051299 seconds.
|