Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Autres questions


Index du Forum » Autres questions » Flash only maintains when holding key
Critical Hors ligne Membre Points: 47 Défis: 0 Message

Flash only maintains when holding key

Posté le 23/05/2025 20:35

I have been working on a game for an add-in for the fx-CG50 one section is that it flashes a custom status message (“GAME OVER!”) in the status area while preserving standard indicators like battery and input mode (“Math”). The flashing uses RTC tick polling to toggle the visibility of the message by altering status area flags via DefineStatusAreaFlags() and updating with DisplayStatusArea(). The add-in exits cleanly on pressing MENU.

However, the flashing only occurs while any keyboard key is physically held down. When no keys are pressed, the status message stops flashing and remains static.

Does anyone have any idea as to why this may happen any help appreciated


Lephenixnoir Hors ligne Administrateur Points: 25156 Défis: 174 Message

Citer : Posté le 23/05/2025 20:36 | #


Can you please provide a small example that showcases the issue? Do you call Bdisp_PutDisp_DD() every redraw?
Mon graphe (28 Janvier): (MPM ; serial gint ; (Rogue Life || HH2) ; PythonExtra ; ? ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Critical Hors ligne Membre Points: 47 Défis: 0 Message

Citer : Posté le 23/05/2025 21:29 | #


Hi

#include <fxcg/display.h>
#include <fxcg/rtc.h>
#include <fxcg/keyboard.h>

void main(void) {
    int flashState = 1;  
    int lastTick = RTC_GetTicks();
    int key;

    Bdisp_AllClr_VRAM();

    while (1) {
        GetKey(&key);
        if (key == KEY_CTRL_MENU) break;

        int currentTick = RTC_GetTicks();
        if (currentTick - lastTick >= 100) {  
            flashState = !flashState;
            lastTick = currentTick;

            char color1 = TEXT_COLOR_WHITE;
            char color2 = TEXT_COLOR_WHITE;

            int flags = SAF_BATTERY;
            if (flashState)
                flags |= SAF_SETUP_COMPLEX_MODE;

            DefineStatusAreaFlags(3, flags, &color1, &color2);
            DisplayStatusArea();
        }
    }
}


This is code for Real flashing in the status bar I was having difficulties reproducing a small bit of code which shows the similar affect of (GAME OVER!) for some reason however this shows the same affect the flashing only takes place when holding any button on the calc but does not flash if you don't hold a button down.
Lephenixnoir Hors ligne Administrateur Points: 25156 Défis: 174 Message

Citer : Posté le 23/05/2025 21:55 | #


Well that would be because of GetKey(). This function pauses the program until you press something. You can't have anything real-time if that function is in your loop, as it will pause your fun effects. Now if you press an arrow key GetKey() will repeat it, which means it will return once when you press it, and when you call GetKey() again at the next iteration of the loop without releasing the key it will return again after a delay. However even in this "favorable" case GetKey() still decides how long it takes for the repeat to count (125 ms I think?) so you're limited in speed (to 8 FPS).

The proper way to deal with this situation is to use a different function for key input, such as IsKeyDown().
Mon graphe (28 Janvier): (MPM ; serial gint ; (Rogue Life || HH2) ; PythonExtra ; ? ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Critical Hors ligne Membre Points: 47 Défis: 0 Message

Citer : Posté le 23/05/2025 23:00 | #


Do you know where I can find more about IsKeyDown(). as its not on PrizmSDK wiki
Lephenixnoir Hors ligne Administrateur Points: 25156 Défis: 174 Message

Citer : Posté le 23/05/2025 23:48 | #


Ah, it seems libfxcg doesn't have that particular function. Well you can use GetKeyWait_OS with no waiting or PRGM_GetKey_OS which is a bit more convenient but has a different keycode numbering. There is a variant called PRGM_GetKey which does mostly the same thing.
Mon graphe (28 Janvier): (MPM ; serial gint ; (Rogue Life || HH2) ; PythonExtra ; ? ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Critical Hors ligne Membre Points: 47 Défis: 0 Message

Citer : Posté le 31/05/2025 18:30 | #


I am having issues with this again as GetyKeyWait_OS interferes with text input is there a way to use IsKeyDown() ?
Lephenixnoir Hors ligne Administrateur Points: 25156 Défis: 174 Message

Citer : Posté le 01/06/2025 13:08 | #


Can you be more specific with the interference?
Mon graphe (28 Janvier): (MPM ; serial gint ; (Rogue Life || HH2) ; PythonExtra ; ? ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Critical Hors ligne Membre Points: 47 Défis: 0 Message

Citer : Posté le 01/06/2025 13:45 | #


#include <fxcg/display.h>
#include <fxcg/rtc.h>
#include <fxcg/keyboard.h>
#include <stdlib.h>  

#define KEYWAIT_HALTON_TIMERON 2
#define MENU_MATRIX_CODE 0x0409

void main(void) {
    int flashState = 1;  
    int lastTick = RTC_GetTicks();


    char *buffer = (char*)malloc(256);
    int start = 0;
    int cursor = 0;
    buffer[0] = '\0';

    Bdisp_AllClr_VRAM();
    DrawFrame(0);
    DisplayMBString((unsigned char*)buffer, start, cursor, 1, 1);
    Bdisp_PutDisp_DD();

    while (1) {
        int col = 0, row = 0;
        unsigned short keycode = 0;

        int result = GetKeyWait_OS(&col, &row, KEYWAIT_HALTON_TIMERON, 0, 1, &keycode);

        if (result == 1) {
            unsigned short matrixCode = (col << 8) | row;

            if (matrixCode == MENU_MATRIX_CODE) {
              
                break;
            }

            int key = (int)keycode;

            if (key && key < 30000) {
            
                cursor = EditMBStringChar((unsigned char*)buffer, 256, cursor, key);
            } else {
                
                EditMBStringCtrl((unsigned char*)buffer, 256, &start, &cursor, &key, 1, 1);
            }

            
            DisplayMBString((unsigned char*)buffer, start, cursor, 1, 1);
        }

        int currentTick = RTC_GetTicks();
        if (currentTick - lastTick >= 100) {
            flashState = !flashState;
            lastTick = currentTick;

            char color1 = TEXT_COLOR_WHITE;
            char color2 = TEXT_COLOR_WHITE;

            int flags = SAF_BATTERY;
            if (flashState)
                flags |= SAF_SETUP_COMPLEX_MODE;

            DefineStatusAreaFlags(3, flags, &color1, &color2);
            DisplayStatusArea();

            Bdisp_PutDisp_DD();
        }
    }

    free(buffer);
    Bdisp_AllClr_VRAM();
    Bdisp_PutDisp_DD();
}


Well I was assuming it does I should not have said that it does, Anyway as you can see this code is suppose to allow me to type and uses GetKeyWait_OS to keep Real flashing forever like you suggested to use and then using the Reading Input tutorial on the PrizmSDK I implemented basic key input (https://prizm.cemetech.net/Tutorials/Reading_Input/) however when typing nothing happens neither does the cursor flash.
Lephenixnoir Hors ligne Administrateur Points: 25156 Défis: 174 Message

Citer : Posté le 02/06/2025 12:24 | #


This looks fine to me from the outside... I'd like to run the program to test it. Any chance you can provide a full project folder with Makefile/etc?
Mon graphe (28 Janvier): (MPM ; serial gint ; (Rogue Life || HH2) ; PythonExtra ; ? ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Critical Hors ligne Membre Points: 47 Défis: 0 Message

Citer : Posté le 02/06/2025 17:02 | #


For this is all the code I used for testing what I did was just use the example project on PrizmSDK modified the default code with that and used the default Makefile that's given I did not touch it has they recommend not to. Then ran .\make by opening terminal for this folder which I am sure you know how to do.

LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2025 | Il y a 132 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd