跳到主要内容

未来板太空人手表

image.png

项目介绍


华为Watch GT2手表的太空人表盘主题前阵子大火,将朴素的时间显示和有趣的旋转太空人效果结合,跟着cc喵在未来板手表上整活儿吧~

项目清单

材料备注
未来板x1
Type-C 数据线x1
网络热点(手机/路由器)

实现步骤

第一步——查找华为太空人表盘主题
第二步——查找表盘解包工具
第三步——处理解包表盘的图片大小
第四步——KittenCode编写太空人表盘程序

第一步——查找华为太空人表盘主题

有事找百度,第一个亲测无毒,当然你也可以找其它表盘主题
image.png

下载得到的压缩包,待用
image.png

第二步——查找表盘解包工具

下载压缩包
image.png

  1. 现将工具解压,得到以下几个文件

  2. 将.hwt格式表盘文件(这个文件是STEP1下载的压缩包得到的hwt文件),后缀修改为.zip解压得到以下文件

  3. 将解压后的 com.huawei.watchface 文件,用鼠标拖至1中的tool.exe文件

危险

解包工具在win10下无法正常使用(现象为拖到tool.exe一点反应都没有),那么你需要先安装一个java环境。
附上附件,请解压后在安装
jre-8u144-windows-i586.rar

  1. 提取成功后,com.huawei.watchface同级目录会出现com.huawei.watchface_extra文件夹,提取的图片就在里面
    image.png

第三步——处理解包表盘的图片大小

得到的素材尺寸是符合华为手表的,但不符合我们未来板的屏幕尺寸,因此根据未来板屏幕大小160x128,进行比例缩放,如最大的表盘图片大小高度是454,那我们就把图片缩放到未来板屏幕高度128,相当于高度的0.28倍,其它图片的高度也按照这个尺寸进行处理
image.png
由于时间的关系,我已经把图片处理好,并且把数字对应的图片名称也改好了,这样可以方便我们编程
image.png

  1. 直接下载这个处理好的图片压缩包

tai.rar

  1. 解压后,把文件夹里面的文件复制到一张TF卡上(当然你也可以一张张传给未来板,TF卡会更方便些),TF卡推荐闪迪高速卡,一般在京东上买就没错了28+左右

第四步——KittenCode编写太空人表盘程序

将代码复制到KittenCode中

危险

只需更改一处地方,41行的wifi名称与密码。
image.png

#/bin/python
from future import *
from sugar import *
from time import sleep
import ntptime
from machine import RTC
wifi.connect(str("Kittenbot"), "kittenbot428")
sleep(1)
ntptime.host="ntp.aliyun.com"
rtc = RTC()
ntptime.settime()

timestarty = 0
H1x = 0
M0x = 0
Dx = 0
H0x = 0
M1x = 0
timestartx = 0
taix = 0
taiy = 0
taidelay = 0

def time():
global timestarty,H1x,M0x,Dx,H0x,M1x,timestartx,taix,taiy,taidelay
timeH1 = (int(rtc.datetime()[int(4)] / 10))
timeH0 = (rtc.datetime()[int(4)] % 10)
timeM1 = (int(rtc.datetime()[int(5)] / 10))
timeM0 = (rtc.datetime()[int(5)] % 10)
timestartx = 40
timestarty = 30
H1x = (timestartx + 16 * 0)
H0x = (timestartx + 16 * 1)
Dx = (timestartx + 16 * 2)
M1x = (timestartx + 16 * 3)
M0x = (timestartx + 16 * 4)
screen.loadPng(str(timeH1)+'.png',H1x,timestarty)
screen.loadPng(str(timeH0)+'.png',H0x,timestarty)
screen.loadPng('10.png',Dx,timestarty)
screen.loadPng(str(timeM1)+'.png',M1x,timestarty)
screen.loadPng(str(timeM0)+'.png',M0x,timestarty)


sleep(3)
screen.sync = 0
taix = 40
taiy = 50
taidelay = 0.1
screen.fill((255, 255, 255))
screen.loadPng('142.png',-8,0)


while True:

screen.loadPng('142.png',-8,0)
time()
screen.loadPng('132.png',taix,taiy)
screen.refresh()
sleep(taidelay)
screen.loadPng('143.png',taix + 13,taiy + 10)
screen.loadPng('133.png',taix,taiy)
screen.refresh()
sleep(taidelay)
screen.loadPng('143.png',taix + 13,taiy + 10)
screen.loadPng('134.png',taix,taiy)
screen.refresh()
sleep(taidelay)
screen.loadPng('143.png',taix + 13,taiy + 10)
screen.loadPng('135.png',taix,taiy)
screen.refresh()
sleep(taidelay)
screen.loadPng('143.png',taix + 13,taiy + 10)
screen.loadPng('136.png',taix,taiy)
screen.refresh()
sleep(taidelay)
screen.loadPng('143.png',taix + 13,taiy + 10)
screen.loadPng('137.png',taix,taiy)
screen.refresh()
sleep(taidelay)
screen.loadPng('143.png',taix + 13,taiy + 10)
screen.loadPng('138.png',taix,taiy)
screen.refresh()
sleep(taidelay)
screen.loadPng('143.png',taix + 13,taiy + 10)
screen.loadPng('139.png',taix,taiy)
screen.refresh()
sleep(taidelay)
screen.loadPng('143.png',taix + 13,taiy + 10)
screen.loadPng('140.png',taix,taiy)
screen.refresh()
sleep(taidelay)
screen.loadPng('143.png',taix + 13,taiy + 10)
screen.loadPng('141.png',taix,taiy)
screen.refresh()
sleep(taidelay)
screen.loadPng('143.png',taix + 13,taiy + 10)

上传程序
image.png

程序重点讲解1——将时与分进行拆分

  • 问题

如21:51分
通过RTC得到的时为 int(rtc.datetime()[int(4)]=21
通过RTC得到的分为 int(rtc.datetime()[int(5)]=51
我们需要拆分成 2、1和5、1,通过变量更换,时的十位数,个位数;分的十位数和个位数的图片

  • 方法

21/10后,只取整数部分,则可以得到2,21取余10后(21/10得到的余数),则可以得到1通过对应图片名称变量为 str(x)+'.png',则可以得到对应数字的图片

程序重点讲解2——将太空人图片轮询显示

从文件夹中可知,太空人图片是132.png~141.png
image.png

只需将132~141.png的图片循环显示即可,可惜是太空人的图片是透明背景的,所以当显示完132.png后,再显示133.png,可以发现133叠加在132上就会如下图一样糊成一团
image.png
因此我们可以借助143.png的蓝底图片
在显示完132.png——》盖上一张143.png的蓝底照片后——》再显示133.png