Commit 35beb9d9 authored by Simon Gölzhäuser's avatar Simon Gölzhäuser
Browse files

Changed recording indication to flashlight & removed automatic RTC time initialization

parent a3057c24
......@@ -63,6 +63,8 @@ https://github.com/jameszah/ESP32-CAM-Video-Recorder-junior
//#define SERIALPRINTS
//#define TESTING
//#define SETRTCTIME
#define FLASHLIGHTINDICATOR
// --------------------------------------------------
// General
......@@ -125,6 +127,9 @@ bool g_bRecording = false;
long g_lBytesBeforeLast100Frames = 0;
long g_lTimeBeforeLast100Frames = 0;
int m_nRecordTriggerDistance = RECORD_TRIGGERDISTANCE;
long m_lRecordTurnOffDelay = RECORD_TURNOFFDELAY;
// --------------------------------------------------
// Avi writer stuff
// --------------------------------------------------
......@@ -295,17 +300,31 @@ void majorFail() {
#endif
for (int j = 0; j < 3; j++) {
#ifdef FLASHLIGHTINDICATOR
digitalWrite(PIN_FLASHLIGHT, HIGH);
delay(150);
digitalWrite(PIN_FLASHLIGHT, LOW);
delay(150);
#else
digitalWrite(PIN_REDLED, LOW);
delay(150);
digitalWrite(PIN_REDLED, HIGH);
delay(150);
#endif
}
delay(1000);
for (int j = 0; j < 3; j++) {
#ifdef FLASHLIGHTINDICATOR
digitalWrite(PIN_FLASHLIGHT, HIGH);
delay(500);
digitalWrite(PIN_FLASHLIGHT, LOW);
delay(500);
#else
digitalWrite(PIN_REDLED, LOW);
delay(500);
digitalWrite(PIN_REDLED, HIGH);
delay(500);
#endif
}
delay(1000);
}
......@@ -495,8 +514,20 @@ void initRtc() {
majorFail();
}
// Uncomment this to set time of the RTC to build time of program
//g_rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
/*
On the internet was found that it can be automatically checked if the
time was already set with:
!g_rtc.initialized() || g_rtc.lostPower()
Tests nevertheless showed that this does not work reliably. So to be
safe, time is set by defining SETRTCTIME.
*/
#ifdef SETRTCTIME
g_rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
#ifdef SERIALPRINTS
Serial.println("RTC time set to sketch build time");
#endif
#endif
}
/**
......@@ -520,6 +551,47 @@ void initDistanceSensor() {
g_sensor.startContinuous(50);
}
/**
* Reads the file "config.txt".
* Line 1: Recording trigger distance (cm)
* Line 2: Recording turnoff delay (ms)
*/
void readConfigFile() {
String sJunk;
File fConfig = SD_MMC.open("/config.txt", "r");
#ifdef SERIALPRINTS
Serial.println("\nReading configfile");
#endif
g_fLog.println("\nReading configfile");
if (!fConfig) {
#ifdef SERIALPRINTS
Serial.println("Failed to open configfile");
#endif
g_fLog.println("Failed to open configfile");
g_fLog.flush();
return;
}
m_nRecordTriggerDistance = fConfig.parseInt();
sJunk = fConfig.readStringUntil('\n');
m_lRecordTurnOffDelay = fConfig.parseInt();
sJunk = fConfig.readStringUntil('\n');
fConfig.close();
#ifdef SERIALPRINTS
Serial.println("Data from config file:");
Serial.printf("Recording trigger distance: %d\n", m_nRecordTriggerDistance);
Serial.printf("Recording turn off delay: %ld\n", m_lRecordTurnOffDelay);
#endif
g_fLog.println("Data from config file:");
g_fLog.printf("Recording trigger distance: %d\n", m_nRecordTriggerDistance);
g_fLog.printf("Recording turn off delay: %ld\n", m_lRecordTurnOffDelay);
g_fLog.flush();
}
// --------------------------------------------------
// Video recording functions
// --------------------------------------------------
......@@ -1022,8 +1094,12 @@ void cameraLoop (void* pvParameter) {
// Trigger SD write to write first frame
xSemaphoreGive(g_semSdGo);
// Red LED blink
// LED blink
#ifdef FLASHLIGHTINDICATOR
digitalWrite(PIN_FLASHLIGHT, (g_u16AviFrameCnt % 2));
#else
digitalWrite(PIN_REDLED, (g_u16AviFrameCnt % 2));
#endif
// --- Case 3: End recording ---
} else if ((g_u16AviFrameCnt > 0) && !g_bRecording) {
......@@ -1040,8 +1116,12 @@ void cameraLoop (void* pvParameter) {
// Save final frame
xSemaphoreGive(g_semSdGo);
// Red LED blink
// LED blink
#ifdef FLASHLIGHTINDICATOR
digitalWrite(PIN_FLASHLIGHT, (g_u16AviFrameCnt % 2));
#else
digitalWrite(PIN_REDLED, (g_u16AviFrameCnt % 2));
#endif
// Wait for final frame to be written
xSemaphoreTake(g_semSdWait, portMAX_DELAY);
......@@ -1058,8 +1138,12 @@ void cameraLoop (void* pvParameter) {
aviEnd();
// Red LED off
// LED off
#ifdef FLASHLIGHTINDICATOR
digitalWrite(PIN_FLASHLIGHT, LOW);
#else
digitalWrite(PIN_REDLED, HIGH);
#endif
g_u16AviFrameCnt = 0;
......@@ -1081,8 +1165,12 @@ void cameraLoop (void* pvParameter) {
g_pFbNext = getGoodJpg(); // Should take nearly zero time, unless SD is faster than camera
g_lDelayWaitForCam += (millis() - lWaitForCamStart);
// Red LED blink
// LED blink
#ifdef FLASHLIGHTINDICATOR
digitalWrite(PIN_FLASHLIGHT, (g_u16AviFrameCnt % 2));
#else
digitalWrite(PIN_REDLED, (g_u16AviFrameCnt % 2));
#endif
if ((g_u16AviFrameCnt % 100) == 10) { // Print some status every 100 frames
if (g_u16AviFrameCnt == 10) {
......@@ -1117,7 +1205,7 @@ void handleRecording() {
static long lRecordingStart = 0;
int nDistance = g_sensor.read();
if (nDistance <= RECORD_TRIGGERDISTANCE) {
if (nDistance <= m_nRecordTriggerDistance) {
lRecordingStart = millis();
if (!g_bRecording) {
getAviFileName(g_aviFileName);
......@@ -1127,7 +1215,7 @@ void handleRecording() {
}
}
if ((lRecordingStart > 0) && (millis() >= (lRecordingStart + RECORD_TURNOFFDELAY))) {
if ((lRecordingStart > 0) && (millis() >= (lRecordingStart + m_lRecordTurnOffDelay))) {
lRecordingStart = 0;
g_bRecording = false;
g_fLog.printf("Time at video stop trigger: %d\n", millis());
......@@ -1146,7 +1234,7 @@ void handleRecordingTesting() {
bRecordingStarted = true;
}
if ((lRecordingStart > 0) && (millis() >= (lRecordingStart + RECORD_TURNOFFDELAY))) {
if ((lRecordingStart > 0) && (millis() >= (lRecordingStart + m_lRecordTurnOffDelay))) {
g_bRecording = false;
lRecordingStart = 0;
}
......@@ -1254,6 +1342,9 @@ void setup() {
#endif
g_fLog.println(sResetReason);
// Read configfile
readConfigFile();
// Camera init
initCamera();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment