1940浏览
查看: 1940|回复: 1

[入门教程] 基于UIFlow的会议与任务提醒系统

[复制链接]
本帖最后由 vany5921 于 2020-6-24 16:39 编辑

      此项目结合MQTT实现会议下发提醒与任务管理功能,在默认待机状态下显示时间,接收到上级下发的通知后会自动切换到提醒界面。系统根据会议时间会自动倒计时,到达指定时间后会通过灯光进行提醒,同时可通过MQTT进行员工个人任务的推送,任务完成后可手动推送至上级服务器进行汇报。屏幕显示3条任务,多余任务将会在完成后主动POP显示。此外该系统自带手动定时的久坐提醒功能,可通过PortA接口外接传感器变更为自动监测提醒。操作说明:开机后显示开机画面,此时为联网状态,红色LED常亮获取网络时间,当接入网络并正确获取时间后,LED熄灭,进入默认时钟界面。长按C键可进入久坐提醒模式,此时若无通知则一直显示时间,久坐提醒时间到会以灯光模式进行提醒。同时按住A+B键手动进入任务/会议查看模式,按住A+B键恢复时钟界面。进入任务/会议查看模式后通过A/C键选择任务,长按B键推送已完成任务,完成的任务从屏幕消失,未完成的新任务自动添加到屏幕。长按A键取消会议提醒。
基于UIFlow的会议与任务提醒系统图1基于UIFlow的会议与任务提醒系统图2基于UIFlow的会议与任务提醒系统图3基于UIFlow的会议与任务提醒系统图4基于UIFlow的会议与任务提醒系统图5
基于UIFlow的会议与任务提醒系统图6基于UIFlow的会议与任务提醒系统图7
以下配合MQTT工具进行测试,在实际使用中有一个前端HTML页面用于任务和消息发布
[mw_shl_code=python,false]from m5stack import *
from m5ui import *
from uiflow import *
import time
import json

import urequests
from m5mqtt import M5mqtt

setScreenColor(0x222222)


m5mqtt = M5mqtt('c8cb7df3fc9b4e9d8b5eb1b45C', 'mqtt.m5stack.com', 1883, 'apimgqyr', 'enYJVZ-drTsT', 300)


task1_label = M5TextBox(35, 15, "暂时无任务", lcd.FONT_UNICODE,0xf40a0a, rotate=0)
task2_label = M5TextBox(35, 70, "暂时无任务", lcd.FONT_UNICODE,0xf3c209, rotate=0)
task3_label = M5TextBox(35, 125, "暂时无任务", lcd.FONT_UNICODE,0x24f802, rotate=0)
task_highlight_mark = M5Circle(20, 25, 5, 0xFFFFFF, 0xFFFFFF)
long_sit_remain_label = M5TextBox(210, 208, "久坐提醒", lcd.FONT_UNICODE,0xb6ecea, rotate=0)
time_label = M5TextBox(213, 5, "13:10:10", lcd.FONT_UNICODE,0x14d8b3, rotate=0)
meetting_remain_label = M5TextBox(210, 40, "会议提醒", lcd.FONT_UNICODE,0xc00ae5, rotate=0)
rectangle0 = M5Rect(200, 0, 2, 240, 0x8f8f8f, 0x8e8e8e)
rectangle1 = M5Rect(200, 30, 120, 2, 0x8c8c8c, 0x8f8f8f)
rectangle2 = M5Rect(200, 200, 120, 2, 0x8e8e8e, 0x8e8e8e)
meeting_time = M5TextBox(233, 97, "Text", lcd.FONT_DejaVu24,0xe70dde, rotate=0)
read_more = M5TextBox(35, 180, "查看更多", lcd.FONT_UNICODE,0xFFFFFF, rotate=0)
large_time = M5TextBox(60, 80, "13:10", lcd.FONT_DejaVu72,0xFFFFFF, rotate=0)
image0 = M5Img(0, 0, "res/123.jpg", True)

from numbers import Number
import random

without_message = None
meeting_H = None
notice = None
SS = None
H = None
metting_M = None
circle_y = None
real_task_ID = None
M = None
meeting_flag = None
ptr = None
S = None
MM = None
receive = None
queueTask = None
HH = None
period = None
getTime = None

def screen1():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  time_label.hide()
  task1_label.hide()
  task2_label.hide()
  task3_label.hide()
  read_more.hide()
  meetting_remain_label.hide()
  meeting_time.hide()
  rectangle0.hide()
  rectangle1.hide()
  rectangle2.hide()
  task_highlight_mark.hide()
  setScreenColor(0x000000)
  large_time.show()

def screen2():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  large_time.hide()
  meeting_time.hide()
  setScreenColor(0x000000)
  time_label.show()
  task1_label.show()
  task2_label.show()
  task3_label.show()
  meetting_remain_label.show()
  read_more.show()
  rectangle0.show()
  rectangle1.show()
  rectangle2.show()
  task_highlight_mark.show()

def display_task():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  task1_label.setText('暂时无任务')
  task2_label.setText('暂时无任务')
  task3_label.setText('暂时无任务')
  read_more.setText('查看更多')
  if len(queueTask) == 1:
    task1_label.setText(str(queueTask[0]['content']))
  elif len(queueTask) == 2:
    task1_label.setText(str(queueTask[0]['content']))
    task2_label.setText(str(queueTask[1]['content']))
  else:
    task1_label.setText(str(queueTask[0]['content']))
    task2_label.setText(str(queueTask[1]['content']))
    task3_label.setText(str(queueTask[2]['content']))


def fun_office_C_task_(topic_data):
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  print(topic_data)
  without_message = False
  lcd.fill(0x000000)
  screen2()
  receive = json.loads(topic_data)
  queueTask = receive
  if len(queueTask) > 0:
    if 'meeting' in queueTask[0].keys():
      meeting_H = (queueTask[0]['meeting'])[ : 2]
      metting_M = (queueTask[0]['meeting'])[3 : 5]
      meeting_time.show()
      meeting_time.setText(str(queueTask[0]['meeting']))
      meetting_remain_label.setText(str((str('开会') + str(''))))
      receive = ''
    else:
      display_task()
  pass
m5mqtt.subscribe(str('office/C/task'), fun_office_C_task_)

def multiBtnCb_AC():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  without_message = True
  screen1()
  pass
btn.multiBtnCb(btnA,btnC,multiBtnCb_AC)

def multiBtnCb_AB():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  without_message = False
  screen2()
  pass
btn.multiBtnCb(btnA,btnB,multiBtnCb_AB)

def buttonA_pressFor():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  meeting_H = 0
  metting_M = 0
  meeting_flag = False
  meeting_time.hide()
  meetting_remain_label.setText('会议提醒')
  rgb.setColorAll(0x000000)
  pass
btnA.pressFor(0.8, buttonA_pressFor)

def buttonA_wasPressed():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  if circle_y < 180:
    circle_y = (circle_y if isinstance(circle_y, Number) else 0) + 55
    if without_message == False:
      task_highlight_mark.setPosition(y=circle_y)
    ptr = (ptr if isinstance(ptr, Number) else 0) + 1
  pass
btnA.wasPressed(buttonA_wasPressed)

def buttonC_pressFor():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  notice = 1 - notice
  if notice == 1:
    timerSch.run('long_sit', 10000, 0x00)
    long_sit_remain_label.setColor(0xff6600)
  else:
    timerSch.stop('long_sit')
    rgb.setColorAll(0x000000)
    long_sit_remain_label.setColor(0x99ffff)
  pass
btnC.pressFor(0.8, buttonC_pressFor)

def buttonC_wasPressed():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  if circle_y > 70:
    circle_y = (circle_y if isinstance(circle_y, Number) else 0) + -55
    if without_message == False:
      task_highlight_mark.setPosition(y=circle_y)
    ptr = (ptr if isinstance(ptr, Number) else 0) + -1
  pass
btnC.wasPressed(buttonC_wasPressed)

def buttonB_pressFor():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  if ptr == 4:
    pass
  else:
    real_task_ID = queueTask.pop(int(ptr - 1))['taskID']
    m5mqtt.publish(str('office/task'),str((json.dumps(({'taskID':str(real_task_ID),'ID':'C'})))))
    display_task()
  pass
btnB.pressFor(0.8, buttonB_pressFor)

@timerSch.event('timer1')
def ttimer1():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  SS = (SS if isinstance(SS, Number) else 0) + 1
  if SS > 59:
    SS = 0
    MM = (MM if isinstance(MM, Number) else 0) + 1
  if MM > 59:
    MM = 0
    HH = (HH if isinstance(HH, Number) else 0) + 1
  if HH > 23:
    HH = 0
  if SS < 10:
    S = str(((str('0') + str(SS))))
  else:
    S = str(SS)
  if MM < 10:
    M = str(((str('0') + str(MM))))
  else:
    M = str(MM)
  if HH < 10:
    H = str(((str('0') + str(HH))))
  else:
    H = str(HH)
  pass

@timerSch.event('long_sit')
def tlong_sit():
  global without_message, meeting_H, notice, SS, H, metting_M, circle_y, real_task_ID, M, meeting_flag, ptr, S, MM, receive, queueTask, HH, period, getTime
  for count in range(5):
    rgb.setColorAll(0xff6600)
    wait_ms(100)
    rgb.setColorAll(0x33cc00)
    wait_ms(100)
    rgb.setColorAll(0xffff00)
    wait_ms(100)
  pass


H = 13
M = 10
S = 10
without_message = True
period = 0
meeting_flag = False
ptr = 1
meeting_H = 0
metting_M = 0
queueTask = ''
notice = 0
circle_y = 20
getTime = True
image0.show()
while getTime == True:
  rgb.setColorAll(0xff0000)
  try:
    req = urequests.request(method='GET', url='http://quan.suning.com/getSysTime.do', headers={})
    HH = int(((json.loads((req.text)))['sysTime1'])[8 : 10])
    MM = int(((json.loads((req.text)))['sysTime1'])[10 : 12])
    SS = int(((json.loads((req.text)))['sysTime1'])[12 : 14])
    getTime = False
  except:
    pass
rgb.setColorAll(0x000000)
m5mqtt.start()
timerSch.run('timer1', 1000, 0x00)
image0.hide()
lcd.clear()
while True:
  if meeting_H == H and metting_M == M:
    meeting_flag = True
  if meeting_flag:
    if (time.ticks_ms()) - period > 1500:
      rgb.setColorAll((random.randint(0, 255) << 16) | (random.randint(0, 255) << 8) | random.randint(0, 255))
      period = time.ticks_ms()
      wait_ms(100)
    else:
      rgb.setColorAll(0x000000)
  long_sit_remain_label.show()
  if without_message == True:
    large_time.setText(str((str(((str(H) + str(':')))) + str(M))))
  else:
    time_label.setText(str((str(((str(H) + str(':')))) + str(((str(((str(M) + str(':')))) + str(S)))))))
  wait_ms(2)[/mw_shl_code]




IMG_2714.JPG

hnyzcj  版主

发表于 2020-6-24 16:48:59

这个有点意思
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail