158142621728105 发表于 6 天前

2025东莞创客嘉年华--主题3 运动健康 (未获奖)作品展示

运动健康包括了科学健身、疾病防治、青少年成长、传统养生等多个领域,请设计一个与之相关的方案。可参考一下选题:趣味运动:为了提高青少年运动的兴趣,将其运动游戏化和趣味化运动健康管理:构建智能化健康管理方案,实现运动过程中身体的监测,预防运动受伤关注受伤后的恢复以及治疗


import sys

sys.path.append("/root/mindplus/.lib/thirdExtension/nick-pyttsx3-thirdex")
sys.path.append("/root/mindplus/.lib/thirdExtension/nick-unihiker_wifi-thirdex")
sys.path.append("/root/mindplus/.lib/thirdExtension/mengchangfeng-kimi-thirdex")
sys.path.append("/root/mindplus/.lib/thirdExtension/nick-unihiker_sound-thirdex")
import siot
import time
import pyttsx3

from unihiker import GUI
import openai
import json
from unihiker_sound import *
from pinpong.board import Board
from pinpong.board import DHT11
from unihiker_connet_wifi import *
from pinpong.board import Board, Pin
from pinpong.extension.unihiker import *

unihiker_sound = SoundManager()

wifi_manager = WiFiManager()

response_success = wifi_manager.connect_wifi(open("./WIFI").read().split("\n"), open("./WIFI").read().split("\n"))


def on_message_callback(client, userdata, msg):
    if msg.topic == (str("siot/sports/info")):
      if msg.payload.decode().split("--") == "cgq":
            if msg.payload.decode().split("--") == "voice":
                if int(msg.payload.decode().split("--")) == 5:
                  sports_mode_window()
                  start_sports()
                if int(msg.payload.decode().split("--")) == 6:
                  end_sports()
                if int((msg.payload.decode().split("--"))) == 7:
                  pass
      elif msg.payload.decode().split("--") == "time":
            pass
      elif msg.payload.decode().split("--") == "":
            pass


siot.init(client_id="7078199769605087", server="10.1.2.3", port=1883, user="siot", password="dfrobot")
Board().begin()
u_gui = GUI()
siot.connect()
siot.loop()
siot.set_callback(on_message_callback)
siot.getsubscribe(topic="siot/sports/info")
siot.getsubscribe(topic="siot/sports/chart")
siot.getsubscribe(topic="siot/sports/chart_1")
record_strength = 0
single_sports_times_sec = 0
total_sports_times_sec = 0
engine = pyttsx3.init()
unihiker_sound.set_volume(100)
engine.setProperty('volume', 1)
dht1 = DHT11(Pin(Pin.P24))

client = openai.OpenAI(api_key=open("./key").read(),
                     base_url="https://api.moonshot.cn/v1")
kimi_model = "moonshot-v1-8k"
kimi_temperature = 0.3
kimi_history = [
    {"role": "system", "content": """你是智能运动助手,
    你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。
    回答问题的时候尽量精简词语,尽量将回答控制在50字以内。
    也不需要在回答中添加关于时效性或者是请注意之类的额外说明"""}
]


def kimi_chat(query, kimi_history_, kimi_model_, kimi_temperature_):
    kimi_history_.append({
      "role": "user",
      "content": query
    })
    completion = client.chat.completions.create(
      model=kimi_model_,
      messages=kimi_history_,
      temperature=kimi_temperature_,
    )
    result = completion.choices.message.content
    kimi_history_.append({
      "role": "assistant",
      "content": result
    })
    return result


def hides(*sth):
    for _ in sth:
      _.config(x=-100, y=-100)


def sports_mode_window():
    print("运动模式")
    hides(btn1, btn2, t1, t2, t3, t4, btn5, btn6, btn7, t5, t6, t7, t8, btn8)
    t4.config(x=5, y=100)
    btn5.config(x=5, y=5)
    btn6.config(x=5, y=40)
    btn7.config(x=135, y=5)
    t5.config(x=5, y=145)
    t6.config(x=5, y=165)
    t7.config(x=5, y=185)


def main_window():
    hides(btn1, btn2, t1, t2, t3, t4, btn5, btn6, btn7, t5, t6, t7, t8, btn8)
    btn1.config(x=5, y=10)
    btn2.config(x=120, y=10)
    t1.config(x=5, y=100)
    t2.config(x=5, y=135)
    t3.config(x=5, y=170)


def report_window():
    hides(btn1, btn2, t1, t2, t3, t4, btn5, btn6, btn7, t5, t6, t7, t8, btn8)
    t8.config(x=5, y=35)
    btn8.config(x=5, y=5)
    btn7.config(x=135, y=5)


def start_sports():
    global record_time, record_strength, main
    t4.config(text="运动状态:已开始")
    record_time = u_gui.start_thread(u_record_time_function)
    record_strength = u_gui.start_thread(u_record_strength_function)
    main = u_gui.start_thread(u_main_function)


def end_sports():
    t4.config(text="运动状态:已结束")
    u_gui.stop_thread(record_time)
    u_gui.stop_thread(record_strength)


def report():
    t8.config(text="正在分析...")
    ttt = kimi_chat(
      f"分析给出数据以返回运动分析报告: 运动时长(s):{single_sports_times_sec} 温度(摄氏度):{dht1.temp_c()} 湿度(%rh):{dht1.humidity()}",
      kimi_history, kimi_model, kimi_temperature)
    t8.config(text=ttt)
    engine.say(ttt)
    engine.runAndWait()


record_time = 0
main = 0
btn1 = u_gui.add_button(text="运动模式", x=5, y=10, w=80, h=30, onclick=sports_mode_window)
btn2 = u_gui.add_button(text="健康报告", x=120, y=10, w=80, h=30, onclick=report_window)
t1 = u_gui.draw_text(text="当前状态:待机中", x=5, y=100, font_size=10, color="#0000FF")
t2 = u_gui.draw_text(text="今日运动: 0分钟 ", x=5, y=135, font_size=10, color="#999900")
t3 = u_gui.draw_text(text="语音提示: 说\"开始运动\"启动 ", x=5, y=170, font_size=10, color="#00FF00")
t4 = u_gui.draw_text(text="运动状态:未知", x=-100, y=-100, font_size=10, color="#00FF00")
btn5 = u_gui.add_button(text="开始运动", x=-100, y=-100, w=80, h=30, onclick=start_sports)
btn6 = u_gui.add_button(text="结束运动", x=-100, y=-100, w=80, h=30, onclick=end_sports)
btn7 = u_gui.add_button(text="返回主界面", x=-100, y=-100, w=100, h=30, onclick=main_window)
t5 = u_gui.draw_text(text="已运动 NaN 分钟 NaN 秒", x=-100, y=-100, font_size=10, color="#00FF00")
t6 = u_gui.draw_text(text="当前湿度:", x=-100, y=-100, font_size=10, color="#000000")
t7 = u_gui.draw_text(text="当前温度:", x=-100, y=-100, font_size=10, color="#000000")
t8 = u_gui.draw_text(text="", x=-100, y=-100, font_size=10, color="#000000", w=230)
btn8 = u_gui.add_button(text="报告", x=-100, y=-100, w=80, h=30, onclick=report)


def StoSM(s):
    return f"{(s - s % 60) // 60}分{s % 60}秒"


def u_record_time_function():
    global single_sports_times_sec, total_sports_times_sec
    single_sports_times_sec = 0
    while True:
      time.sleep(1)
      single_sports_times_sec += 1
      total_sports_times_sec += 1


def u_record_strength_function():
    while True:
      time.sleep(3)
      siot.publish(topic="siot/sports/info",
                     data=f"info--strength--{(accelerometer.get_strength() + 1) ** 2.5}")
      siot.publish_save(topic="siot/sports/chart", data=(accelerometer.get_strength() + 1) ** 2.5)
      siot.publish_save(topic="siot/sports/chart_1", data=f"{dht1.temp_c()},{dht1.humidity()}")


def u_main_function():
    while True:
      t5.config(text=(str("已运动") + str(StoSM(single_sports_times_sec))))
      t6.config(text=f"当前湿度:{dht1.humidity()}")
      t7.config(text=f"当前温度:{dht1.temp_c()}")
      last_record = accelerometer.get_strength()
      time.sleep(0.001)
      if accelerometer.get_strength() - last_record >= 3:
            engine.say("你还好吗?你摔到了吗?")
            engine.runAndWait()
            for _ in range(5):
                buzzer.pitch(988, 1)
                buzzer.pitch(523, 1)
                buzzer.pitch(698, 1)
                buzzer.pitch(311, 1)
                buzzer.pitch(156, 1)


while True:
    t2.config(text=f"今日运动: {StoSM(total_sports_times_sec)}")
https://mc.dfrobot.com.cn/forum.php?mod=image&aid=198564&size=300x300&key=6a2e1bb436f5d426&nocache=yes&type=fixnonehttps://mc.dfrobot.com.cn/forum.php?mod=image&aid=198563&size=300x300&key=8635b8e75eb4b179&nocache=yes&type=fixnonehttps://mc.dfrobot.com.cn/forum.php?mod=image&aid=198562&size=300x300&key=7068c022923de47f&nocache=yes&type=fixnonehttps://mc.dfrobot.com.cn/forum.php?mod=image&aid=198561&size=300x300&key=af77af78dccfeee4&nocache=yes&type=fixnonehttps://mc.dfrobot.com.cn/forum.php?mod=image&aid=198560&size=300x300&key=e87e63cde5ffcf36&nocache=yes&type=fixnonehttps://mc.dfrobot.com.cn/forum.php?mod=image&aid=198565&size=300x300&key=7e4d4679ce8ef77c&nocache=yes&type=fixnone
页: [1]
查看完整版本: 2025东莞创客嘉年华--主题3 运动健康 (未获奖)作品展示