diff --git a/vbms32/vbms32.lisp b/vbms32/vbms32.lisp index 1e059cd7..9fb6bc75 100644 --- a/vbms32/vbms32.lisp +++ b/vbms32/vbms32.lisp @@ -61,17 +61,20 @@ (defun bms-current () (- (bms-get-current))) (defun beep (times dt) { - (mutex-lock buz-mutex) - - (loopwhile (> times 0) { - (pwm-set-duty 0.5 0) - (sleep dt) - (pwm-set-duty 0.0 0) - (sleep dt) - (setq times (- times 1)) - }) + (if (= (bms-get-param 'beeper_enabled) 1) + { + (mutex-lock buz-mutex) + + (loopwhile (> times 0) { + (pwm-set-duty 0.5 0) + (sleep dt) + (pwm-set-duty 0.0 0) + (sleep dt) + (setq times (- times 1)) + }) - (mutex-unlock buz-mutex) + (mutex-unlock buz-mutex) + }) }) (def rtc-val-magic 115) diff --git a/vbms32_micro/ui.qml.in b/vbms32_micro/ui.qml.in index 58a4815b..63b737f4 100644 --- a/vbms32_micro/ui.qml.in +++ b/vbms32_micro/ui.qml.in @@ -33,6 +33,10 @@ Item { property Commands mCommands: VescIf.commands() property ConfigParams mMcConf: VescIf.mcConfig() property ConfigParams mCustomConf: VescIf.customConfig(0) + + Component.onVisibleChanged: { + mCommands.sendCustomAppData("(send-config)"); + } ColumnLayout { id: gaugeColumn @@ -62,6 +66,14 @@ Item { Layout.fillWidth: true Layout.fillHeight: true } + CheckBox { + text: "Beeper Enabled" + checkable: true + checked: mainItem.state.beeperEnabled + onClicked: { + commands.sendDataEnableBeeper(checked); + } + } Rectangle { Layout.fillWidth: true Layout.preferredHeight: 2 @@ -84,4 +96,29 @@ Item { } } } + + Connections { + id: commands + target: mCommands + + function sendDataEnableBeeper(value) { + mCommands.sendCustomAppData("(beeper-enabled " + value + ")"); + } + + function onCustomAppDataReceived(data) { + var str = data.toString() + + if (str.startsWith("settings")) { + var tokens = str.split(" ") + mainItem.state.beeperEnabled = (Number(tokens[1])) ? true : false + } + } + } + + property var state: QtObject { + id: state + + property bool beeperEnabled: true + } + } diff --git a/vbms32_micro/vbms32_micro.lisp b/vbms32_micro/vbms32_micro.lisp index 26095285..453ddee8 100644 --- a/vbms32_micro/vbms32_micro.lisp +++ b/vbms32_micro/vbms32_micro.lisp @@ -34,6 +34,7 @@ (soc . 0.5) (charge-fault . false) (updated . false) + (beeper-en . true) )) (def is-bal false) @@ -84,24 +85,38 @@ loopwhile-thd (defun bms-current () (* (bms-get-current) -0.2)) (defun beep (times dt) { - (mutex-lock buz-mutex) - - (loopwhile (> times 0) { - (pwm-set-duty 0.5 0) - (sleep dt) - (pwm-set-duty 0.0 0) - (sleep dt) - (setq times (- times 1)) + (if (assoc rtc-val 'beeper-en) + { + (mutex-lock buz-mutex) + + (loopwhile (> times 0) { + (pwm-set-duty 0.5 0) + (sleep dt) + (pwm-set-duty 0.0 0) + (sleep dt) + (setq times (- times 1)) + }) + + (mutex-unlock buz-mutex) }) +}) - (mutex-unlock buz-mutex) +(defun beeper-enabled (enabled) { + (setassoc rtc-val 'beeper-en enabled) }) -(def rtc-val-magic 115) +(defun send-config () { + (var config-string "settings ") + (setq config-string (str-merge config-string (if (assoc rtc-val 'beeper-en) "1" "0"))) + (send-data config-string) +}) + +(def rtc-val-magic 116) ; If in deepsleep, this will return 4 ; (bms-direct-cmd 1 0x00) + ; Exit deepsleep ; (bms-subcmd-cmdonly 1 0x000e) @@ -820,6 +835,7 @@ loopwhile-thd (setq bal-ok true) (setq bal-ok false) )) + ((event-data-rx ? data) (eval (read data))) (_ nil) ;((? a) (print a)) ))) @@ -903,6 +919,7 @@ loopwhile-thd (event-enable 'event-bms-reset-cnt) (event-enable 'event-bms-force-bal) (event-enable 'event-bms-zero-ofs) + (event-enable 'event-data-rx) (set-bms-val 'bms-cell-num cell-num) (set-bms-val 'bms-can-id (can-local-id)) diff --git a/vbms32_micro/version b/vbms32_micro/version index 7dea76ed..6d7de6e6 100644 --- a/vbms32_micro/version +++ b/vbms32_micro/version @@ -1 +1 @@ -1.0.1 +1.0.2 diff --git a/vbms_harmony16/harmony16.lisp b/vbms_harmony16/harmony16.lisp index b9d21126..602b9f2b 100644 --- a/vbms_harmony16/harmony16.lisp +++ b/vbms_harmony16/harmony16.lisp @@ -90,12 +90,15 @@ loopwhile-thd (defun bms-current () (* (bms-get-current) -2.0)) (defun beep (times dt) { - (loopwhile (> times 0) { - (pwm-set-duty 0.5 0) - (sleep dt) - (pwm-set-duty 0.0 0) - (sleep dt) - (setq times (- times 1)) + (if (= (bms-get-param 'beeper_enabled) 1) + { + (loopwhile (> times 0) { + (pwm-set-duty 0.5 0) + (sleep dt) + (pwm-set-duty 0.0 0) + (sleep dt) + (setq times (- times 1)) + }) }) }) diff --git a/vbms_harmony32/harmony32.lisp b/vbms_harmony32/harmony32.lisp index aded1ab8..ca98ef2f 100644 --- a/vbms_harmony32/harmony32.lisp +++ b/vbms_harmony32/harmony32.lisp @@ -87,12 +87,15 @@ loopwhile-thd (defun bms-current () (* (bms-get-current) -2.0)) (defun beep (times dt) { - (loopwhile (> times 0) { - (pwm-set-duty 0.5 0) - (sleep dt) - (pwm-set-duty 0.0 0) - (sleep dt) - (setq times (- times 1)) + (if (= (bms-get-param 'beeper_enabled) 1) + { + (loopwhile (> times 0) { + (pwm-set-duty 0.5 0) + (sleep dt) + (pwm-set-duty 0.0 0) + (sleep dt) + (setq times (- times 1)) + }) }) })