mirror of
https://github.com/kxgx/2.13-Ink-screen-clock.git
synced 2026-03-16 07:13:17 +08:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b688062ca4 | ||
|
|
d63d12de38 | ||
|
|
9ef97ab7a2 | ||
|
|
6651491941 | ||
|
|
d498dad18f | ||
|
|
2bd8dc0bc6 | ||
|
|
7873004d74 | ||
|
|
a5eec2e9a3 | ||
|
|
a8059bac56 | ||
|
|
a80e3a2722 | ||
|
|
c60fccb210 | ||
|
|
53e1845ce4 | ||
|
|
3844f71943 | ||
|
|
b2336dcbfb | ||
|
|
5a976157c2 | ||
|
|
b6866ee2b9 | ||
|
|
32565ef2f5 | ||
|
|
0c4282ebc9 | ||
|
|
f8b2c1b332 | ||
|
|
5b5dace7d3 | ||
|
|
04ab97f5b6 | ||
|
|
0565fd6cf5 | ||
|
|
173d7eba78 |
15
README.md
15
README.md
@@ -64,23 +64,25 @@ sudo reboot
|
||||
```Bash
|
||||
--zh 设置系统语言为zh_CN,UTF-8
|
||||
--cn 替换apt镜像源为中国镜像源
|
||||
--gitcn 克隆中国仓库
|
||||
--debug 输出详细信息
|
||||
```
|
||||
###
|
||||
```Bash
|
||||
#国内源默认设置
|
||||
#中国源默认设置
|
||||
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash
|
||||
```
|
||||
```Bash
|
||||
#国内源--cn设置
|
||||
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --cn
|
||||
#中国源全参数设置(不使用--debug参数)
|
||||
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --zh --cn --gitcn
|
||||
```
|
||||
```Bash
|
||||
#默认源默认设置
|
||||
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash
|
||||
```
|
||||
```Bash
|
||||
#默认源--cn设置
|
||||
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --cn
|
||||
#中国源全参数设置(不使用--debug参数)
|
||||
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --zh --cn --gitcn
|
||||
```
|
||||
|
||||
## 需要安装的软件和依赖:
|
||||
@@ -112,4 +114,5 @@ sudo apt-get update && sudo apt install -y git && sudo apt-get install -y python
|
||||
|
||||
特别注意:
|
||||
在代码文件第三十三行,此次代码需要更改,否则将展示默认城市天气数据
|
||||

|
||||
# 效果展示
|
||||

|
||||
|
||||
34
bin/clean.sh
34
bin/clean.sh
@@ -1,27 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
f_name=clean.py
|
||||
f_name="clean.py"
|
||||
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
logdir=${dir%/*}
|
||||
screen_name="clean_screen"
|
||||
logdir="${dir}/log"
|
||||
service_name="raspi_e-Paper.service"
|
||||
hold_time_seconds=3 # 设置维持时间,例如300秒(5分钟)
|
||||
|
||||
# 创建一个新的screen会话并运行Python脚本
|
||||
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/clean-info.log 2>&1
|
||||
# 停止raspi_e-Paper服务
|
||||
echo "正在停止$service_name服务..."
|
||||
sudo systemctl stop "$service_name"
|
||||
|
||||
# 确保日志目录存在
|
||||
mkdir -p "${logdir}"
|
||||
|
||||
# 获取并终止所有与脚本相关的进程
|
||||
pids=$(pgrep -f "$dir/$f_name")
|
||||
if [ -n "$pids" ]; then
|
||||
kill -9 $pids
|
||||
fi
|
||||
|
||||
# 使用nohup在后台运行Python脚本,并将输出重定向到日志文件
|
||||
nohup /usr/bin/python3 -u "$dir/$f_name" > "${logdir}/info-clean.log" 2>&1 &
|
||||
|
||||
# 等待维持时间
|
||||
echo "正在运行脚本,将在 ${hold_time_seconds} 秒后停止服务..."
|
||||
sleep $hold_time_seconds
|
||||
|
||||
# 停止raspi_e-Paper服务
|
||||
echo "正在停止$service_name服务..."
|
||||
sudo systemctl stop $service_name
|
||||
|
||||
# 查找并结束所有与指定screen_name相关的screen会话
|
||||
pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}')
|
||||
for pid in $pids; do
|
||||
screen -S $pid -X quit
|
||||
done
|
||||
|
||||
echo "脚本运行完成,服务已停止,screen会话已结束。"
|
||||
|
||||
@@ -12,6 +12,8 @@ DEFAULT_LANG="en_US.UTF-8"
|
||||
USE_CN_MIRROR=false
|
||||
# 控制调试输出
|
||||
DEBUG=false
|
||||
# 检查是否使用中国git仓库
|
||||
USE_CN_GIT=false
|
||||
|
||||
# 解析命令行参数
|
||||
while [ "$#" -gt 0 ]; do
|
||||
@@ -22,6 +24,9 @@ while [ "$#" -gt 0 ]; do
|
||||
--cn)
|
||||
USE_CN_MIRROR=true
|
||||
;;
|
||||
--gitcn)
|
||||
USE_CN_GIT=true
|
||||
;;
|
||||
--debug)
|
||||
DEBUG=true
|
||||
;;
|
||||
@@ -102,7 +107,6 @@ is_raspberry_pi() {
|
||||
DEBIAN_MIRROR="http://deb.debian.org/debian/"
|
||||
DEBIAN_SECURITY_MIRROR="http://security.debian.org/"
|
||||
PI_SUGAR_POWER_MANAGER_URL="https://cdn.pisugar.com/release/pisugar-power-manager.sh"
|
||||
INK_SCREEN_CLOCK_REPO_URL="https://github.com/kxgx/2.13-Ink-screen-clock.git"
|
||||
PIPY_MIRROR="https://pypi.org/simple"
|
||||
# 修改 Raspberry Pi 特定源链接
|
||||
RASPBERRY_PI_SOURCE_DEBIAN11="https://archive.raspberrypi.org/debian/"
|
||||
@@ -112,13 +116,19 @@ RASPBERRY_PI_SOURCE_DEBIAN12="https://archive.raspberrypi.com/debian/"
|
||||
if [ "$USE_CN_MIRROR" = true ]; then
|
||||
DEBIAN_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian/"
|
||||
DEBIAN_SECURITY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian-security"
|
||||
INK_SCREEN_CLOCK_REPO_URL="https://gitee.com/xingguangk/2.13-Ink-screen-clock.git"
|
||||
PIPY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
|
||||
# 使用中国镜像源时,Raspberry Pi 特定源链接保持不变
|
||||
RASPBERRY_PI_SOURCE_DEBIAN11="https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/"
|
||||
RASPBERRY_PI_SOURCE_DEBIAN12="https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/"
|
||||
fi
|
||||
|
||||
# 定义仓库链接变量
|
||||
INK_SCREEN_CLOCK_REPO_URL="https://github.com/kxgx/2.13-Ink-screen-clock.git"
|
||||
# 如果使用中国仓库,则更新链接变量
|
||||
if [ "$USE_CN_GIT" = true ]; then
|
||||
INK_SCREEN_CLOCK_REPO_URL="https://gitee.com/xingguangk/2.13-Ink-screen-clock.git"
|
||||
fi
|
||||
|
||||
# 更新源列表函数
|
||||
update_sources_list() {
|
||||
local version=$1
|
||||
@@ -175,11 +185,7 @@ install_packages() {
|
||||
echo "更新源列表失败" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! sudo apt-get upgrade -y; then
|
||||
echo "系统更新失败" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! sudo apt-get install -y git pigpio raspi-config netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential screen; then
|
||||
if ! sudo apt-get install -y git pigpio netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential; then
|
||||
echo "软件包安装失败" >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -187,8 +193,9 @@ install_packages() {
|
||||
|
||||
# 安装pip包函数
|
||||
install_pip_packages() {
|
||||
if ! sudo pip3 install -i "$PIPY_MIRROR" spidev borax pillow requests --break-system-packages; then
|
||||
echo "pip软件包安装包失败" >&2
|
||||
if ! sudo pip3 install -i "$PIPY_MIRROR" spidev borax pillow requests; then
|
||||
echo "pip软件包安装包失败,如果是最新版系统" >&2
|
||||
echo "请手动运行sudo pip3 install -i "$PIPY_MIRROR" spidev borax pillow requests --break-system-packages" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -202,22 +209,24 @@ setup_service() {
|
||||
|
||||
# 检查墨水屏时钟仓库是否存在
|
||||
if [ ! -d "$HOME/2.13-Ink-screen-clock" ]; then
|
||||
echo "正在克隆仓库"
|
||||
cd ~
|
||||
if ! git clone $INK_SCREEN_CLOCK_REPO_URL; then
|
||||
echo "克隆墨水屏时钟仓库失败" >&2
|
||||
echo "克隆仓库失败" >&2
|
||||
exit 1
|
||||
fi
|
||||
# 设置start.sh和clean.sh脚本的执行权限
|
||||
chmod +x "$HOME/2.13-Ink-screen-clock/bin/start.sh"
|
||||
chmod +x "$HOME/2.13-Ink-screen-clock/bin/clean.sh"
|
||||
else
|
||||
echo "墨水屏时钟仓库文件夹已存在,跳过克隆"
|
||||
echo "仓库文件夹已存在,跳过克隆"
|
||||
fi
|
||||
|
||||
# 检查服务文件是否存在
|
||||
if [ -f "$service_file_path" ] && [ -f "$service1_file_path" ]; then
|
||||
# 检查服务是否已经启用
|
||||
if ! systemctl is-enabled $service_path &>/dev/null && ! systemctl is-enabled $service1_path &>/dev/null; then
|
||||
echo "正在复制服务文件并启用服务"
|
||||
# 复制服务文件到 systemd 目录
|
||||
if sudo cp "$service_file_path" /etc/systemd/system/ && sudo cp "$service1_file_path" /etc/systemd/system/; then
|
||||
# 重载 systemd 管理器配置
|
||||
|
||||
25
bin/main.py
25
bin/main.py
@@ -32,7 +32,7 @@ def Local_strong_brush(): #局部强制刷新显示
|
||||
i = i + 1
|
||||
def getWeath(city='101060111'): #天气函数,下载json天气至本地
|
||||
headers = {
|
||||
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36 Edg/94.0.992.50',
|
||||
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
|
||||
'Referer':'http://www.weather.com.cn/'
|
||||
}
|
||||
response = requests.get('http://d1.weather.com.cn/sk_2d/'+city+'.html',headers=headers)
|
||||
@@ -66,25 +66,8 @@ def Memory_footprint():#显示内存占用百分比
|
||||
return(subprocess.check_output(u"free -m | awk -F '[ :]+' 'NR==2{printf \"%d\", ($3)/$2*100}'", shell = True ).decode('gbk'))
|
||||
def CPU_usage(): #显示CPU占用百分比
|
||||
return(str(int(float(os.popen("top -b -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip()))))
|
||||
def power_battery():
|
||||
try:
|
||||
# 获取电池电量
|
||||
battery_percentage = subprocess.check_output(
|
||||
"echo \"get battery\" | nc -q 0 127.0.0.1 8423 | awk -F':' '{print $2}'",
|
||||
shell=True,
|
||||
text=True
|
||||
).strip()
|
||||
|
||||
# 检查电量信息
|
||||
if not battery_percentage:
|
||||
return "无效"
|
||||
|
||||
# 返回电量百分比
|
||||
return f"{int(battery_percentage)}%"
|
||||
except Exception as e:
|
||||
# 返回错误信息
|
||||
return "失败"
|
||||
|
||||
def power_battery():#获取当前电池电量
|
||||
return(str(int(subprocess.check_output(u"echo \"get battery\" | nc -q 0 127.0.0.1 8423|awk -F':' '{print int($2)}'", shell = True ).decode('gbk')))+u'%')
|
||||
# 打印电量信息
|
||||
print(power_battery())
|
||||
def Bottom_edge(): #在图片中添加底边内容
|
||||
@@ -141,8 +124,6 @@ def Weather(): #在图片中添加天气内容
|
||||
|
||||
def Basic_refresh(): #全刷函数
|
||||
logging.info("Refresh and prepare the basic content before starting the canvas")#开始画布前刷新准备基础内容
|
||||
epd.init()
|
||||
epd.Clear(0xFF)
|
||||
global get_date_var
|
||||
get_date_var=get_date() #记录开始数据
|
||||
draw.text((2,2),get_date_var,font = font02,fill =0)#将日期及星期几显示到屏幕
|
||||
|
||||
15
bin/start.sh
15
bin/start.sh
@@ -1,15 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
f_name=main.py
|
||||
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
logdir=${dir%/*}
|
||||
screen_name="main_screen"
|
||||
|
||||
# 查找并结束所有与指定screen_name相关的screen会话
|
||||
pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}')
|
||||
for pid in $pids; do
|
||||
screen -S $pid -X quit
|
||||
pid=`ps -ef |grep $dir/$f_name | grep -v grep |awk '{print $2}'`
|
||||
for id in $pid
|
||||
do
|
||||
kill -9 $id
|
||||
done
|
||||
|
||||
# 创建一个新的screen会话并运行Python脚本
|
||||
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/info.log 2>&1
|
||||
nohup /usr/bin/python3 -u $dir/$f_name > $logdir/log/info.log 2>&1 &
|
||||
|
||||
BIN
pic/1736672578025.jpg
Normal file
BIN
pic/1736672578025.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.0 MiB |
Reference in New Issue
Block a user