Skip to content

Commit

Permalink
update pebblejs/sdk/README
Browse files Browse the repository at this point in the history
  • Loading branch information
gitgud-software committed Jan 12, 2016
1 parent a13d324 commit ddde41d
Show file tree
Hide file tree
Showing 19 changed files with 190 additions and 69 deletions.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
The MIT License (MIT)

Copyright (C) 2014 Meiguro
Copyright (c) 2015 Gitgud Software

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
55 changes: 55 additions & 0 deletions doc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">

<title>Pebble.js</title>

<!-- Flatdoc -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src='http://rstacruz.github.io/flatdoc/v/0.8.1/legacy.js'></script>
<script src='http://rstacruz.github.io/flatdoc/v/0.8.1/flatdoc.js'></script>

<!-- Flatdoc theme -->
<link href='http://rstacruz.github.io/flatdoc/v/0.8.1/theme-white/style.css' rel='stylesheet'>
<script src='http://rstacruz.github.io/flatdoc/v/0.8.1/theme-white/script.js'></script>

<!-- Meta -->
<meta content="Pebble.js" property="og:title">
<meta content="A JavaScript framework for the Pebble smartwatch." name="description">

<!-- Initializer -->
<script>
Flatdoc.run({
fetcher: Flatdoc.github('pebble/pebblejs')
//fetcher: Flatdoc.file('README.md')
});
</script>
</head>
<body role='flatdoc' class="large-brief">

<div class='header'>
<div class='left'>
<h1>Pebble.js</h1>
<ul>
<li><a href='https://github.com/pebble/pebblejs'>View on GitHub</a></li>
<li><a href='https://github.com/pebble/pebblejs/issues'>Issues</a></li>
</ul>
</div>
<div class='right'>
<!-- GitHub buttons: see http://ghbtns.com -->
<iframe src="http://ghbtns.com/github-btn.html?user=pebble&amp;repo=pebblejs&amp;type=watch&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="110" height="20"></iframe>
</div>
</div>

<div class='content-root'>
<div class='menubar'>
<div class='menu section' role='flatdoc-menu'></div>
</div>
<div role='flatdoc-content' class='content'></div>
</div>

</body>
</html>
2 changes: 1 addition & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ Pebble.addEventListener('ready', function(e) {
window.moment = globalMoment;

// Load local file
require('app.js');
require('./app');
});
43 changes: 23 additions & 20 deletions src/js/ui/simply-pebble.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var struct = require('struct');
var util2 = require('util2');
var myutil = require('myutil');
var Platform = require('platform');
var Wakeup = require('wakeup');
var Timeline = require('timeline');
var Resource = require('ui/resource');
Expand Down Expand Up @@ -971,7 +972,7 @@ var PacketQueue = function() {
this._send = this.send.bind(this);
};

PacketQueue.prototype._maxPayloadSize = 2044 - 32;
PacketQueue.prototype._maxPayloadSize = (Platform.version() === 'aplite' ? 1024 : 2044) - 32;

PacketQueue.prototype.add = function(packet) {
var byteArray = toByteArray(packet);
Expand Down Expand Up @@ -1148,48 +1149,50 @@ SimplyPebble.accelConfig = function(def) {
};

SimplyPebble.voiceDictationStart = function(callback, enableConfirmation) {
// If there's a transcription in progress
if (SimplyPebble.dictationCallback) {
// Create the eror event
var e = {
if (Platform.version() === 'aplite') {
// If there is no microphone, call with an error event
callback({
'err': DictationSessionStatus[65], // noMicrophone
'failed': true,
'transcription': null,
});
return;
} else if (state.dictationCallback) {
// If there's a transcription in progress, call with an error event
callback({
'err': DictationSessionStatus[64], // dictationAlreadyInProgress
'failed': true,
'transcription': null,
};

// Invoke the callback and return
callback(e);
});
return;
}

// Set the callback and send the packet
state.dictationCallback = callback;
SimplyPebble.sendPacket(VoiceDictationStartPacket.enableConfirmation(enableConfirmation));
}
};

SimplyPebble.voiceDictationStop = function() {
// Send the message
// Send the message and delete the callback
SimplyPebble.sendPacket(VoiceDictationStopPacket);

// Clear the callback variable
state.dictationCallback = null;
}
delete state.dictationCallback;
};

SimplyPebble.onVoiceData = function(packet) {
if (!state.dictationCallback) {
// Something bad happened
console.log("No callback specified for dictation session");
} else {
var e = {
'err': DictationSessionStatus[packet.status()],
'failed': packet.status() != 0,
'err': DictationSessionStatus[packet.status()],
'failed': packet.status() !== 0,
'transcription': packet.transcription(),
};
// invoke and clear the callback
// Invoke and delete the callback
state.dictationCallback(e);
state.dictationCallback = null;
delete state.dictationCallback;
}
}
};

SimplyPebble.menuClear = function() {
SimplyPebble.sendPacket(MenuClearPacket);
Expand Down
3 changes: 1 addition & 2 deletions src/js/ui/voice.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Voice.dictate = function(type, confirm, callback) {
default:
console.log('Unsupported type passed to Voice.dictate');
}

};

module.exports = Voice;
module.exports = Voice;
4 changes: 2 additions & 2 deletions src/simply/simply_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
#include "util/list1.h"
#include "util/math.h"
#include "util/memory.h"
#include "util/platform.h"
#include "util/string.h"

#include <pebble.h>

#define SEND_DELAY_MS 10

static const size_t APP_MSG_SIZE_INBOUND = 2044;

static const size_t APP_MSG_SIZE_INBOUND = IF_APLITE_ELSE(1024, 2044);
static const size_t APP_MSG_SIZE_OUTBOUND = 1024;

typedef enum VibeType VibeType;
Expand Down
1 change: 1 addition & 0 deletions src/simply/simply_res.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static void destroy_image(SimplyRes *self, SimplyImage *image) {
list1_remove(&self->images, &image->node);
gbitmap_destroy(image->bitmap);
free(image->palette);
free(image);
}

static void destroy_font(SimplyRes *self, SimplyFont *font) {
Expand Down
18 changes: 3 additions & 15 deletions src/simply/simply_voice.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <pebble.h>

#if !defined(PBL_PLATFORM_APLITE)
typedef struct VoiceStartPacket VoiceStartPacket;

struct __attribute__((__packed__)) VoiceStartPacket {
Expand Down Expand Up @@ -33,7 +34,7 @@ static bool send_voice_data(int status, char *transcription) {
// Handle success case
size_t transcription_length = strlen(transcription) + 1;
size_t packet_length = sizeof(VoiceDataPacket) + transcription_length;

uint8_t buffer[packet_length];
VoiceDataPacket *packet = (VoiceDataPacket *)buffer;
*packet = (VoiceDataPacket) {
Expand All @@ -47,7 +48,6 @@ static bool send_voice_data(int status, char *transcription) {
return simply_msg_send_packet(&packet->packet);
}

#ifndef PBL_SDK_2
// Define a callback for the dictation session
static void dictation_session_callback(DictationSession *session, DictationSessionStatus status,
char *transcription, void *context) {
Expand All @@ -56,20 +56,13 @@ static void dictation_session_callback(DictationSession *session, DictationSessi
// Send the result
send_voice_data(status, transcription);
}
#endif

static void timer_callback_start_dictation(void *data) {
dictation_session_start(s_voice->session);
}


static void handle_voice_start_packet(Simply *simply, Packet *data) {
#ifdef PBL_SDK_2
// send an immediate reply if we don't support voice
// Status 65 = NoMicrophone
send_voice_data(65, "");
#else

// Send an immediate response if there's already a dictation session in progress
// Status 64 = SessionAlreadyInProgress
if (s_voice->in_progress) {
Expand All @@ -84,16 +77,12 @@ static void handle_voice_start_packet(Simply *simply, Packet *data) {
VoiceStartPacket *packet = (VoiceStartPacket*) data;
dictation_session_enable_confirmation(s_voice->session, packet->enable_confirmation);
s_voice->timer = app_timer_register(0, timer_callback_start_dictation, NULL);
#endif
}

static void handle_voice_stop_packet(Simply *simply, Packet *data) {
// Do nothing for SDK 2
#ifndef PBL_SDK_2
// Stop the session and clear the in_progress flag
dictation_session_stop(s_voice->session);
s_voice->in_progress = false;
#endif
}

bool simply_voice_handle_packet(Simply *simply, Packet *packet) {
Expand All @@ -120,9 +109,7 @@ SimplyVoice *simply_voice_create(Simply *simply) {
.in_progress = false,
};

#ifndef PBL_SDK_2
self->session = dictation_session_create(SIMPLY_VOICE_BUFFER_LENGTH, dictation_session_callback, NULL);
#endif

s_voice = self;
return self;
Expand All @@ -140,3 +127,4 @@ void simply_voice_destroy(SimplyVoice *self) {
bool simply_voice_dictation_in_progress() {
return s_voice->in_progress;
}
#endif
13 changes: 13 additions & 0 deletions src/simply/simply_voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,22 @@ struct SimplyVoice {
bool in_progress;
};

#if defined(PBL_PLATFORM_APLITE)

#define simply_voice_create(simply) NULL
#define simply_voice_destroy(self)

#define simply_voice_handle_packet(simply, packet) (false)

#define simply_voice_dictation_in_progress() (false)

#else

SimplyVoice *simply_voice_create(Simply *simply);
void simply_voice_destroy(SimplyVoice *self);

bool simply_voice_handle_packet(Simply *simply, Packet *packet);

bool simply_voice_dictation_in_progress();

#endif
38 changes: 23 additions & 15 deletions src/simply/simply_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ void simply_window_set_action_bar_background_color(SimplyWindow *self, GColor8 b
}

void simply_window_action_bar_clear(SimplyWindow *self) {
if (!self->action_bar_layer) {
return;
}

simply_window_set_action_bar(self, false);

for (ButtonId button = BUTTON_ID_UP; button <= BUTTON_ID_DOWN; ++button) {
Expand Down Expand Up @@ -274,12 +278,18 @@ void simply_window_load(SimplyWindow *self) {
GRect frame = layer_get_frame(window_layer);
frame.origin = GPointZero;

ScrollLayer *scroll_layer = self->scroll_layer = scroll_layer_create(frame);
Layer *scroll_base_layer = scroll_layer_get_layer(scroll_layer);
self->scroll_layer = scroll_layer_create(frame);
Layer *scroll_base_layer = scroll_layer_get_layer(self->scroll_layer);
layer_add_child(window_layer, scroll_base_layer);

scroll_layer_set_context(scroll_layer, self);
scroll_layer_set_shadow_hidden(scroll_layer, true);
scroll_layer_set_context(self->scroll_layer, self);
scroll_layer_set_shadow_hidden(self->scroll_layer, true);

self->status_bar_layer = status_bar_layer_create();
status_bar_layer_remove_from_window(self->window, self->status_bar_layer);

self->action_bar_layer = action_bar_layer_create();
action_bar_layer_set_context(self->action_bar_layer, self);

window_set_click_config_provider_with_context(window, click_config_provider, self);
simply_window_set_action_bar(self, self->is_action_bar);
Expand Down Expand Up @@ -320,6 +330,15 @@ void simply_window_unload(SimplyWindow *self) {

scroll_layer_destroy(self->scroll_layer);
self->scroll_layer = NULL;

action_bar_layer_destroy(self->action_bar_layer);
self->action_bar_layer = NULL;

status_bar_layer_destroy(self->status_bar_layer);
self->status_bar_layer = NULL;

window_destroy(self->window);
self->window = NULL;
}

static void handle_window_props_packet(Simply *simply, Packet *data) {
Expand Down Expand Up @@ -382,14 +401,9 @@ SimplyWindow *simply_window_init(SimplyWindow *self, Simply *simply) {

simply_window_preload(self);

self->status_bar_layer = status_bar_layer_create();
status_bar_layer_remove_from_window(self->window, self->status_bar_layer);
self->is_status_bar = false;
self->is_fullscreen = true;

ActionBarLayer *action_bar_layer = self->action_bar_layer = action_bar_layer_create();
action_bar_layer_set_context(action_bar_layer, self);

return self;
}

Expand All @@ -398,12 +412,6 @@ void simply_window_deinit(SimplyWindow *self) {
return;
}

action_bar_layer_destroy(self->action_bar_layer);
self->action_bar_layer = NULL;

status_bar_layer_destroy(self->status_bar_layer);
self->status_bar_layer = NULL;

window_destroy(self->window);
self->window = NULL;
}
3 changes: 2 additions & 1 deletion src/simply/simply_window_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "util/math.h"
#include "util/none.h"
#include "util/platform.h"
#include "util/sdk.h"

#include <pebble.h>
Expand Down Expand Up @@ -104,7 +105,7 @@ static void show_window_sdk_3(SimplyWindowStack *self, SimplyWindow *window, boo

window_stack_push(window->window, animated);

if (animated) {
if (IF_APLITE_ELSE(true, animated)) {
window_stack_remove(prev_window, animated);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define GColor8Clear (GColor8){.argb=GColorClearARGB8}
#define GColor8ClearWhite (GColor8){.argb=0x3F}

#ifndef PBL_COLOR
#ifndef PBL_SDK_3

static inline GColor gcolor8_get(GColor8 color) {
switch (color.argb) {
Expand Down
Loading

0 comments on commit ddde41d

Please sign in to comment.