Skip to content

Commit

Permalink
Add simply msg set image
Browse files Browse the repository at this point in the history
  • Loading branch information
Meiguro committed May 12, 2014
1 parent e9f5988 commit 95a7549
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/js/simply.pebble.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ var commands = [{
name: 'title',
}, {
name: 'subtitle',
}, {
name: 'image',
}],
}, {
name: 'getMenuItem',
Expand Down Expand Up @@ -146,6 +148,17 @@ var commands = [{
}, {
name: 'item',
}],
}, {
name: 'image',
params: [{
name: 'id',
}, {
name: 'width',
}, {
name: 'height',
}, {
name: 'pixels',
}],
}];

var commandMap = {};
Expand Down Expand Up @@ -455,6 +468,14 @@ SimplyPebble.menuItem = function(sectionIndex, itemIndex, itemDef) {
SimplyPebble.sendPacket(packet);
};

SimplyPebble.image = function(id, gbitmap) {
var command = commandMap.image;
var packetDef = util2.copy(gbitmap);
packetDef.id = id;
var packet = makePacket(command, packetDef);
SimplyPebble.sendPacket(packet);
};

var readInt = function(packet, width, pos, signed) {
var value = 0;
pos = pos || 0;
Expand Down
30 changes: 30 additions & 0 deletions src/simply_msg.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "simply_msg.h"

#include "simply_accel.h"
#include "simply_res.h"
#include "simply_menu.h"
#include "simply_ui.h"

Expand Down Expand Up @@ -35,6 +36,7 @@ enum SimplyACmd {
SimplyACmd_menuSelect,
SimplyACmd_menuLongSelect,
SimplyACmd_menuExit,
SimplyACmd_image,
};

typedef enum VibeType VibeType;
Expand Down Expand Up @@ -192,16 +194,41 @@ static void handle_set_menu_item(DictionaryIterator *iter, Simply *simply) {
if ((tuple = dict_find(iter, 4))) {
subtitle = tuple->value->cstring;
}
if ((tuple = dict_find(iter, 5))) {
image = tuple->value->uint32;
}
SimplyMenuItem *item = malloc(sizeof(*item));
*item = (SimplyMenuItem) {
.section = section_index,
.index = row,
.title = strdup2(title),
.subtitle = strdup2(subtitle),
.image = image,
};
simply_menu_add_item(simply->menu, item);
}

static void handle_set_image(DictionaryIterator *iter, Simply *simply) {
Tuple *tuple;
uint32_t id = 0;
int16_t width = 0;
int16_t height = 0;
uint32_t *pixels = NULL;
if ((tuple = dict_find(iter, 1))) {
id = tuple->value->uint32;
}
if ((tuple = dict_find(iter, 2))) {
width = tuple->value->int16;
}
if ((tuple = dict_find(iter, 3))) {
height = tuple->value->int16;
}
if ((tuple = dict_find(iter, 4))) {
pixels = (uint32_t*) tuple->value->data;
}
simply_res_add_image(simply->res, id, width, height, pixels);
}

static void received_callback(DictionaryIterator *iter, void *context) {
Tuple *tuple = dict_find(iter, 0);
if (!tuple) {
Expand Down Expand Up @@ -245,6 +272,9 @@ static void received_callback(DictionaryIterator *iter, void *context) {
case SimplyACmd_setMenuItem:
handle_set_menu_item(iter, context);
break;
case SimplyACmd_image:
handle_set_image(iter, context);
break;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/simplyjs.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "simplyjs.h"

#include "simply_accel.h"
#include "simply_res.h"
#include "simply_splash.h"
#include "simply_menu.h"
#include "simply_ui.h"
Expand All @@ -11,6 +12,7 @@
static Simply *init(void) {
Simply *simply = malloc(sizeof(*simply));
simply->accel = simply_accel_create();
simply->res = simply_res_create();
simply->splash = simply_splash_create(simply);
simply->menu = simply_menu_create();
simply->ui = simply_ui_create(simply);
Expand All @@ -26,6 +28,7 @@ static void deinit(Simply *simply) {
simply_msg_deinit();
simply_ui_destroy(simply->ui);
simply_menu_destroy(simply->menu);
simply_res_destroy(simply->res);
simply_accel_destroy(simply->accel);
}

Expand Down
1 change: 1 addition & 0 deletions src/simplyjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ typedef struct Simply Simply;

struct Simply {
struct SimplyAccel *accel;
struct SimplyRes *res;
struct SimplySplash *splash;
struct SimplyMenu *menu;
struct SimplyUi *ui;
Expand Down
5 changes: 3 additions & 2 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def build(ctx):
ctx.load('pebble_sdk')

ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'),
cflags=['-Wno-type-limits',
'-Wno-address'],
cflags=['-Wno-address',
'-Wno-type-limits',
'-Wno-missing-field-initializers'],
target='pebble-app.elf')

js_target = ctx.concat_javascript(js=ctx.path.ant_glob('src/js/**/*.js'))
Expand Down

0 comments on commit 95a7549

Please sign in to comment.