April 26, 2024

Intelligent mirror design based on dragonboard 410c (9) - how to implement UI interactive control logic

In the UI prototyping and Python script implementation UI prototype two blogs have introduced the design and prototype of the interactive UI of the entire smart mirror end and the implementation of Python scripts and methods, here will further teach you how to achieve the logic control of the entire UI interaction The program, according to the design of the smart mirror overall design article, the intelligent mirror interaction mainly relies on the camera, ultrasound and display to interact with the user. The smart mirror relies on the ultrasonic module to monitor the human body dynamics in front of the mirror in real time. The camera is started, and then the current user identity is processed and recognized by image recognition. Finally, the display module control display is started according to the user identity, and the specified user message is pushed and displayed in front of the user currently using the mirror.

The above is the content that needs to be completed in the design of the display control logic in the smart mirror. In the process of concrete implementation, the display logic control is mainly realized by constructing a magic_mirroWindows.py file, which is realized here. The magical mirror's interactive UI class is instantiated, and a magic_mirroWindows class is created to implement the various logic control functions of the magic mirror UI control. The main logic is to instantiate the magical mirror UI interactive program by instantiating the class. In the control, the public display information of the page is first refreshed by the function call, then the timer is called to control the execution process, the situation in front of the current mirror is detected periodically, and then the corresponding refresh program is executed according to the result of the timing detection, the specific code The design is as follows:

Class magic_mirroWindows(QtWidgets.QWidget):
Def __init__(self):
Super(magic_mirroWindows,self).__init__()
Self.new=Ui_MainWindow()
self.new.setupUi(self)

#save user video Info
self.push_video_userID=[]
self.videoPathList=[]

#self.viedoMsg.setWindowFlags(
self.zhishuUpdateTIme=0
#set Text
Self.tp=QtGui.QPalette(self)
self.tp.setColor(QtGui.QPalette.WindowText, QtGui.QColor(255,255,255))
Self.movie=QtGui.QMovie()
#default userID =0 ,camera and face model not find user InfomaTIon
self.current_userID=0
self.currentUserName=""
#default supper sound sensor status, suppper sound sensor not find people
Self.curren_su_status=1
#self.showPushInfo(4)
#set html view is black
self.new.webMessageText.setHtml(" ")
self.new.webMemorandum.setHtml(" ")
self.new.webZhishu.setHtml(" ")
Self.img=QtGui.QImage()
Self.manager = QtNetwork.QNetworkAccessManager()
#self.weather=getWeatherInfo()
Self.weather_updateOK=0
self.new.helloWelcome.setText("

Hello, welcom2...

")
self.Reply=self.manager.get(QtNetwork.QNetworkRequest(QtCore.QUrl("http://wthrcdn.etouch.cn/WeatherApi?city=%E6%B7%B1%E5%9C%B3")))
self.Reply.finished.connect(self.replayFinished)
Forecast_date_list.append(self.new.forecast_0_date)
Forecast_date_list.append(self.new.forecast_1_date)
Forecast_date_list.append(self.new.forecast_2_date)
Forecast_date_list.append(self.new.forecast_3_date)
Forecast_date_list.append(self.new.forecast_4_date)
Forecast_temp_list.append(self.new.forecast_0_temp)
Forecast_temp_list.append(self.new.forecast_1_temp)
Forecast_temp_list.append(self.new.forecast_2_temp)
Forecast_temp_list.append(self.new.forecast_3_temp)
Forecast_temp_list.append(self.new.forecast_4_temp)

Forecast_type_list.append(self.new.forecast_0_type)
Forecast_type_list.append(self.new.forecast_1_type)
Forecast_type_list.append(self.new.forecast_2_type)
Forecast_type_list.append(self.new.forecast_3_type)
Forecast_type_list.append(self.new.forecast_4_type)
#时间更新 self.TImer=QtCore.QTImer(self)
#self.count=0
Self.timer.timeout.connect(self.timerControl)
# test button
self.new.closeButton.setStyleSheet("QPushButton {border-image:url(:/images/close);}QPushButton:hover{border-image:url(:/images/close_on);}QPushButton:hover:pressed{border -image:url(:/images/close);}")
Time = QtCore.QDateTime.currentDateTime()
self.new.date.setPalette(self.tp)
self.new.date.setText(time.toString("yyyy-MM-dd"))

Palette1 = QtGui.QPalette(self)
palette1.setColor(self.backgroundRole(), QtGui.QColor(0,0,0))
self.setPalette(palette1)
self.setWindowTitle('w')
self.setWindowFlags(Qt.FramelessWindowHint)

Def paintEvent(self,QPaintEvent):
Painter=QtGui.QPainter(self)
#painter.drawPixmap(0, 0, pixmap) #ç”»UI

Def replayFinished(self):
Global weather
Print("weather replayFinished")
Qbyte = self.Reply.readAll()
Pbyte = bytes(qbyte.data())
Str(pbyte, encoding = "utf-8")
weatherInfo = bytes.decode(pbyte)
Weather=getWeatherInfo(weatherInfo)
self.updateUIdata(weather)
Def updateUIdata(self,weatherResult):
For i in range(0,5):
Forecast_date_list[i].setPalette(self.tp)
Forecast_date_list[i].setText(weatherResult.forecast_weather_info_date[i])
Forecast_temp_list[i].setPalette(self.tp)
Forecast_temp_list[i].setText(weatherResult.forecast_weather_info_low[i][3:6]+"~"+weatherResult.forecast_weather_info_high[i][3:6])
Forecast_type_list[i].setPalette(self.tp)
Forecast_type_list[i].setPixmap(QtGui.QPixmap(":/images/"+weatherResult.forecast_weather_info_dtype[i]))
self.new.city.setPalette(self.tp)
self.new.city.setText(weatherResult.weather_city)
self.new.temp.setPalette(self.tp)
self.new.temp.setText(weatherResult.weather_wendu+"°C")

self.new.fengli.setPalette(self.tp)
self.new.fengli.setText(weatherResult.weather_fengli)
self.new.fengxiang.setPalette(self.tp)
self.new.fengxiang.setText(weatherResult.weather_fengxiang)
self.new.shidu.setPalette(self.tp)
self.new.shidu.setText(weatherResult.weather_shidu)
self.new.label_3.setPalette(self.tp)
self.new.label_3.setText("humidity")
self.updateZhishu()
Self.timer.start(1000)
Def updateZhishu(self):
Global weather
If self.zhishuUpdateTime == 0:
i=random.randint(0,5)
Format="

%s:

%s

"
Values=(weather.weather_zhishu_name[i],weather.weather_zhishu_data[i])
Result= format % values
self.new.webZhishu.setHtml(result)
self.zhishuUpdateTime=5
Else:
self.zhishuUpdateTime=self.zhishuUpdateTime-1
# start Personalized Display by userID when system detect someone in front of the magic mirror
Def startPersonalizedDisplay(self,userID):
self.showPushInfo(userID)
#display user video msg
Def detectPeople(self):
MMDB=MagicMirrorDB("./db.sqlite3")
#get System Status
#statusName peopeleInfront
#statusValue{0,1,2},0 no people in front,1 have people in front of mirror but no detect people ID
#2 have people in front of mirror and detect people ID return ID
Result=MMDB.getSystemStatusValue("peopleInfront")
Print("peopleInfront")
Print(result)
If result[0]==1:
Return 0
Elif result[0]==2:
Print("front people ID:")
Print(result[1])
Return result[1] #return userID
Else:
Return -1
Def timerControl(self):
#self.updateZhishu()
# test have people
detectResult=self.detectPeople()
If detectResult==-1:
Print("no people")
Self.hide()
Elif detectResult==0:
self.showNormalInfo()
Self.show()
Print("have people but no ID")
Else:
Self.show()
Print(detectResult)
Print("in front of magicmirror")
If self.current_userID!=detectResult:
self.startPersonalizedDisplay(detectResult)
self.current_userID=detectResult
Else:
Return
Def showNormalInfo(self):
self.new.webMessageText.setHtml(" ")
self.new.webMemorandum.setHtml(" ")
self.new.helloWelcome.setText("

Hello, welcom2...

")

Def showPushInfo(self,userID):

MMDB=MMDB=MagicMirrorDB("db.sqlite3")
#update welcome info by userID
userName=MMDB.getUserName(userID)
Format="

Hello %s Welcome...

"
Values=(userName)
Result=format % values
self.new.helloWelcome.setText(result)
#update pushInfo
#infoID,pushID,infoSubject,infoContent,pushTime
msgList=MMDB.getTextMessageList(userID)
Print("test0")
Print(msgList)
Print("hello")
i=0
pushName=""
Msg_info=""
pushTime=""
msgStr=""
selfMsgStr=""
If msgList!=None:
For msg in msgList:
Print(msg)
Print("test1")
Print(msg)
pushName=MMDB.getUserName(msg[1])
Msg_info=msg[3]
pushTime=msg[4]
If msg[1]!=userID:
msgStr+=("

"+pushTime+"

"+"

"+pushName+"to you:"+"

"+msg_info+"

")
Else:
selfMsgStr+=("

"+msg_info+"

")

self.new.webMessageText.setHtml(" "+msgStr+" ")
self.new.webMemorandum.setHtml("
"+selfMsgStr+" ")
videoMsgList=MMDB.getUserVideoMessageList(self.current_userID)
Print("videoMsgList")
Print(videoMsgList)

#show message end get video message info
If videoMsgList!=None:
Print("start play video msg")
i=0
For videoMsg in videoMsgList:
If i%2==0:
Print(videoMsg)
self.push_video_userID.append(videoMsg)
Else:
Print(videoMsg)
self.videoPathList.append(videoMsg)
i=i+1
Videocmd="mplayer -vo x11 -playlist "
For video in self.videoPathList:
Videocmd=videocmd+' '+video
Os.system(videocmd)

Finally, you only need to write the main function to the file, start the class to instantiate to complete the startup of the interactive logic control program, that is, the startup of the entire UI interactive program. The specific main function code is as follows:

If __name__=="__main__":
Import sys
Import os

App=QtWidgets.QApplication(sys.argv)

Pixmap = QtGui.QPixmap(":/images/UI1")
Myshow=weatherWindows()
Myshow.show()

Sys.exit(app.exec_())

In this design, we separate the UI design and data design of the entire mirror. In the process of integration, we only need to start the ultrasound, camera monitor and database program, and then start the UI interactive program to complete the whole process. The integration of the model of the smart mirror.

Solar Battery PACK

What are the best batteries for solar? Batteries used in home energy storage typically are made with one of three chemical compositions: lead acid, lithium ion, and saltwater. In most cases, lithium ion batteries are the best option for a solar panel system, though other battery types can be more affordable.

If you install a solar battery today, you will likely need to replace it at least once to match the 25 to 30 year lifespan of your PV system. However, just as the lifespan of solar panels has increased significantly in the past decade, it is expected that solar batteries will follow suit as the market for energy storage solutions grows.

The most important ones to use during your evaluation are the battery`s capacity & power ratings, depth of discharge (DoD), round-trip efficiency, warranty, and manufacturer. Capacity is the total amount of electricity that a solar battery can store, measured in kilowatt-hours (kWh).

Batteries used in home energy storage typically are made with one of three chemical compositions: lead acid, lithium ion, and saltwater. In most cases, lithium ion batteries are the best option for a solar panel system, though other battery types can be more affordable.

12V Solar Battery,Solar Battery Storage,Solar Deep Cycle Battery,Lithium Batteries For Solar Systems 12V

Shenzhen Glida Electronics Co., Ltd. , https://www.szglida.com