利用PebbleJS写pebble手表应用

这个月初,任性买了刚发布的pebble time,一直还没写个应用,这个周末抽出时间看看。

开头

pebble的应用可以用C和Node开发,开发工具也可以使用cloudpebble(墙内用户伤不起)或者下载sdk离线开发。

安装SDK

mac安装pebble sdk太简单了

brew install pebble/pebble-sdk/pebble-sdk

网路顺畅的话,安装就完成了。

建立PebbleJS工程

离线建C项目只要运行pebble new-project xxx就好,但是js项目需要把github上的项目https://github.com/pebble/pebblejs.git clone下来

git clone https://github.com/pebble/pebblejs.git

文件目录

pebble应用的配置文件在appinfo.json里面,逻辑代码都写在src下的js/app.js里

UI module

引入ui模块

var ui = require('ui');

Window

var wind = new UI.Window({
  fullscreen: true,
});
wind.show();

效果如图:

<img src="https://developer.getpebble.com/assets/images/getting-started/watchface-tutorial/1-blank.png">

Card

创建一个卡片

// Create a Card with title and subtitle
var card = new UI.Card({
    title:'Weather',
    subtitle:'Fetching...'
    });

// Display the Card
card.show();

card.on('click', 'up', function(e) {
    /*上键事件*/
    })
card.on('click', 'select', function(e) {
    /* 中键事件*/
    })
card.on('click', 'down', function(e) {
    /*下键事件*/
    })

效果如图

<img src="https://developer.getpebble.com/assets/images/getting-started/pebble-js-tutorial/1-fetching.png">

Card还有body和icon属性

Menu

var resultsMenu = new UI.Menu({
    sections: [{
        title: 'Current Forecast',
        items: [{
            title: 'Clear',
            subtitle: '11-05 21:00'
            }]
        }]
    });

    resultsMenu.on('select', function(e)    {
        console.log('Selected item #' + e.itemIndex + ' of section #' + e.sectionIndex);
        console.log('The item is titled "' + e.item.title + '"');
    });

    // Show the Menu
    resultsMenu.show();

<img src="https://developer.getpebble.com/assets/images/getting-started/pebble-js-tutorial/2-menu.png">

编译

pebble build

#安装

pebble install --phone 192.168.1.107//你的手机ip,记得打开pebble的调试模式

查看偶的博客,欢迎来踩

转载于:https://my.oschina.net/gongbaodd/blog/496993

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值