From c8796b592ee9507b71674e75c25ec30d08dcee1b Mon Sep 17 00:00:00 2001 From: falconArdente Date: Thu, 10 Oct 2024 23:27:28 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=BB=D0=B5=D1=80:=20=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BE=D1=82=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B0=D0=B2=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=B9=D0=BA=D0=B8=20=D0=B2=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=D0=BC=20=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?;=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=B7=D0=B0=D0=B2=D0=BF=D1=83=D1=81=D0=BA=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=20=D0=BF=D1=80=D0=B8=20=D0=B2=D1=8B=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=D0=B5=20=D0=B8=D0=B7=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CameraLightTurnsSupplyController.cpp | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/VideoCamModule/CameraLightTurnsSupplyController.cpp b/VideoCamModule/CameraLightTurnsSupplyController.cpp index 9506358..c2abc0f 100644 --- a/VideoCamModule/CameraLightTurnsSupplyController.cpp +++ b/VideoCamModule/CameraLightTurnsSupplyController.cpp @@ -25,12 +25,21 @@ void CameraLightTurnsSupplyController::initiate() { pinMode(outRightFogLight, OUTPUT); pinMode(outRelayCameraSwitch, OUTPUT); pinMode(outControllerLed, OUTPUT); + digitalWrite(outAngelEyeRight, LOW); + digitalWrite(outAngelEyeLeft, LOW); + digitalWrite(outCautionSignal, LOW); + digitalWrite(outDisplayOn, LOW); + digitalWrite(outLeftFogLight, LOW); + digitalWrite(outRightFogLight, LOW); + digitalWrite(outRelayCameraSwitch, LOW); + digitalWrite(outControllerLed, LOW); reverseGear = Lever(A1, &timings); leftTurnLever = Lever(A0, &timings); rightTurnLever = Lever(12, &timings); setCameraState(CAMS_OFF); getTimingsFromStorage(); getGearsState(); + sendCurrentState(); } void CameraLightTurnsSupplyController::updateTimings(Timings newTimings) { @@ -116,13 +125,19 @@ void CameraLightTurnsSupplyController::checkGearsLoopStep() { case TEST_MODE: break; } - if (!reverseGear.isOn() && cameraState != TEST_MODE)digitalWrite(outCautionSignal, LOW); + if (!reverseGear.isOn() && cameraState != TEST_MODE && + (digitalRead(outCautionSignal) == HIGH)) { + digitalWrite(outCautionSignal, LOW); + isChangedFlag = true; + } } void CameraLightTurnsSupplyController::setCameraState(CameraStates state) { if (cameraState == state)return; + switch (state) { case CAMS_OFF: + if (cameraState == TEST_MODE)asm volatile("jmp 0x00"); //return to code start digitalWrite(outDisplayOn, LOW); digitalWrite(outRelayCameraSwitch, LOW); digitalWrite(outCautionSignal, LOW); @@ -147,24 +162,24 @@ void CameraLightTurnsSupplyController::setCameraState(CameraStates state) { } void CameraLightTurnsSupplyController::turnFogLightOn() { - FogLightState newFogsState=ALL_OFF; + FogLightState newFogsState = ALL_OFF; if (leftTurnLever.isOn()) { digitalWrite(outLeftFogLight, HIGH); digitalWrite(outRightFogLight, LOW); - newFogsState=LEFT_ON; + newFogsState = LEFT_ON; } else if (rightTurnLever.isOn()) { digitalWrite(outRightFogLight, HIGH); digitalWrite(outLeftFogLight, LOW); - newFogsState=RIGHT_ON; + newFogsState = RIGHT_ON; } else { digitalWrite(outLeftFogLight, HIGH); digitalWrite(outRightFogLight, HIGH); - newFogsState=BOTH_ON; + newFogsState = BOTH_ON; + } + if (newFogsState != fogLightsState) { + fogLightsState = newFogsState; + isChangedFlag = true; } - if(newFogsState!=fogLightsState){ - fogLightsState=newFogsState; - isChangedFlag = true; - } } void CameraLightTurnsSupplyController::turnOffFogLight() { @@ -203,11 +218,9 @@ void CameraLightTurnsSupplyController::getTimingsFromStorage() { if (checkByte == 0) { if (!(timings == timingsFromStorage)) timings = timingsFromStorage; } else { - setCameraState(TEST_MODE); digitalWrite(outCautionSignal, HIGH); - delay(1500); + delay(300); digitalWrite(outCautionSignal, LOW); - setCameraState(CAMS_OFF); } } From a5124fe22b1122803d99db2aa405740607ddf9fd Mon Sep 17 00:00:00 2001 From: falconArdente Date: Fri, 11 Oct 2024 23:04:54 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8=20=D0=B2=20PacketsMapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../carcamerasandlightsbluetooth/data/map/PacketsMapper.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/example/carcamerasandlightsbluetooth/data/map/PacketsMapper.kt b/src/main/java/com/example/carcamerasandlightsbluetooth/data/map/PacketsMapper.kt index 6c625e1..0f16a68 100644 --- a/src/main/java/com/example/carcamerasandlightsbluetooth/data/map/PacketsMapper.kt +++ b/src/main/java/com/example/carcamerasandlightsbluetooth/data/map/PacketsMapper.kt @@ -1,6 +1,5 @@ package com.example.carcamerasandlightsbluetooth.data.map -import android.util.Log import com.example.carcamerasandlightsbluetooth.data.CameraState import com.example.carcamerasandlightsbluetooth.data.bluetooth.Constants import com.example.carcamerasandlightsbluetooth.data.dto.DeviceReports @@ -116,7 +115,6 @@ object PacketsMapper { fun commandToPacket(command: ControlCommand): ByteArray { val bits = BitSet(16) with(command) { - Log.d("SimpleBle", "c Bits: ${command.cameraState}") val cameraBits = BitSet(2) when (command.cameraState) { CameraState.CAMS_OFF -> Unit @@ -127,7 +125,6 @@ object PacketsMapper { cameraBits.set(1) } } - Log.d("SimpleBle", "c Bits: ${cameraBits.toByteArray().toList()}") bits[0] = true bits[1] = false bits[2] = cautionIsOn From 9cf1c60d1144c8086d28a014e1d7618cf4cc46df Mon Sep 17 00:00:00 2001 From: falconArdente Date: Sun, 13 Oct 2024 23:54:53 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=D0=B0,=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=20=D1=84=D0=B0=D0=BA=D1=82=D1=83=D1=80=D1=83=20BCM?= =?UTF-8?q?=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=BE=D0=B1=D0=B8=D0=BB=D1=8F?= =?UTF-8?q?.=20=D0=9A=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20=D0=B0=D0=B2=D0=B0?= =?UTF-8?q?=D1=80=D0=B8=D0=B9=D0=BA=D0=B8=20=D0=B1=D0=B5=D0=B7=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CameraLightTurnsSupplyController.cpp | 34 ++++++++++++------- .../CameraLightTurnsSupplyController.h | 4 +++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/VideoCamModule/CameraLightTurnsSupplyController.cpp b/VideoCamModule/CameraLightTurnsSupplyController.cpp index c2abc0f..706ecc9 100644 --- a/VideoCamModule/CameraLightTurnsSupplyController.cpp +++ b/VideoCamModule/CameraLightTurnsSupplyController.cpp @@ -5,7 +5,7 @@ #include const int TIMINGS_ADDR = 0; - +const int CAUTION_BUTTON_DELAY =450; CameraLightTurnsSupplyController::CameraLightTurnsSupplyController() {} void CameraLightTurnsSupplyController::setCommunicationDevice(CommunicationUnit network) { @@ -36,6 +36,7 @@ void CameraLightTurnsSupplyController::initiate() { reverseGear = Lever(A1, &timings); leftTurnLever = Lever(A0, &timings); rightTurnLever = Lever(12, &timings); + cautionIsTimeStamp=millis(); setCameraState(CAMS_OFF); getTimingsFromStorage(); getGearsState(); @@ -49,7 +50,8 @@ void CameraLightTurnsSupplyController::updateTimings(Timings newTimings) { void CameraLightTurnsSupplyController::executeCommand(CommunicationUnit::ControlCommandSet command) { - digitalWrite(outCautionSignal, command.cautionIsOn); + if(cautionIsPressed!=command.cautionIsOn)pushCautionButton(); + digitalWrite(outLeftFogLight, command.leftFogIsOn); digitalWrite(outRightFogLight, command.rightFogIsOn); digitalWrite(outRelayCameraSwitch, command.relayIsOn); @@ -125,13 +127,21 @@ void CameraLightTurnsSupplyController::checkGearsLoopStep() { case TEST_MODE: break; } - if (!reverseGear.isOn() && cameraState != TEST_MODE && - (digitalRead(outCautionSignal) == HIGH)) { - digitalWrite(outCautionSignal, LOW); + if (!reverseGear.isOn() && cameraState != TEST_MODE && cautionIsPressed) { + pushCautionButton(); isChangedFlag = true; } +// for caution no fixation sequence + if (digitalRead(outCautionSignal) == HIGH + && (millis()> cautionIsTimeStamp+CAUTION_BUTTON_DELAY)){ + digitalWrite(outCautionSignal, LOW); + } +} +void CameraLightTurnsSupplyController::pushCautionButton(){ + if (cautionIsPressed) cautionIsPressed=false; else cautionIsPressed=true; + cautionIsTimeStamp=millis(); + digitalWrite(outCautionSignal, HIGH); } - void CameraLightTurnsSupplyController::setCameraState(CameraStates state) { if (cameraState == state)return; @@ -140,7 +150,7 @@ void CameraLightTurnsSupplyController::setCameraState(CameraStates state) { if (cameraState == TEST_MODE)asm volatile("jmp 0x00"); //return to code start digitalWrite(outDisplayOn, LOW); digitalWrite(outRelayCameraSwitch, LOW); - digitalWrite(outCautionSignal, LOW); + if(cautionIsPressed) pushCautionButton(); turnOffFogLight(); break; case REAR_CAM_ON: @@ -148,12 +158,12 @@ void CameraLightTurnsSupplyController::setCameraState(CameraStates state) { digitalWrite(outRelayCameraSwitch, LOW); turnOffFogLight(); if (!leftTurnLever.isOn() && !rightTurnLever.isOn()) - digitalWrite(outCautionSignal, HIGH); + if(!cautionIsPressed) pushCautionButton(); break; case FRONT_CAM_ON: // Fog lights turn on logic is inside checkGearsLoopStep case digitalWrite(outDisplayOn, HIGH); digitalWrite(outRelayCameraSwitch, HIGH); - digitalWrite(outCautionSignal, LOW); + if(cautionIsPressed) pushCautionButton(); break; } cameraState = state; @@ -218,9 +228,9 @@ void CameraLightTurnsSupplyController::getTimingsFromStorage() { if (checkByte == 0) { if (!(timings == timingsFromStorage)) timings = timingsFromStorage; } else { - digitalWrite(outCautionSignal, HIGH); - delay(300); - digitalWrite(outCautionSignal, LOW); + // digitalWrite(outCautionSignal, HIGH); + // delay(300); + // digitalWrite(outCautionSignal, LOW); } } diff --git a/VideoCamModule/CameraLightTurnsSupplyController.h b/VideoCamModule/CameraLightTurnsSupplyController.h index 3b15239..fbacde7 100644 --- a/VideoCamModule/CameraLightTurnsSupplyController.h +++ b/VideoCamModule/CameraLightTurnsSupplyController.h @@ -52,6 +52,8 @@ class CameraLightTurnsSupplyController : public ControllerForCommUnitInterface { RIGHT_ON, BOTH_ON } fogLightsState=ALL_OFF; + bool cautionIsPressed=false; + long cautionIsTimeStamp=0; //input gears Lever reverseGear; Lever leftTurnLever; @@ -70,6 +72,8 @@ class CameraLightTurnsSupplyController : public ControllerForCommUnitInterface { bool isTimeOutForFront(); + void pushCautionButton(); + bool isTimeOutForRear(); void setCameraState(CameraStates state); From 7f0da8578e4d56da995f78c715321860856dc24e Mon Sep 17 00:00:00 2001 From: falconArdente Date: Sun, 13 Oct 2024 23:57:22 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=D0=B0,=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=20=D1=84=D0=B0=D0=BA=D1=82=D1=83=D1=80=D1=83=20BCM?= =?UTF-8?q?=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=BE=D0=B1=D0=B8=D0=BB=D1=8F?= =?UTF-8?q?.=20=D0=9A=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20=D0=B0=D0=B2=D0=B0?= =?UTF-8?q?=D1=80=D0=B8=D0=B9=D0=BA=D0=B8=20=D0=B1=D0=B5=D0=B7=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CameraLightTurnsSupplyController.cpp | 35 ++++++++++--------- .../CameraLightTurnsSupplyController.h | 18 +++++----- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/VideoCamModule/CameraLightTurnsSupplyController.cpp b/VideoCamModule/CameraLightTurnsSupplyController.cpp index 706ecc9..fcba8dd 100644 --- a/VideoCamModule/CameraLightTurnsSupplyController.cpp +++ b/VideoCamModule/CameraLightTurnsSupplyController.cpp @@ -5,7 +5,8 @@ #include const int TIMINGS_ADDR = 0; -const int CAUTION_BUTTON_DELAY =450; +const int CAUTION_BUTTON_DELAY = 450; + CameraLightTurnsSupplyController::CameraLightTurnsSupplyController() {} void CameraLightTurnsSupplyController::setCommunicationDevice(CommunicationUnit network) { @@ -36,7 +37,7 @@ void CameraLightTurnsSupplyController::initiate() { reverseGear = Lever(A1, &timings); leftTurnLever = Lever(A0, &timings); rightTurnLever = Lever(12, &timings); - cautionIsTimeStamp=millis(); + cautionIsTimeStamp = millis(); setCameraState(CAMS_OFF); getTimingsFromStorage(); getGearsState(); @@ -50,8 +51,8 @@ void CameraLightTurnsSupplyController::updateTimings(Timings newTimings) { void CameraLightTurnsSupplyController::executeCommand(CommunicationUnit::ControlCommandSet command) { - if(cautionIsPressed!=command.cautionIsOn)pushCautionButton(); - + if (cautionIsPressed != command.cautionIsOn)pushCautionButton(); + digitalWrite(outLeftFogLight, command.leftFogIsOn); digitalWrite(outRightFogLight, command.rightFogIsOn); digitalWrite(outRelayCameraSwitch, command.relayIsOn); @@ -132,16 +133,18 @@ void CameraLightTurnsSupplyController::checkGearsLoopStep() { isChangedFlag = true; } // for caution no fixation sequence - if (digitalRead(outCautionSignal) == HIGH - && (millis()> cautionIsTimeStamp+CAUTION_BUTTON_DELAY)){ + if (digitalRead(outCautionSignal) == HIGH + && (millis() > cautionIsTimeStamp + CAUTION_BUTTON_DELAY)) { digitalWrite(outCautionSignal, LOW); } } -void CameraLightTurnsSupplyController::pushCautionButton(){ - if (cautionIsPressed) cautionIsPressed=false; else cautionIsPressed=true; - cautionIsTimeStamp=millis(); - digitalWrite(outCautionSignal, HIGH); + +void CameraLightTurnsSupplyController::pushCautionButton() { + if (cautionIsPressed) cautionIsPressed = false; else cautionIsPressed = true; + cautionIsTimeStamp = millis(); + digitalWrite(outCautionSignal, HIGH); } + void CameraLightTurnsSupplyController::setCameraState(CameraStates state) { if (cameraState == state)return; @@ -150,7 +153,7 @@ void CameraLightTurnsSupplyController::setCameraState(CameraStates state) { if (cameraState == TEST_MODE)asm volatile("jmp 0x00"); //return to code start digitalWrite(outDisplayOn, LOW); digitalWrite(outRelayCameraSwitch, LOW); - if(cautionIsPressed) pushCautionButton(); + if (cautionIsPressed) pushCautionButton(); turnOffFogLight(); break; case REAR_CAM_ON: @@ -158,12 +161,12 @@ void CameraLightTurnsSupplyController::setCameraState(CameraStates state) { digitalWrite(outRelayCameraSwitch, LOW); turnOffFogLight(); if (!leftTurnLever.isOn() && !rightTurnLever.isOn()) - if(!cautionIsPressed) pushCautionButton(); + if (!cautionIsPressed) pushCautionButton(); break; case FRONT_CAM_ON: // Fog lights turn on logic is inside checkGearsLoopStep case digitalWrite(outDisplayOn, HIGH); digitalWrite(outRelayCameraSwitch, HIGH); - if(cautionIsPressed) pushCautionButton(); + if (cautionIsPressed) pushCautionButton(); break; } cameraState = state; @@ -228,13 +231,11 @@ void CameraLightTurnsSupplyController::getTimingsFromStorage() { if (checkByte == 0) { if (!(timings == timingsFromStorage)) timings = timingsFromStorage; } else { - // digitalWrite(outCautionSignal, HIGH); - // delay(300); - // digitalWrite(outCautionSignal, LOW); + // Some way to signalise } } void CameraLightTurnsSupplyController::putTimingsToStorage() { timings.crc = utils::crc8((byte * ) & timings, sizeof(timings)); EEPROM.put(TIMINGS_ADDR, timings); -} +} \ No newline at end of file diff --git a/VideoCamModule/CameraLightTurnsSupplyController.h b/VideoCamModule/CameraLightTurnsSupplyController.h index fbacde7..5927e43 100644 --- a/VideoCamModule/CameraLightTurnsSupplyController.h +++ b/VideoCamModule/CameraLightTurnsSupplyController.h @@ -47,13 +47,13 @@ class CameraLightTurnsSupplyController : public ControllerForCommUnitInterface { ChangeStateCallback changeStateCallback; CameraStates cameraState = CAMS_OFF; enum FogLightState { - ALL_OFF, - LEFT_ON, - RIGHT_ON, - BOTH_ON -} fogLightsState=ALL_OFF; - bool cautionIsPressed=false; - long cautionIsTimeStamp=0; + ALL_OFF, + LEFT_ON, + RIGHT_ON, + BOTH_ON + } fogLightsState = ALL_OFF; + bool cautionIsPressed = false; + long cautionIsTimeStamp = 0; //input gears Lever reverseGear; Lever leftTurnLever; @@ -72,7 +72,7 @@ class CameraLightTurnsSupplyController : public ControllerForCommUnitInterface { bool isTimeOutForFront(); - void pushCautionButton(); + void pushCautionButton(); bool isTimeOutForRear(); @@ -87,4 +87,4 @@ class CameraLightTurnsSupplyController : public ControllerForCommUnitInterface { void putTimingsToStorage(); }; -#endif +#endif \ No newline at end of file