From 8f8f42990d3693a237167fc6560ba98a0b4973a5 Mon Sep 17 00:00:00 2001 From: Softonik Date: Tue, 22 Nov 2022 23:58:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=AF=D1=80=D0=BA=D0=BE=D1=81=D1=82=D1=8C:=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=D0=BB=D0=B5=D0=BC=D1=8B=D0=B5=20=D1=80=D0=B0=D0=BC=D0=BA?= =?UTF-8?q?=D0=B8=20=D1=8F=D1=80=D0=BA=D0=BE=D1=81=D1=82=D0=B8=20=D0=B8=20?= =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=B2=D0=BA=D0=BB?= =?UTF-8?q?/=D0=B2=D1=8B=D0=BA=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go.h | 16 ++++++++++------ pkg/app/main.go | 36 +++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/main.go.h b/main.go.h index a9390bb..9bf49f7 100644 --- a/main.go.h +++ b/main.go.h @@ -10,25 +10,26 @@ void Yarkost(int i); void Enable(); void Disable(); void TaskSveta(); +void PropustitRaz(); -const int MAX_YARKOST = 100; const int MIN_YARKOST = 0; const unsigned long VREMYA_SVETA = 20000; TickType_t loopBlockTime = pdMS_TO_TICKS(1000); int vklYarkBlockTime = 10; TickType_t vyklYarkBlockTime = pdMS_TO_TICKS(50); int yarkost; unsigned long kogdaVyklyuchit; void initSvet() { - yarkost=0; kogdaVyklyuchit=0; Vyklyuchit(); +const int MAX_YARKOST = 25; const int MIN_YARKOST = 15; const int VREMYA_VKL = 2000; const unsigned long VREMYA_SVETA = 10000; const int VREMYA_VYKL = 10000; const int DIFF_YARKOST = MAX_YARKOST-MIN_YARKOST; TickType_t loopBlockTime = pdMS_TO_TICKS(1000); TickType_t vyklYarkBlockTime = pdMS_TO_TICKS(VREMYA_VYKL/DIFF_YARKOST); int yarkost; unsigned long kogdaVyklyuchit; void initSvet() { + yarkost=MIN_YARKOST; kogdaVyklyuchit=0; Vyklyuchit(); } void DvizhEst() { - kogdaVyklyuchit=millis()+VREMYA_SVETA; if (!Vklyucheno()) { if (DEBUG) { Serial.println("Vkl svet"); } PlavnoVklyuchit(); } + kogdaVyklyuchit=millis()+VREMYA_SVETA; if (DEBUG) { Serial.println("Vkl svet"); } PlavnoVklyuchit(); } void DvizhaNet() { if (kogdaVyklyuchit>millis()) { return; } if (Vklyucheno()) { if (DEBUG) { Serial.println("Vykl"); } PlavnoVyklyuchit(); } } void PlavnoVklyuchit() { - Enable(); for(yarkost=yarkost; yarkost<=MAX_YARKOST; yarkost++) {Yarkost(yarkost); if (DEBUG) { Serial.println(yarkost); } delay(vklYarkBlockTime);} Vklyuchit(); + Enable(); for(yarkost=yarkost; yarkost<=MAX_YARKOST; yarkost++) {Yarkost(yarkost); if (DEBUG) { Serial.println(yarkost); } delay(VREMYA_VKL/DIFF_YARKOST);} Vklyuchit(); } void PlavnoVyklyuchit() { int v; for(yarkost=yarkost; yarkost>=MIN_YARKOST; yarkost--) {Yarkost(yarkost); if (DEBUG) { Serial.println(yarkost); } v=ulTaskNotifyTake(0,vyklYarkBlockTime); if (v>0) { DvizhEst(); return; }} Vyklyuchit(); } bool Vklyucheno() { - return yarkost>0; + return yarkost>MIN_YARKOST; } void Vklyuchit() { Yarkost(MAX_YARKOST); Enable(); @@ -46,5 +47,8 @@ void Disable() { digitalWrite(SVET_ONOFF_PIN,0); } void TaskSveta() { - int v; while(1) {v=ulTaskNotifyTake(0,loopBlockTime); if (v>0) { DvizhEst(); } else { DvizhaNet(); }} + int v; PropustitRaz(); while(1) {v=ulTaskNotifyTake(0,loopBlockTime); if (v>0) { DvizhEst(); } else { DvizhaNet(); }} +} +void PropustitRaz() { + ulTaskNotifyTake(0,loopBlockTime); } diff --git a/pkg/app/main.go b/pkg/app/main.go index 6104f6d..3e70bbc 100644 --- a/pkg/app/main.go +++ b/pkg/app/main.go @@ -10,21 +10,26 @@ import ( // 150 - примерно то же, что и 255 (должно быть те 1.25В где-то там же) // 100 - средненько +// 50 - приглушённо -const MAX_YARKOST int = 100 -const MIN_YARKOST int = 0 +const MAX_YARKOST int = 25 +const MIN_YARKOST int = 15 -const VREMYA_SVETA uint32 = 20000 +const VREMYA_VKL int = 2000 +const VREMYA_SVETA uint32 = 10000 +const VREMYA_VYKL int = 10000 + +const DIFF_YARKOST int = MAX_YARKOST - MIN_YARKOST var loopBlockTime task.TickType = task.MS_TO_TICKS(1000) -var vklYarkBlockTime int = 10 -var vyklYarkBlockTime task.TickType = task.MS_TO_TICKS(50) + +var vyklYarkBlockTime task.TickType = task.MS_TO_TICKS(VREMYA_VYKL / DIFF_YARKOST) var yarkost int var kogdaVyklyuchit uint32 func initSvet() { - yarkost = 0 + yarkost = MIN_YARKOST kogdaVyklyuchit = 0 Vyklyuchit() @@ -33,12 +38,10 @@ func initSvet() { func DvizhEst() { kogdaVyklyuchit = timer.Millis() + VREMYA_SVETA - if !Vklyucheno() { - if DEBUG { - serial.Println("Vkl svet") - } - PlavnoVklyuchit() + if DEBUG { + serial.Println("Vkl svet") } + PlavnoVklyuchit() } func DvizhaNet() { if kogdaVyklyuchit > timer.Millis() { @@ -61,7 +64,7 @@ func PlavnoVklyuchit() { if DEBUG { serial.Println(yarkost) } - timer.Delay(vklYarkBlockTime) + timer.Delay(VREMYA_VKL / DIFF_YARKOST) } Vklyuchit() @@ -80,11 +83,12 @@ func PlavnoVyklyuchit() { return } } + Vyklyuchit() } func Vklyucheno() bool { - return yarkost > 0 + return yarkost > MIN_YARKOST } func Vklyuchit() { Yarkost(MAX_YARKOST) @@ -109,6 +113,8 @@ func Disable() { func TaskSveta() { var v int + PropustitRaz() + for { /* Block to wait for a notification. Here the RTOS task notification is being used as a counting semaphore. @@ -127,3 +133,7 @@ func TaskSveta() { } } } + +func PropustitRaz() { + task.TaskNotifyTake(0, loopBlockTime) +}