Skip to content

Commit

Permalink
Update camflasher with copy/paste/resume
Browse files Browse the repository at this point in the history
  • Loading branch information
remibert committed Jan 9, 2022
1 parent a250c08 commit 7b2410a
Show file tree
Hide file tree
Showing 18 changed files with 795 additions and 343 deletions.
14 changes: 7 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"cwd" : "${workspaceFolder}/modules",
"justMyCode": false
},
{
"name": "CamFlasher",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/tools/camflasher/main.py",
"cwd": "${workspaceFolder}/tools/camflasher",
},
{
"name": "Editor",
"type": "python",
Expand All @@ -24,13 +31,6 @@
"request": "launch",
"program": "${workspaceFolder}/modules/lib/shell/shell.py",
"cwd" : "${workspaceFolder}/modules",
},
{
"name": "CamFlasher",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/tools/camflasher/main.py",
"cwd": "${workspaceFolder}/tools/camflasher",
}
]
}
38 changes: 11 additions & 27 deletions modules/lib/motion/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ def __init__(self):
# Turn on the led flash when the light goes down
self.light_compensation = True

# Notify motion
# Notify motion detection or problem to save on sd card
self.notify = True

# Notify motion state change
self.notify_state = True

# Empty mask is equal disable masking
self.mask = b""

Expand Down Expand Up @@ -524,10 +527,8 @@ async def detect(self):
# Capture motion
result = await self.capture()
else:
result = await self.fake_capture()
if result:
if self.motion:
self.motion.stop_light()
if self.motion:
self.motion.stop_light()
await uasyncio.sleep(10)
self.cadencer.refresh()

Expand All @@ -552,8 +553,11 @@ async def is_activated(self):

# If state of motion changed
if self.activated != result:
# Force garbage collection
collect()

# If notification enabled
if self.motion_config.notify:
if self.motion_config.notify_state:
if result:
await Notifier.notify(lang.motion_detection_on)
else:
Expand Down Expand Up @@ -604,26 +608,6 @@ def release_image(self):
if self.motion.index %30 == 0:
collect()

async def fake_capture(self):
""" Used to continue the dialogue with the camera, to avoid losing the link after too long a delay (The problem occurs once every ten days) """
result = False
try:
# Waits for the camera's availability
reserved = await video.Camera.reserve(self, timeout=60)

# If reserved
if reserved:
# Initialize motion detection
await self.init_motion()

# Captures an unnecessary image to maintain a dialogue with the camera
video.Camera.capture()
result = True
finally:
if reserved:
await video.Camera.unreserve(self)
return result

async def capture(self):
""" Capture motion """
result = False
Expand Down Expand Up @@ -667,7 +651,7 @@ async def capture(self):
Historic.set_motion_state(False)
result = True
else:
if self.motion_config.notify:
if self.motion_config.notify_state:
await Notifier.notify(lang.motion_detection_suspended)
result = True

Expand Down
2 changes: 1 addition & 1 deletion modules/lib/server/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def task():
""" Run the task """
# If configuration must be read
if Presence.config:
if Presence.configRefreshCounter % 7 == 0:
if Presence.configRefreshCounter % 7 == 0 or Presence.pollingDuration == Presence.SLOW_POLLING:
if Presence.config.is_changed():
if Presence.config.load() is False:
Presence.config.save()
Expand Down
2 changes: 1 addition & 1 deletion modules/lib/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async def synchronize_wan_ip(forced):
if newWanIp is not None:
# If wan ip must be notified
if (Server.context.wan_ip != newWanIp or forced):
await Server.context.notifier.notify("Lan Ip %s, Wan Ip %s"%(wifi.Station.get_info()[0],newWanIp))
await Server.context.notifier.notify("Lan Ip %s, Wan Ip %s, %s"%(wifi.Station.get_info()[0],newWanIp, useful.uptime()))
Server.context.wan_ip = newWanIp
wifi.Wifi.wan_connected()
else:
Expand Down
2 changes: 1 addition & 1 deletion modules/lib/tools/builddate.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
date=b'2021/11/27 20:06:55'
date=b'2022/01/09 11:17:29'
2 changes: 2 additions & 0 deletions modules/lib/tools/lang_english.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
detects_a_movement =b"Detects a movement if a number of different squares on two successive images is greater than or equal to"
motion_detection_sensitivity =b"Motion detection sensitivity"
notification =b"Notification"
notification_motion =b"Notify motion detection"
notification_state =b"Notify state change"
suspends_motion_detection =b"Suspends motion detection on the presence of an occupant"
turn_on_flash =b"Turn on the led flash when the light goes down"
pushover_on =b"Pushover notification on"
Expand Down
4 changes: 3 additions & 1 deletion modules/lib/tools/lang_french.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
item_server =b"Configuration"
item_notification =b"Notification"

menu_motion =b" Motion"
menu_motion =b" Mouvement"
item_motion =b" Configuration"
item_historic =b" Historique"
item_motion_onoff =b"Marche/Arr\xC3\xAAt"
Expand Down Expand Up @@ -54,6 +54,8 @@
detects_a_movement =b"D\xC3\xA9tecter un mouvement si le nombre de carr\xC3\xA9s diff\xC3\xA9rents entre deux images est \xC3\xA9gal ou plus grand que"
motion_detection_sensitivity =b"R\xC3\xA9gler la sensibilit\xC3\xA9 \xC3\xA0 la d\xC3\xA9tection de mouvement"
notification =b"Notifier"
notification_motion =b"Notifier d\xC3\xA9tection de mouvement"
notification_state =b"Notifier changement \xC3\xA9tat"
suspends_motion_detection =b"Suspendre la d\xC3\xA9tection de mouvement en pr\xC3\xA9sence d'occupants"
turn_on_flash =b"Allumer le flash LED lorsque la lumi\xC3\xA8re baisse"
pushover_on =b"Notification pushover activ\xC3\xA9e"
Expand Down
3 changes: 2 additions & 1 deletion modules/lib/webpage/motionpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ async def motion(request, response, args):
zone_masking(config, disabled), Br(),
Slider(text=lang.detects_a_movement, name=b"differences_detection", min=b"1", max=b"64", step=b"1", value=b"%d"%config.differences_detection, disabled=disabled),
Slider(text=lang.motion_detection_sensitivity, name=b"sensitivity", min=b"0", max=b"100", step=b"5", value=b"%d"%config.sensitivity, disabled=disabled),
Switch(text=lang.notification, name=b"notify", checked=config.notify, disabled=disabled),Br(),
Switch(text=lang.notification_motion, name=b"notify", checked=config.notify, disabled=disabled),Br(),
Switch(text=lang.notification_state, name=b"notify_state", checked=config.notify_state, disabled=disabled),Br(),
Switch(text=lang.suspends_motion_detection, name=b"suspend_on_presence", checked=config.suspend_on_presence, disabled=disabled),Br(),
Switch(text=lang.turn_on_flash, name=b"light_compensation", checked=config.light_compensation, disabled=disabled),Br(),
submit)
Expand Down
4 changes: 3 additions & 1 deletion tools/camflasher/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ def execute(command):
elif platform == "darwin":
ICONS = "icons/camflasher.icns"
TARGET = "osx"

execute("pyuic%(UIC)s camflasher.ui -o camflasher.py"%globals())
execute("pyuic%(UIC)s dialogflash.ui -o dialogflash.py"%globals())
execute("pyuic%(UIC)s dialogabout.ui -o dialogabout.py"%globals())

spec_file = open("build-%(TARGET)s.spec"%globals(),"w")
spec_file.write(spec%globals())
Expand Down
202 changes: 94 additions & 108 deletions tools/camflasher/camflasher.py
Original file line number Diff line number Diff line change
@@ -1,108 +1,94 @@
# Form implementation generated from reading ui file 'camflasher.ui'
#
# Created by: PyQt6 UI code generator 6.2.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_win_main(object):
def setupUi(self, win_main):
win_main.setObjectName("win_main")
win_main.resize(800, 600)
win_main.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.DefaultContextMenu)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("icons/camflasher.ico"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
win_main.setWindowIcon(icon)
self.lay_window = QtWidgets.QWidget(win_main)
self.lay_window.setObjectName("lay_window")
self.gridLayout_2 = QtWidgets.QGridLayout(self.lay_window)
self.gridLayout_2.setContentsMargins(5, 5, 5, 5)
self.gridLayout_2.setObjectName("gridLayout_2")
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.lbl_port = QtWidgets.QLabel(self.lay_window)
self.lbl_port.setMaximumSize(QtCore.QSize(80, 16777215))
self.lbl_port.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter)
self.lbl_port.setObjectName("lbl_port")
self.gridLayout.addWidget(self.lbl_port, 1, 0, 1, 1)
self.cbo_port = QtWidgets.QComboBox(self.lay_window)
self.cbo_port.setObjectName("cbo_port")
self.gridLayout.addWidget(self.cbo_port, 1, 1, 1, 2)
self.chk_erase = QtWidgets.QCheckBox(self.lay_window)
self.chk_erase.setObjectName("chk_erase")
self.gridLayout.addWidget(self.chk_erase, 1, 6, 1, 1)
self.cbo_baud = QtWidgets.QComboBox(self.lay_window)
self.cbo_baud.setObjectName("cbo_baud")
self.gridLayout.addWidget(self.cbo_baud, 1, 4, 1, 2)
self.lbl_firmware = QtWidgets.QLabel(self.lay_window)
self.lbl_firmware.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter)
self.lbl_firmware.setObjectName("lbl_firmware")
self.gridLayout.addWidget(self.lbl_firmware, 0, 0, 1, 1)
self.lbl_baud = QtWidgets.QLabel(self.lay_window)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lbl_baud.sizePolicy().hasHeightForWidth())
self.lbl_baud.setSizePolicy(sizePolicy)
self.lbl_baud.setMaximumSize(QtCore.QSize(16777215, 16777213))
self.lbl_baud.setLayoutDirection(QtCore.Qt.LayoutDirection.LeftToRight)
self.lbl_baud.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter)
self.lbl_baud.setObjectName("lbl_baud")
self.gridLayout.addWidget(self.lbl_baud, 1, 3, 1, 1)
self.but_flash = QtWidgets.QPushButton(self.lay_window)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
self.but_flash.setFont(font)
self.but_flash.setObjectName("but_flash")
self.gridLayout.addWidget(self.but_flash, 1, 7, 1, 1)
self.but_firmware = QtWidgets.QPushButton(self.lay_window)
self.but_firmware.setEnabled(True)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.but_firmware.sizePolicy().hasHeightForWidth())
self.but_firmware.setSizePolicy(sizePolicy)
self.but_firmware.setAcceptDrops(True)
self.but_firmware.setObjectName("but_firmware")
self.gridLayout.addWidget(self.but_firmware, 0, 7, 1, 1)
self.txt_firmware = QtWidgets.QLineEdit(self.lay_window)
self.txt_firmware.setObjectName("txt_firmware")
self.gridLayout.addWidget(self.txt_firmware, 0, 1, 1, 6)
self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)
self.txt_result = QtWidgets.QTextBrowser(self.lay_window)
font = QtGui.QFont()
font.setFamily("Courier")
self.txt_result.setFont(font)
self.txt_result.setObjectName("txt_result")
self.gridLayout_2.addWidget(self.txt_result, 1, 0, 1, 1)
win_main.setCentralWidget(self.lay_window)

self.retranslateUi(win_main)
QtCore.QMetaObject.connectSlotsByName(win_main)
win_main.setTabOrder(self.txt_firmware, self.but_firmware)
win_main.setTabOrder(self.but_firmware, self.cbo_port)
win_main.setTabOrder(self.cbo_port, self.cbo_baud)
win_main.setTabOrder(self.cbo_baud, self.chk_erase)
win_main.setTabOrder(self.chk_erase, self.but_flash)
win_main.setTabOrder(self.but_flash, self.txt_result)

def retranslateUi(self, win_main):
_translate = QtCore.QCoreApplication.translate
win_main.setWindowTitle(_translate("win_main", "CamFlasher"))
self.lbl_port.setText(_translate("win_main", "Serial port"))
self.cbo_port.setToolTip(_translate("win_main", "Select device serial port"))
self.chk_erase.setToolTip(_translate("win_main", "Check to erase the flash content before write firmware"))
self.chk_erase.setText(_translate("win_main", "Erase flash"))
self.cbo_baud.setToolTip(_translate("win_main", "Select flash baud rate"))
self.lbl_firmware.setText(_translate("win_main", "Firmware"))
self.lbl_baud.setText(_translate("win_main", "Baud rate"))
self.but_flash.setToolTip(_translate("win_main", "Start the flash of firmware"))
self.but_flash.setText(_translate("win_main", "Flash firmware"))
self.but_firmware.setToolTip(_translate("win_main", "Select firmware file"))
self.but_firmware.setText(_translate("win_main", "..."))
self.txt_firmware.setToolTip(_translate("win_main", "Enter firmware file"))
# Form implementation generated from reading ui file 'camflasher.ui'
#
# Created by: PyQt6 UI code generator 6.2.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_main_window(object):
def setupUi(self, main_window):
main_window.setObjectName("main_window")
main_window.resize(800, 600)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("icons/camflasher.ico"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
main_window.setWindowIcon(icon)
self.main_layout = QtWidgets.QWidget(main_window)
self.main_layout.setObjectName("main_layout")
self.gridLayout = QtWidgets.QGridLayout(self.main_layout)
self.gridLayout.setContentsMargins(5, 5, 5, 5)
self.gridLayout.setObjectName("gridLayout")
self.combo_port = QtWidgets.QComboBox(self.main_layout)
self.combo_port.setEnabled(True)
self.combo_port.setObjectName("combo_port")
self.gridLayout.addWidget(self.combo_port, 0, 1, 1, 1)
self.output = QtWidgets.QTextBrowser(self.main_layout)
self.output.setEnabled(True)
font = QtGui.QFont()
font.setFamily("Courier")
self.output.setFont(font)
self.output.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.CursorShape.ArrowCursor))
self.output.setReadOnly(False)
self.output.setObjectName("output")
self.gridLayout.addWidget(self.output, 1, 0, 1, 2)
self.label_port = QtWidgets.QLabel(self.main_layout)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_port.sizePolicy().hasHeightForWidth())
self.label_port.setSizePolicy(sizePolicy)
self.label_port.setObjectName("label_port")
self.gridLayout.addWidget(self.label_port, 0, 0, 1, 1)
main_window.setCentralWidget(self.main_layout)
self.menu_bar = QtWidgets.QMenuBar(main_window)
self.menu_bar.setGeometry(QtCore.QRect(0, 0, 800, 24))
self.menu_bar.setObjectName("menu_bar")
self.menu_flasher = QtWidgets.QMenu(self.menu_bar)
self.menu_flasher.setObjectName("menu_flasher")
self.menu_output = QtWidgets.QMenu(self.menu_bar)
self.menu_output.setObjectName("menu_output")
self.menu_info = QtWidgets.QMenu(self.menu_bar)
self.menu_info.setObjectName("menu_info")
main_window.setMenuBar(self.menu_bar)
self.action_flash = QtGui.QAction(main_window)
self.action_flash.setObjectName("action_flash")
self.action_copy = QtGui.QAction(main_window)
self.action_copy.setObjectName("action_copy")
self.action_paste = QtGui.QAction(main_window)
self.action_paste.setObjectName("action_paste")
self.action_pause = QtGui.QAction(main_window)
self.action_pause.setObjectName("action_pause")
self.action_resume = QtGui.QAction(main_window)
self.action_resume.setObjectName("action_resume")
self.action_about = QtGui.QAction(main_window)
self.action_about.setObjectName("action_about")
self.menu_flasher.addAction(self.action_flash)
self.menu_output.addAction(self.action_copy)
self.menu_output.addAction(self.action_paste)
self.menu_output.addAction(self.action_pause)
self.menu_output.addAction(self.action_resume)
self.menu_info.addAction(self.action_about)
self.menu_bar.addAction(self.menu_flasher.menuAction())
self.menu_bar.addAction(self.menu_output.menuAction())
self.menu_bar.addAction(self.menu_info.menuAction())

self.retranslateUi(main_window)
QtCore.QMetaObject.connectSlotsByName(main_window)

def retranslateUi(self, main_window):
_translate = QtCore.QCoreApplication.translate
main_window.setWindowTitle(_translate("main_window", "CamFlasher"))
self.combo_port.setToolTip(_translate("main_window", "Select device serial port"))
self.label_port.setText(_translate("main_window", "Serial port"))
self.menu_flasher.setTitle(_translate("main_window", "Flasher"))
self.menu_output.setTitle(_translate("main_window", "Output"))
self.menu_info.setTitle(_translate("main_window", "Info"))
self.action_flash.setText(_translate("main_window", "Flash"))
self.action_copy.setText(_translate("main_window", " Copy"))
self.action_paste.setText(_translate("main_window", " Paste"))
self.action_pause.setText(_translate("main_window", " Pause"))
self.action_resume.setText(_translate("main_window", " Resume"))
self.action_about.setText(_translate("main_window", "About"))
Loading

0 comments on commit 7b2410a

Please sign in to comment.