Commit 0c2cbc50 authored by Douglas6's avatar Douglas6

add username and password

parent 28b77933
{
"appKeys": {
"MSG_KEY_ARTIST": 102,
"MSG_KEY_CMD": 0,
"MSG_KEY_CMD_DATA": 1,
"MSG_KEY_VOLUME": 100,
"MSG_KEY_TITLE": 101,
"MSG_KEY_ARTIST": 102,
"MSG_KEY_MUTED": 104,
"MSG_KEY_PLAY_STATE": 103,
"MSG_KEY_MUTED": 104
"MSG_KEY_TITLE": 101,
"MSG_KEY_VOLUME": 100
},
"capabilities": [
"configurable"
......@@ -17,134 +17,134 @@
"resources": {
"media": [
{
"file": "images/pics.png",
"name": "ICON_PICS",
"file": "images/ff.png",
"name": "ICON_FF",
"type": "png"
},
{
"file": "images/info.png",
"name": "ICON_INFO",
"file": "images/rev.png",
"name": "ICON_REV",
"type": "png"
},
{
"file": "images/weather.png",
"name": "ICON_WEATHER",
"file": "images/rockodi.png",
"menuIcon": true,
"name": "ICON_ROCKODI",
"type": "png"
},
{
"file": "images/video.png",
"name": "ICON_VIDEO",
"file": "images/play.png",
"name": "ICON_PLAY",
"type": "png"
},
{
"file": "images/home.png",
"name": "ICON_HOME",
"file": "images/down.png",
"name": "ICON_DOWN",
"type": "png"
},
{
"file": "images/full.png",
"name": "ICON_FULL",
"file": "images/up.png",
"name": "ICON_UP",
"type": "png"
},
{
"file": "images/goto.png",
"name": "ICON_GOTO",
"file": "images/check.png",
"name": "ICON_CHECK",
"type": "png"
},
{
"file": "images/list.png",
"name": "ICON_LIST",
"file": "images/cursor_down.png",
"name": "ICON_CURSOR_DOWN",
"type": "png"
},
{
"file": "images/button.png",
"name": "ICON_BUTTON",
"file": "images/cursor_up.png",
"name": "ICON_CURSOR_UP",
"type": "png"
},
{
"file": "images/vol_up.png",
"name": "ICON_VOL_UP",
"file": "images/pause.png",
"name": "ICON_PAUSE",
"type": "png"
},
{
"file": "images/vol_dn.png",
"name": "ICON_VOL_DN",
"file": "images/speaker.png",
"name": "ICON_SPEAKER",
"type": "png"
},
{
"file": "images/power.png",
"name": "ICON_POWER",
"file": "images/addons.png",
"name": "ICON_ADDONS",
"type": "png"
},
{
"file": "images/player.png",
"name": "ICON_PLAYER",
"file": "images/remote.png",
"name": "ICON_REMOTE",
"type": "png"
},
{
"file": "images/remote.png",
"name": "ICON_REMOTE",
"file": "images/player.png",
"name": "ICON_PLAYER",
"type": "png"
},
{
"file": "images/addons.png",
"name": "ICON_ADDONS",
"file": "images/power.png",
"name": "ICON_POWER",
"type": "png"
},
{
"file": "images/speaker.png",
"name": "ICON_SPEAKER",
"file": "images/vol_dn.png",
"name": "ICON_VOL_DN",
"type": "png"
},
{
"file": "images/pause.png",
"name": "ICON_PAUSE",
"file": "images/vol_up.png",
"name": "ICON_VOL_UP",
"type": "png"
},
{
"file": "images/cursor_up.png",
"name": "ICON_CURSOR_UP",
"file": "images/button.png",
"name": "ICON_BUTTON",
"type": "png"
},
{
"file": "images/cursor_down.png",
"name": "ICON_CURSOR_DOWN",
"file": "images/list.png",
"name": "ICON_LIST",
"type": "png"
},
{
"file": "images/check.png",
"name": "ICON_CHECK",
"file": "images/goto.png",
"name": "ICON_GOTO",
"type": "png"
},
{
"file": "images/up.png",
"name": "ICON_UP",
"file": "images/full.png",
"name": "ICON_FULL",
"type": "png"
},
{
"file": "images/down.png",
"name": "ICON_DOWN",
"file": "images/home.png",
"name": "ICON_HOME",
"type": "png"
},
{
"file": "images/play.png",
"name": "ICON_PLAY",
"file": "images/video.png",
"name": "ICON_VIDEO",
"type": "png"
},
{
"file": "images/rockodi.png",
"menuIcon": true,
"name": "ICON_ROCKODI",
"file": "images/weather.png",
"name": "ICON_WEATHER",
"type": "png"
},
{
"file": "images/rev.png",
"name": "ICON_REV",
"file": "images/info.png",
"name": "ICON_INFO",
"type": "png"
},
{
"file": "images/ff.png",
"name": "ICON_FF",
"file": "images/pics.png",
"name": "ICON_PICS",
"type": "png"
}
]
......
......@@ -61,7 +61,6 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context)
t = dict_read_next(iterator);
}
int items_size = dict_write_end(&items_iter);
DEBUG("Size of the written buffer is %d bytes.", items_size);
load_menu();
}
......
......@@ -70,11 +70,19 @@ static int16_t menu_get_header_height_cb(MenuLayer *menu_layer, uint16_t section
return 0;
}
static int16_t menu_get_separator_height_cb(MenuLayer *menu_layer, MenuIndex *cell_index, void *data) {
return 0;
}
static void menu_draw_row_cb(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) {
// graphics_context_set_fill_color(ctx, GColorBlack);
BasicMenuModel *model = (BasicMenuModel*) data;
GRect bounds = layer_get_frame(cell_layer);
GBitmap *icon = model->items[cell_index->row]->icon;
graphics_context_set_fill_color(ctx, GColorWhite);
graphics_fill_rect(ctx, GRect(0, 0, bounds.size.w, bounds.size.h), 12, GCornersAll);
graphics_context_set_fill_color(ctx, GColorBlack);
graphics_fill_rect(ctx, GRect(1, 1, bounds.size.w - 2, bounds.size.h - 2), 12, GCornersAll);
int offset = 4;
if (icon != NULL) {
......@@ -100,6 +108,7 @@ BasicMenuLayer* basic_menu_layer_create(GRect rect, BasicMenuModel* model) {
.draw_header = menu_draw_header_cb,
.draw_row = menu_draw_row_cb,
.select_click = menu_select_cb,
.get_separator_height = menu_get_separator_height_cb,
});
return layer;
......
......@@ -26,7 +26,7 @@ void outbox_send(char* send_cmd){
DictionaryIterator *iter;
app_message_outbox_begin(&iter);
Tuplet value = TupletCString(MSG_KEY_BUTTON_CODE, send_cmd);
Tuplet value = TupletCString(MSG_KEY_CMD, send_cmd);
dict_write_tuplet(iter, &value);
dict_write_end(iter);
......@@ -37,9 +37,9 @@ void outbox_send_with_data(char* send_cmd, char* send_data){
DictionaryIterator *iter;
app_message_outbox_begin(&iter);
Tuplet code = TupletCString(MSG_KEY_BUTTON_CODE, send_cmd);
Tuplet code = TupletCString(MSG_KEY_CMD, send_cmd);
dict_write_tuplet(iter, &code);
Tuplet data = TupletCString(MSG_KEY_BUTTON_DATA, send_data);
Tuplet data = TupletCString(MSG_KEY_CMD_DATA, send_data);
dict_write_tuplet(iter, &data);
dict_write_end(iter);
......
......@@ -19,8 +19,8 @@
// THE SOFTWARE.
//
#pragma once
#define MSG_KEY_BUTTON_CODE 0
#define MSG_KEY_BUTTON_DATA 1
#define MSG_KEY_CMD 0
#define MSG_KEY_CMD_DATA 1
#define MSG_KEY_VOLUME 100
#define MSG_KEY_TITLE 101
#define MSG_KEY_ARTIST 102
......
// Copyright (c) 2015 Douglas Otwell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#include <pebble.h>
#include "config.h"
#include "common.h"
static Window *s_window;
static void initialize_ui(void) {
s_window = window_create();
window_set_fullscreen(s_window, false);
window_set_background_color(s_window, GColorBlack);
Layer *window_layer = window_get_root_layer(s_window);
GRect bounds = layer_get_frame(window_layer);
}
static void destroy_ui() {
window_destroy(s_window);
}
static void handle_window_unload(Window* window) {
destroy_ui();
}
void show_config(void) {
initialize_ui();
window_set_window_handlers(s_window, (WindowHandlers) {
.unload = handle_window_unload,
});
window_stack_push(s_window, true);
}
void hide_config(void) {
window_stack_remove(s_window, true);
}
// Copyright (c) 2015 Douglas Otwell
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#pragma once
void show_config(void);
void hide_config(void);
......@@ -23,10 +23,16 @@
//
var MessageQueue=function(){var RETRY_MAX=5;var queue=[];var sending=false;var timer=null;return{reset:reset,sendAppMessage:sendAppMessage,size:size};function reset(){queue=[];sending=false}function sendAppMessage(message,ack,nack){if(!isValidMessage(message)){return false}queue.push({message:message,ack:ack||null,nack:nack||null,attempts:0});setTimeout(function(){sendNextMessage()},1);return true}function size(){return queue.length}function isValidMessage(message){if(message!==Object(message)){return false}var keys=Object.keys(message);if(!keys.length){return false}for(var k=0;k<keys.length;k+=1){var validKey=/^[0-9a-zA-Z-_]*$/.test(keys[k]);if(!validKey){return false}var value=message[keys[k]];if(!validValue(value)){return false}}return true;function validValue(value){switch(typeof value){case"string":return true;case"number":return true;case"object":if(toString.call(value)=="[object Array]"){return true}}return false}}function sendNextMessage(){if(sending){return}var message=queue.shift();if(!message){return}message.attempts+=1;sending=true;Pebble.sendAppMessage(message.message,ack,nack);timer=setTimeout(function(){timeout()},1e3);function ack(){clearTimeout(timer);setTimeout(function(){sending=false;sendNextMessage()},200);if(message.ack){message.ack.apply(null,arguments)}}function nack(){clearTimeout(timer);if(message.attempts<RETRY_MAX){queue.unshift(message);setTimeout(function(){sending=false;sendNextMessage()},200*message.attempts)}else{if(message.nack){message.nack.apply(null,arguments)}}}function timeout(){setTimeout(function(){sending=false;sendNextMessage()},1e3);if(message.ack){message.ack.apply(null,arguments)}}}}();
// global variables
var ISDEBUG = true;
var g_server_url = "http://192.168.1.76";
var g_user;
var g_password;
var storage_keys = {
"IP_ADDRESS": 0,
"USERNAME": 1,
"PASSWORD": 2
}
var ISDEBUG = false;
var g_ip_address = "";
var g_username = "";
var g_password = "";
var g_player_id;
var g_player_type;
var g_volume;
......@@ -41,30 +47,42 @@ var JsonRpcRequest = function (method, params) {
};
function sendJsonRequest(requests, callback) {
var username = null;
var password = null;
var response = null;
var req = new XMLHttpRequest();
req.onload = function(e) {
if (req.readyState == 4 && req.status == 200) {
if (ISDEBUG) console.log("Response text: "+req.responseText);
response = JSON.parse(req.responseText);
if (response.result == null) {
handleJsonRpcError(response);
req.onreadystatechange = function(e) {
if (req.readyState == 4) {
if (req.status == 200) {
if (ISDEBUG) console.log("Response text: "+req.responseText);
response = JSON.parse(req.responseText);
if (response.result == null) {
handleJsonRpcError(response);
} else {
if (callback != null) {
callback(response.result);
}
}
} else {
if (callback != null) {
callback(response.result);
if (req.status !== 0) {
console.log("Error connecting ["+req.status+"]: "+req.statusText);
Pebble.showSimpleNotificationOnPebble("Could not connect ["+req.status+"]", "Please check your Rockodi settings in the Pebble app.");
}
}
}
};
req.onerror = function(e) {
console.log("Error connecting to Kodi");
};
var url_string = g_server_url+"/jsonrpc?request=";
req.open('GET', url_string+encodeURI(JSON.stringify(requests)), true);
req.timeout = 2000;
if (g_username !== "") {
username = g_username;
if (g_password !== "") {
password = g_password;
}
}
var url_string = "http://"+g_ip_address+"/jsonrpc?request=";
req.open('GET', url_string+encodeURI(JSON.stringify(requests)), true, username, password);
req.timeout = 4000;
req.send(null);
if (ISDEBUG) console.log("Sent request: "+url_string);
if (ISDEBUG) console.log("Sent request: "+url_string+encodeURI(JSON.stringify(requests)));
}
function handleJsonRpcError(response) {
......@@ -123,7 +141,6 @@ function getItemCb(result) {
} else {
artist = (result.item.artist.length < 1) ? "" : result.item.artist[0];
}
console.log("Artist:"+artist);
MessageQueue.sendAppMessage({"MSG_KEY_TITLE":title,"MSG_KEY_ARTIST":artist});
}
function playPause() {
......@@ -226,7 +243,7 @@ function getMusicPlaylistsCb(result) {
MessageQueue.sendAppMessage(dict);
}
function playMusicPlaylist(payload) {
var filename = payload.MSG_KEY_BUTTON_DATA;
var filename = payload.MSG_KEY_CMD_DATA;
var requests = [];
requests.push(new JsonRpcRequest("PlayList.Clear", {"playlistid": 0}));
requests.push(new JsonRpcRequest("PlayList.Add", {"playlistid":0, "item":{"directory":filename,"recursive":true}}));
......@@ -249,7 +266,7 @@ function getAddonsCb(result) {
MessageQueue.sendAppMessage(dict);
}
function executeAddon(payload) {
var addonid = payload.MSG_KEY_BUTTON_DATA;
var addonid = payload.MSG_KEY_CMD_DATA;
sendJsonRequest(new JsonRpcRequest("Addons.ExecuteAddon", {"addonid": addonid}));
}
// Power methods
......@@ -269,11 +286,31 @@ function systemSuspend() {
Pebble.addEventListener('ready',
function(e) {
console.log('Rockodi copyright (c) 2015, Douglas Otwell');
g_ip_address = localStorage.getItem(storage_keys.IP_ADDRESS);
g_username = localStorage.getItem(storage_keys.USERNAME);
g_password = localStorage.getItem(storage_keys.PASSWORD);
}
);
Pebble.addEventListener('showConfiguration', function(e) {
var query_string = encodeURI("?ip_address="+g_ip_address+"&username="+g_username+"&password="+g_password);
Pebble.openURL('http://www.dkographicdetails.com/rockodi/config/config-page.html'+query_string);
});
Pebble.addEventListener('webviewclosed',
function(e) {
var configuration = JSON.parse(decodeURIComponent(e.response));
if (typeof configuration.ip_address !== "undefined") {
localStorage.setItem(storage_keys.IP_ADDRESS, configuration.ip_address);
localStorage.setItem(storage_keys.USERNAME, configuration.username);
localStorage.setItem(storage_keys.PASSWORD, configuration.password);
g_ip_address = localStorage.getItem(storage_keys.IP_ADDRESS);
g_username = localStorage.getItem(storage_keys.USERNAME);
g_password = localStorage.getItem(storage_keys.PASSWORD);
}
}
);
Pebble.addEventListener("appmessage",
function(e) {
var cmd = e.payload.MSG_KEY_BUTTON_CODE;
var cmd = e.payload.MSG_KEY_CMD;
switch(cmd) {
// Player messages
case "GET_STATUS": getStatus(); break;
......
......@@ -79,23 +79,19 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context)
while(t != NULL) {
switch(t->key) {
case MSG_KEY_TITLE:
DEBUG("Adjusting title: %s", t->value->cstring);
strncpy(s_title, t->value->cstring, sizeof(s_title));
text_layer_set_text(s_txt_title, s_title);
break;
case MSG_KEY_ARTIST:
DEBUG("Adjusting artist: %s", t->value->cstring);
strncpy(s_artist, t->value->cstring, sizeof(s_artist));
text_layer_set_text(s_txt_artist, s_artist);
break;
case MSG_KEY_VOLUME:
DEBUG("Adjusting volume: %d", (int) t->value->int32);
layer_data = (uint32_t *)layer_get_data(s_lyr_volume);
*layer_data = t->value->int32;
layer_mark_dirty(s_lyr_volume);
break;
case MSG_KEY_PLAY_STATE:
DEBUG("Adjusting play state: %d", (int) t->value->int32);
if (t->value->int32 > 0) {
action_bar_layer_set_icon(s_action_bar, BUTTON_ID_SELECT, s_icon_pause);
} else {
......
......@@ -60,7 +60,6 @@ static void inbox_received_callback(DictionaryIterator *iterator, void *context)
t = dict_read_next(iterator);
}
int items_size = dict_write_end(&items_iter);
DEBUG("Size of the written buffer is %d bytes.", items_size);
load_menu();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment