0

I am trying to display a 128px * 128px image on Pebble, sent from Android over AppMessage.

In Android app, I have a BitmapFactory ARGB_8888 bmp, and I do:

byte pbi[] = new byte[16*128];      
for(int i = 0; i < 128; i++) {
    for(int j = 0; j < 128; j++) {
        if(bmp.getPixel(i, j) >= 0x7FFFFFFF) {
            pbi[i*16] |= 1 << (j % 8);        //set pixel (white)
        }
        pbi[i*16] &= ~(1 << (j % 8));         //explicitly set = 0 (black)
    }
}

PebbleDictionary data;
byte send[];
for (int k = 0; k < 128; k++){
    data = new PebbleDictionary();
    send = new byte[16];
    send = Arrays.copyOfRange(pbi, k*16, (k+1)*16-1);
    data.addBytes(KEY_IMG, send);
    data.addInt16(KEY_ROW, (byte)k);
    PebbleKit.sendDataToPebble(getApplicationContext(), PEBBLE_APP_UUID, data);
}

Pebble has:

static int transNum;
static uint8_t received[128][16] = {0};

static void in_received_handler(DictionaryIterator *iter, void *context) {
    Tuple *img_tuple = dict_find(iter, KEY_IMG);
    Tuple *row_tuple = dict_find(iter, KEY_ROW);
    if (img_tuple && row_tuple) {
        memcpy(img_data[(int)(row_tuple->value->cstring)], img_tuple->value->data, 16);
    }
}

Which should be displayed by:

static void window_load(Window *window) {
    static Window *window;
    static BitmapLayer *img_layer;
    static GBitmap img;

    static void window_load(Window *window) {
        L    img_layer = bitmap_layer_create( (GRect) {
        .origin = {8, 20},
        .size = {128, 128}
    });


    img = (GBitmap) {
        .addr = img_data,
        .bounds = GRect(8, 20, 128, 128),
        .row_size_bytes = 16,
    };

    bitmap_layer_set_bitmap(img_layer, &img);
    bitmap_layer_set_alignment(img_layer, GAlignCenter);
    layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(img_layer));
    display_no_img();    
}

But on window_load, I get the expected black square, but I can't figure how to make it load the received data.

Edit: It's hard for me to keep the code above updated, but it's pretty representative. I'm hoping someone can tell me what to do to make it load the received bytes. I thought the secret was in .addr = img_data, alas.. Thanks.

OJFord
  • 10,522
  • 8
  • 64
  • 98

1 Answers1

-1

You should take a look at the Pebble-faces example. It uses JavaScript but you could probably completely reuse the C part and just change the phone code.

sarfata
  • 4,625
  • 4
  • 28
  • 36
  • "you could probably completely reuse the C" - Pebble-faces uses JS! I looked at it before, but I can't use JS because I have to communicate with an app on the phone anyway, and don't believe you can do both. – OJFord Mar 08 '14 at 09:05
  • What I meant is that you are writing C for the Pebble side and you can completely re-use that. You only need to write the Android part from scratch. It still solves half your problem. – sarfata Mar 09 '14 at 06:04
  • I already have the Android side. It's just not updating the image on Pebble side. – OJFord Mar 09 '14 at 08:30