A) Clonage de source :
Attention la sauvegarde en ZIP puis restauration en renommant peut poser des difficultés. Il est préférable de faire un copier/coller des sources…
B) En « c » :
Affichage d’un nombre :
Il est nécessaire de stocker la conversion dans un buffer :
int i;
static char buf[] = "123456";
snprintf(buf, sizeof(buf), "%d", i);
text_layer_set_text(&countLayer, buf);
Concaténation de chaîne de caractères :
static char buf[] = "123456"; //-- En C uniquement des tableaux de char
snprintf(buf, sizeof(buf), "%d", reason);
char cMsg[80];
strcpy (cMsg, "Output_failed ");
strcat (cMsg,buf);
APP_LOG(APP_LOG_LEVEL_DEBUG, cMsg);
Gestion du Case Switch :
switch ( <variable> ) {
case this-value:
Code to execute if <variable> == this-value
break;
case that-value:
Code to execute if <variable> == that-value
break;
...
default:
Code to execute if <variable> does not equal the value following any of the cases
break;
}
B) SDK :
Attention à l’ordre du code : toute fonction doit être définie avant son appel !
Affichages Layers (cf. page layers)
Vibration :
vibes_short_pulse(); //-- Une vibration
vibes_double_pulse(); //-- Deux vibrations
vibes_long_pulse(); //-- Longue vibration
vibes_cancel(); //-- Annulation de la vibration
//--- Vibrations personnalisées :
//-- Pattern: ON for 200ms, OFF for 100ms, ON for 400ms:
static const uint32_t const segments[] = { 200, 100, 400 };
VibePattern pat = {
.durations = segments,
.num_segments = ARRAY_LENGTH(segments),
};
vibes_enqueue_custom_pattern(pat);
Gestion des boutons :
Il convient de définir pour chaque bouton l’action à effectuer dans un handler :
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(text_layer, "Select");
send_int(KEY_BUTTON_EVENT, BUTTON_EVENT_SELECT);
}
static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(text_layer, "Up");
send_int(KEY_BUTTON_EVENT, BUTTON_EVENT_UP);
}
static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
text_layer_set_text(text_layer, "Down");
send_int(KEY_BUTTON_EVENT, BUTTON_EVENT_DOWN);
}
Puis de préciser ses handlers dans la fonction click_config_provider
static void click_config_provider(void *context) {
window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
window_single_click_subscribe(BUTTON_ID_UP, up_click_handler);
window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
window_long_click_subscribe(BUTTON_ID_SELECT, 500, NULL, long_click_handler);}
et ne pas oublier de définir le provider dans la fonction init
static void init(void) {
window = window_create();
window_set_click_config_provider(window, click_config_provider);
…
Votre commentaire