π
<-
Chat plein-écran
[^]

Writing a Daemon/Task

C, C++, ASM...

Writing a Daemon/Task

Message non lude jsrk » 13 Mai 2014, 17:51

Hello everyboby,
I am new to this community and I apologize in advance for not posting this french but unfortunately I don't speak the language :(.

So I would like to write a daemon or task that's active in the background and waits for certain key combinations to perform certain actions. The usage of the calculator should continue to work unimpaired. I was wondering if something like:

Code: Tout sélectionner
while(true)
{
      if(isKeyPressed(KEY_NSPIRE_R) && isKeyPressed(KEY_NSPIRE_E))
      {
            resetHandheld();
            break;
      }
      sleep(500);
}


is possible at all. If it is not, is there anyway to register a program to be launched on certain hotkey combos/shortcuts?
Avatar de l’utilisateur
jsrk
Niveau 1: MD (Membre Débutant)
Niveau 1: MD (Membre Débutant)
Prochain niv.: 60%
 
Messages: 2
Inscription: 11 Mai 2014, 08:01
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: Writing a Daemon/Task

Message non lude Excale » 13 Mai 2014, 17:57

jsrk a écrit:Hello everyboby,
I am new to this community and I apologize in advance for not posting this french but unfortunately I don't speak the language :(.

English is not an issue (it is in fact way better to write in English than to attempt to use an automatic translator). :)

jsrk a écrit:So I would like to write a daemon or task that's active in the background and waits for certain key combinations to perform certain actions. The usage of the calculator should continue to work unimpaired. I was wondering if something like:

Code: Tout sélectionner
while(true)
{
      if(isKeyPressed(KEY_NSPIRE_R) && isKeyPressed(KEY_NSPIRE_E))
      {
            resetHandheld();
            break;
      }
      sleep(500);
}


is possible at all. If it is not, is there anyway to register a program to be launched on certain hotkey combos/shortcuts?

There are some ways to make a daemon, but this will clearly not work that way. A probably not too-hard way to do this would be to hook your program in the event loop or timer interrupt handler. See the ndless-hook "documentation" (search for HOOK_INSTALL in the source code).
Avatar de l’utilisateur
ExcaleAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 3.9%
 
Messages: 2955
Images: 3
Inscription: 10 Sep 2010, 00:00
Genre: Homme
Calculatrice(s):
MyCalcs profile

Re: Writing a Daemon/Task

Message non lude Lepzulnag » 13 Mai 2014, 18:01

I've never done that by myself, but Levak's nCapture installs a hook which waits the user to press CTRL+'.'
Looking at his code may be helpful.
Avatar de l’utilisateur
Lepzulnag
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Prochain niv.: 78.5%
 
Messages: 151
Inscription: 02 Aoû 2012, 21:15
Localisation: Bretagne
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile
Classe: M2 Maths

Re: Writing a Daemon/Task

Message non lude jsrk » 13 Mai 2014, 18:15

Thank you both for your help, I really appreciate it.
Avatar de l’utilisateur
jsrk
Niveau 1: MD (Membre Débutant)
Niveau 1: MD (Membre Débutant)
Prochain niv.: 60%
 
Messages: 2
Inscription: 11 Mai 2014, 08:01
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: Writing a Daemon/Task

Message non lude Levak » 13 Mai 2014, 18:27

The most elegant way is to use Nucleus tasks/timers (which is on what the Nspire is based on) which are made for that.
Obviously, those syscalls have to be found by yourself which is not an easy solution. I have the addresses for CX CAS 3.1 but not for others such as 3.6.
I was wondering Ndless integrating those syscalls but it appears it only includes file management one (or hackspire is not up to date).

Below is an old test I found on my HDD :
Code: Tout sélectionner
#include <os.h>
#include <libndls.h>

typedef void (*Timer_Callback)(void);

static unsigned TMS_Reset_Timer_addrs[] = {0x0, 0x0, 0x0, 0x10277740};
#define TMS_Reset_Timer SYSCALL_CUSTOM(TMS_Reset_Timer_addrs, void, void * /* timer */, Timer_Callback, int /* initial_time */, int /* reschedule_time */, int /* 4 = disable, 5 = enable */)
                                                                                                                                                                                                     
static unsigned TMS_Control_Timer_addrs[] = {0x0, 0x0, 0x0, 0x102776AC};
#define TMS_Control_Timer SYSCALL_CUSTOM(TMS_Control_Timer_addrs, void, void * /* timer */, int /* 4 = disable, 5 = enable */)
static unsigned TMS_Create_Timer_addrs[] = {0x0, 0x0, 0x0, 0x10277830};
#define TMS_Create_Timer SYSCALL_CUSTOM(TMS_Create_Timer_addrs, void, void * /* timer */, char * /* name */, Timer_Callback, int /* id */, int /* initial_timer */, int /* reschedule_time */, int /* 4 = disable, 5 = enable */)
static unsigned TMS_Delete_Timer_addrs[] = {0x0, 0x0, 0x0, 0x102777BC};
#define TMS_Delete_Timer SYSCALL_CUSTOM(TMS_Delete_Timer_addrs, void, void * /* timer */)

static unsigned NU_printf_addrs[] = {0x0, 0x0, 0x0, 0x10101FF8};
#define NU_printf SYSCALL_CUSTOM(NU_printf_addrs, int, char * /* format */, ...)

static int mtimer[0x64];

void timer_handler()
{
    NU_printf("Hello World\n");
    TMS_Reset_Timer(&mtimer, timer_handler, 100, 0, 5);
//    TMS_Control_Timer(&mtimer, 5);
//    TMS_Delete_Timer(&mtimer);
}

int main(int argc, char* argv[]) {
    if(argc < 1) return 0;

    TMS_Create_Timer(&mtimer, "1s", timer_handler, 0, 100, 0, 5);
    nl_set_resident();
    return;
}
Responsable design/graphique de TI-Planet
I do not get mad at people, I just want them to learn the way I learnt.
ImageTNOC [topic][DL]
nClock [topic][DL]
HideManager [topic][DL]
ZLock [topic][DL]
Theme Editor [topic][DL]
Mes programmes
Avatar de l’utilisateur
LevakAdmin
Niveau 14: CI (Calculateur de l'Infini)
Niveau 14: CI (Calculateur de l'Infini)
Prochain niv.: 98.9%
 
Messages: 6414
Images: 22
Inscription: 27 Nov 2008, 00:00
Localisation: 0x1AACC355
Genre: Homme
Calculatrice(s):
MyCalcs profile
Classe: BAC+5: Epita (ING3)


Retourner vers Native: Ndless, Linux, ...

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 6 invités

-
Rechercher
-
Social TI-Planet
-
Sujets à la une
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Offre de test des nouveautés de rentrée 2024 par Casio. Enseignant(e), reçois gratuitement 1 exemplaire, à ton choix, de la Graph Light ou bien de la Graph Math+
14€ remboursés par Casio sur l'achat de ta calculatrice Graph 35 d'ici le 31 Octobre 2024
10€ remboursés par Casio sur l'achat de ta calculatrice Graph 90+E d'ici le 31 Décembre 2024
10€ remboursés par Casio sur l'achat de ta calculatrice Graph 25 d'ici le 31 Décembre 2024
8€ remboursés par Casio sur l'achat de ta calculatrice Graph Math+ d'ici le 31 Octobre 2024
Reprise de ton ancienne fx-92 Collège ou Graph 25/35/90 à 3€ peu importe son état. Même non fonctionnelle et donc invendable, même ancienne Graph 35 non conforme aux programmes (pas de Python), même ancienne Graph 25/35 inutilisable aux examens (pas de mode examen) et donc invendable. Etiquette de retour fournie, pas de frais de port à payer.
3€ remboursés par Casio sur l'achat de ta calculatrice fx-92 Collège d'ici le 30 Septembre 2024
5€ de remise immédiate sur l'achat de ta calculatrice TI-83 Premium CE Edition Python chez les revendeurs partenaires
4€ de remise immédiate sur l'achat de ta calculatrice TI-82 Advanced Edition Python chez les revendeurs partenaires
3€ de remise immédiate sur l'achat de ta calculatrice TI-82 Advanced chez les revendeurs partenaires
Comparaisons des meilleurs prix pour acheter sa calculatrice !
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234567891011121314
-
Faire un don / Premium
Pour plus de concours, de lots, de tests, nous aider à payer le serveur et les domaines...
Faire un don
Découvrez les avantages d'un compte donateur !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partenaires et pub
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1477 utilisateurs:
>1461 invités
>11 membres
>5 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Autres sites intéressants
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)