Skip to content

Commit

Permalink
Merge pull request #72 from falconArdente/caution_button_no_fix
Browse files Browse the repository at this point in the history
Caution button no fix
  • Loading branch information
falconArdente authored Oct 15, 2024
2 parents 2ec49fe + 7f0da85 commit ca51641
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 28 deletions.
62 changes: 43 additions & 19 deletions VideoCamModule/CameraLightTurnsSupplyController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <EEPROM.h>

const int TIMINGS_ADDR = 0;
const int CAUTION_BUTTON_DELAY = 450;

CameraLightTurnsSupplyController::CameraLightTurnsSupplyController() {}

Expand All @@ -25,12 +26,22 @@ 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);
cautionIsTimeStamp = millis();
setCameraState(CAMS_OFF);
getTimingsFromStorage();
getGearsState();
sendCurrentState();
}

void CameraLightTurnsSupplyController::updateTimings(Timings newTimings) {
Expand All @@ -40,7 +51,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);
Expand Down Expand Up @@ -116,29 +128,45 @@ void CameraLightTurnsSupplyController::checkGearsLoopStep() {
case TEST_MODE:
break;
}
if (!reverseGear.isOn() && cameraState != TEST_MODE)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;

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);
if (cautionIsPressed) pushCautionButton();
turnOffFogLight();
break;
case REAR_CAM_ON:
digitalWrite(outDisplayOn, HIGH);
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;
Expand All @@ -147,24 +175,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() {
Expand Down Expand Up @@ -203,15 +231,11 @@ void CameraLightTurnsSupplyController::getTimingsFromStorage() {
if (checkByte == 0) {
if (!(timings == timingsFromStorage)) timings = timingsFromStorage;
} else {
setCameraState(TEST_MODE);
digitalWrite(outCautionSignal, HIGH);
delay(1500);
digitalWrite(outCautionSignal, LOW);
setCameraState(CAMS_OFF);
// Some way to signalise
}
}

void CameraLightTurnsSupplyController::putTimingsToStorage() {
timings.crc = utils::crc8((byte * ) & timings, sizeof(timings));
EEPROM.put(TIMINGS_ADDR, timings);
}
}
16 changes: 10 additions & 6 deletions VideoCamModule/CameraLightTurnsSupplyController.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +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;
ALL_OFF,
LEFT_ON,
RIGHT_ON,
BOTH_ON
} fogLightsState = ALL_OFF;
bool cautionIsPressed = false;
long cautionIsTimeStamp = 0;
//input gears
Lever reverseGear;
Lever leftTurnLever;
Expand All @@ -70,6 +72,8 @@ class CameraLightTurnsSupplyController : public ControllerForCommUnitInterface {

bool isTimeOutForFront();

void pushCautionButton();

bool isTimeOutForRear();

void setCameraState(CameraStates state);
Expand All @@ -83,4 +87,4 @@ class CameraLightTurnsSupplyController : public ControllerForCommUnitInterface {
void putTimingsToStorage();
};

#endif
#endif
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ca51641

Please sign in to comment.