Je n'ai pu tester que sur ma V-200, je n'ai aucune idée si ça fonctionne sur les autres.
J'espère que ça pourra servir au débutants en C (TI)
Moi-même étant débutant je ne suis pas certains si les types de variables sont les mieux choisis.
Je sais que j'aurais pu stocker les heures,minutes et secondes dans un tableau, ça aurait fait une source plus courte, mais je suis paresseux et c'est plus lisible comme ceci.
// C Source File
// Created 2004-09-15; 17:36:09
#include <tigcclib.h>
#define DateAndTime_Get _rom_call(void,(unsigned short*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,unsigned short*),5F3)
// Main Function
void _main(void)
{
LCD_BUFFER ecran; //buffer écran
unsigned char length[3] = {10,20,40}; //longueur des aiguilles (heure,minute,seconde)
unsigned char nb[9]; //petit buffer
unsigned short year, month, day, hour, minute, second; //variables pour enregistrer les données
unsigned short hour2=123,minute2=123,second2=123; //dernières données affichées
unsigned short i; //variable de contrôle
float angle; //pour y stocker l'angle
LCD_save(ecran); //sauvegarde l'écran
ClrScr(); //efface l'écran
DrawClipEllipse(LCD_WIDTH/2,LCD_HEIGHT/2,50,50,(&(SCR_RECT){{0, 0, LCD_WIDTH, LCD_HEIGHT}}),A_NORMAL); //dessine le contour
FontSetSys(F_6x8); //taille de police: 6x8 (Fixed)
for (i=0; i<12; i++) // boucle pour afficher les heures
{
angle = fdiv(i,12) * (2*PI) - (PI/3); //calcul de l'angle, -(PI/3) pour minuit en haut
sprintf(nb,"%i",i+1); //entier->string
if (i>=9) //si nombre à 2 digits, centrer
DrawStr((LCD_WIDTH/2)+40*cos(angle)-6,(LCD_HEIGHT/2)+40*sin(angle)-2,nb,A_NORMAL);
else
DrawStr((LCD_WIDTH/2)+40*cos(angle)-3,(LCD_HEIGHT/2)+40*sin(angle)-2,nb,A_NORMAL);
}
FontSetSys(F_8x10); //taille de police: 8x10 (Fixed)
DrawStr(2,2,"Par Julien C.",A_NORMAL); //moi :P
while (!kbhit()) //tant qu'aucune touche n'est appuyée
{
DateAndTime_Get(&year, &month, &day, &hour, &minute, &second); //stocke les données
if (hour2 != hour) //si l'heure a changé
{
angle = fdiv(hour2 % 12,12) * (2*PI) - (PI/2); //calcul de l'angle
if (hour2 != 123)
DrawLine((LCD_WIDTH/2),(LCD_HEIGHT/2),(LCD_WIDTH/2)+length[0]*cos(angle),(LCD_HEIGHT/2)+length[0]*sin(angle),A_XOR);
//Efface l'aiguille précédente
hour2 = hour; //actualise l'heure
angle = fdiv(hour % 12,12) * (2*PI) - (PI/2); //recalcul de l'angle
DrawLine((LCD_WIDTH/2),(LCD_HEIGHT/2),(LCD_WIDTH/2)+length[0]*cos(angle),(LCD_HEIGHT/2)+length[0]*sin(angle),A_XOR);
//XOR pour ne pas effacer en dessous
}
if (minute2 != minute) //même chose pour les minutes
{
angle = fdiv(minute2,60) * (2*PI) - (PI/2);
if (minute2 != 123)
DrawLine((LCD_WIDTH/2),(LCD_HEIGHT/2),(LCD_WIDTH/2)+length[1]*cos(angle),(LCD_HEIGHT/2)+length[1]*sin(angle),A_XOR);
minute2 = minute;
angle = fdiv(minute,60) * (2*PI) - (PI/2);
DrawLine((LCD_WIDTH/2),(LCD_HEIGHT/2),(LCD_WIDTH/2)+length[1]*cos(angle),(LCD_HEIGHT/2)+length[1]*sin(angle),A_XOR);
}
if (second2 != second) //même chose pour les secondes
{
angle = fdiv(second2,60) * (2*PI) - (PI/2);
if (second2 != 123)
DrawLine((LCD_WIDTH/2),(LCD_HEIGHT/2),(LCD_WIDTH/2)+length[2]*cos(angle),(LCD_HEIGHT/2)+length[2]*sin(angle),A_XOR);
second2 = second;
angle = fdiv(second,60) * (2*PI) - (PI/2);
DrawLine((LCD_WIDTH/2),(LCD_HEIGHT/2),(LCD_WIDTH/2)+length[2]*cos(angle),(LCD_HEIGHT/2)+length[2]*sin(angle),A_XOR);
}
idle();
}
ngetchx(); //vide le buffer du clavier
LCD_restore(ecran); //restaure l'écran
ST_helpMsg("Par Julien C."); //affiche le message dans la statusline
}
Screenshot:
