A) Principe :
B) Code HTML :
Utilisation du framework Slate :
- créez la page de configuration (exemple)
- modifiez le fichier de config .js afin de récupérer les valeurs (exemple)
C) Code Pebble :
Fichier configcolor.js :
//////////////////
// Color Config //
//////////////////
var dict = {};
//-- Init
Pebble.addEventListener('ready',
function(e) {
console.log('JavaScript app ready and running!');
}
);
//-- Affichage de la page de config.
Pebble.addEventListener("showConfiguration", function() {
console.log("Configuration Color v1.0 !");
Pebble.openURL('http://andropebble.byethost33.com/AATEST/index.html');
});
//-- Page config fermée
Pebble.addEventListener("webviewclosed", function(e) {
var configData = JSON.parse(decodeURIComponent(e.response));
console.log('Configuration page returned: ' + JSON.stringify(configData));
//--Object {bgColor: "0xFFFF00", timeColor: "0x00FFAA"}
dict = {};
var backgroundColor = configData.bgColor;
var timeColor = configData.timeColor;
dict.ColorBckR = parseInt(backgroundColor.substring(2, 4), 16);
dict.ColorBckG = parseInt(backgroundColor.substring(4, 6), 16);
dict.ColorBckB = parseInt(backgroundColor.substring(6), 16);
dict.ColorPolR = parseInt(timeColor.substring(2, 4), 16);
dict.ColorPolG = parseInt(timeColor.substring(4, 6), 16);
dict.ColorPolB = parseInt(timeColor.substring(6), 16);
// Send to watchapp
Pebble.sendAppMessage(dict, function() {
console.log('Send successful: ' + JSON.stringify(dict));
}, function() {
console.log('Send failed!');
});
});
Récupération dans le code c:
Déclaration des clefs
//-- Color management
#define KEY_BGCOLOR_R 3
#define KEY_BGCOLOR_G 4
#define KEY_BGCOLOR_B 5
#define KEY_TIME_COLOR_R 6
#define KEY_TIME_COLOR_G 7
#define KEY_TIME_COLOR_B 8
static GColor bg_color, time_color;
static void in_received_handler(DictionaryIterator *received, void *context) {
Tuple *tuple;
#if PBL_SDK_3
int red, green, blue;
Tuple *color_red_t, *color_green_t, *color_blue_t;
// Background color?
color_red_t = dict_find(received, KEY_BGCOLOR_R);
color_green_t = dict_find(received, KEY_BGCOLOR_G);
color_blue_t = dict_find(received, KEY_BGCOLOR_B);
if(color_red_t && color_green_t && color_blue_t) {
// Apply the color if available
red = color_red_t->value->int32;
green = color_green_t->value->int32;
blue = color_blue_t->value->int32;
// Persist values
persist_write_int(KEY_BGCOLOR_R, red);
persist_write_int(KEY_BGCOLOR_G, green);
persist_write_int(KEY_BGCOLOR_B, blue);
bg_color = GColorFromRGB(red, green, blue);
text_layer_set_background_color(time_layer, COLOR_FALLBACK(bg_color, GColorBlack));
window_set_background_color(s_window, COLOR_FALLBACK(bg_color, GColorBlack));
text_layer_set_background_color(date_layer, COLOR_FALLBACK(bg_color, GColorBlack));
text_layer_set_background_color(fete_layer, COLOR_FALLBACK(bg_color, GColorBlack));
}
#endif
Références :
Framework Slate : https://github.com/pebble/slate
https://github.com/AlbertYau/pebble-classy-colors-config
https://github.com/AlbertYau/pebble-classy-colors/blob/master/src/script.js