Skip to content

Commit

Permalink
significantly more user customizable settings have been migrated from…
Browse files Browse the repository at this point in the history
… the headers (requiring compiliation) to settings.cfg
  • Loading branch information
BlueNalgene committed Nov 17, 2020
1 parent ee675ee commit a99fe4c
Show file tree
Hide file tree
Showing 9 changed files with 515 additions and 85 deletions.
155 changes: 124 additions & 31 deletions LunAero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void cb_framecheck() {
}
current_frame();
//~ frame_centroid();
if (*val_ptr.LOST_COUNTERaddr == 30) {
if (*val_ptr.LOST_COUNTERaddr == LOST_THRESH) {
sem_wait(&LOCK);
*val_ptr.ABORTaddr = 1;
sem_post(&LOCK);
Expand Down Expand Up @@ -500,8 +500,6 @@ void current_frame() {
// Read the rectangular data from resource into the image calloc
vc_dispmanx_rect_set(&rect, 0, 0, info.width, info.height);
vc_dispmanx_resource_read_data(resource, &rect, image, info.width*3);
// Store the image in a .ppm format file on the hard drive
// TODO - assert that the drive is plugged in
// TODO - Make this an mmap stored image.

if (DEBUG_COUT) {
Expand Down Expand Up @@ -549,7 +547,9 @@ void current_frame() {

// Optionally, save the image to a file on the disk so we can check that it makes sense
if (SAVE_DEBUG_IMAGE) {
FILE *fp = fopen("/media/pi/MOON1/out.pbm", "wb");
std::string userenv = std::getenv("USER");
std::string filestr = "/media/" + userenv + "/" + DRIVE_NAME + "/out.pbm";
FILE *fp = fopen(filestr.c_str(), "wb");
//~ fprintf(fp, "P1\n%d %d\n1\n", frmwidth, frmheight);
fprintf(fp, "P1\n%d %d\n1\n", local_width, local_height);
for (int i=0; i<local_height; i++) {
Expand Down Expand Up @@ -591,8 +591,8 @@ void current_frame() {
int checkval = 0;

// Number of points to be "on edge" is 10% of edge
int w_thresh = WORK_WIDTH/20;
int h_thresh = WORK_HEIGHT/20;
int w_thresh = WORK_WIDTH/EDGE_DIVISOR_W;
int h_thresh = WORK_HEIGHT/EDGE_DIVISOR_H;

// Store sum of each edge
int top_edge = 0;
Expand Down Expand Up @@ -824,7 +824,7 @@ void current_frame() {
int notify_handler(std::string input1, std::string input2) {
notify_init("LunAero");
NotifyNotification* n = notify_notification_new (input1.c_str(), input2.c_str(), 0);
notify_notification_set_timeout(n, 10000); // 10 seconds
notify_notification_set_timeout(n, EMG_DUR); // 10 seconds
if (!notify_notification_show(n, 0)) {
std::cerr << "Libnotify failed. I hope you have terminal open!" << std::endl;
return -1;
Expand All @@ -847,7 +847,7 @@ int notify_handler(std::string input1, std::string input2) {
int startup_disk_check() {

std::string userenv = std::getenv("USER");
std::string local_path = "/media/" + userenv + "/MOON1";
std::string local_path = "/media/" + userenv + "/" + DRIVE_NAME;
DEFAULT_FILEPATH = local_path + "/";

std::ifstream mountsfile("/proc/mounts", std::ifstream::in);
Expand Down Expand Up @@ -920,20 +920,74 @@ int parse_checklist(std::string name, std::string value) {
}*/
}
// Int cases
// else if (
// name == "BLUR_THRESH"
// || name == "QHE_WIDTH"
// || name == "T1_AT_BLOCKSIZE"
// ) {
// int result = std::stoi(value);
// if (name == "BLUR_THRESH") {
// BLUR_THRESH = result;
// } else if (name == "QHE_WIDTH") {
// QHE_WIDTH = result;
// } else if (name == "T1_AT_BLOCKSIZE") {
// T1_AT_BLOCKSIZE = result;
// }
// }
else if (
name == "FONT_MOD"
|| name == "EDGE_DIVISOR_W"
|| name == "EDGE_DIVISOR_H"
|| name == "FRAMECHECK_FREQ"
|| name == "MMAL_ERROR_THRESH"
|| name == "RPI_FPS"
|| name == "RPI_BR"
|| name == "SHUT_JUMP"
|| name == "SHUT_JUMP_BIG"
|| name == "FREQ"
|| name == "MIN_DUTY"
|| name == "MAX_DUTY"
|| name == "BRAKE_DUTY"
|| name == "APINP"
|| name == "APIN1"
|| name == "APIN2"
|| name == "BPIN1"
|| name == "BPIN2"
|| name == "BPINP"
|| name == "EMG_DUR"
|| name == "LOST_THRESH"
) {
int result = std::stoi(value);
if (name == "FONT_MOD") {
FONT_MOD = result;
} else if (name == "EDGE_DIVISOR_W") {
EDGE_DIVISOR_W = result;
} else if (name == "EDGE_DIVISOR_H") {
EDGE_DIVISOR_H = result;
} else if (name == "FRAMECHECK_FREQ") {
FRAMECHECK_FREQ = result;
} else if (name == "MMAL_ERROR_THRESH") {
MMAL_ERROR_THRESH = result;
} else if (name == "RPI_FPS") {
RPI_FPS = result;
} else if (name == "RPI_BR") {
RPI_BR = result;
} else if (name == "SHUT_JUMP") {
SHUT_JUMP = result;
} else if (name == "SHUT_JUMP_BIG") {
SHUT_JUMP_BIG = result;
} else if (name == "FREQ") {
FREQ = result;
} else if (name == "MIN_DUTY") {
MIN_DUTY = result;
} else if (name == "MAX_DUTY") {
MAX_DUTY = result;
} else if (name == "BRAKE_DUTY") {
BRAKE_DUTY = result;
} else if (name == "APINP") {
APINP = result;
} else if (name == "APIN1") {
APIN1 = result;
} else if (name == "APIN2") {
APIN2 = result;
} else if (name == "BPIN1") {
BPIN1 = result;
} else if (name == "BPIN2") {
BPIN2 = result;
} else if (name == "BPINP") {
BPINP = result;
} else if (name == "EMG_DUR") {
EMG_DUR = result;
} else if (name == "LOST_THRESH") {
LOST_THRESH = result;
}
}
// Double cases
else if (
name == "RECORD_DURATION"
Expand All @@ -946,15 +1000,54 @@ int parse_checklist(std::string name, std::string value) {
LOOSE_WHEEL_DURATION = (std::chrono::duration<double>) result;
}
// String cases
// } else if (
// name == "OSFPROJECT"
// || name == "OUTPUTDIR"
// ) {
// if (name == "OSFPROJECT") {
// OSFPROJECT = value;
// } else if (name == "OUTPUTDIR") {
// OUTPUTDIR = value;
// }
} else if (
name == "KV_QUIT"
|| name == "KV_RUN"
|| name == "KV_LEFT"
|| name == "KV_RIGHT"
|| name == "KV_UP"
|| name == "KV_DOWN"
|| name == "KV_STOP"
|| name == "KV_REFRESH"
|| name == "KV_S_UP_UP"
|| name == "KV_S_DOWN_DOWN"
|| name == "KV_S_UP"
|| name == "KV_S_DOWN"
|| name == "KV_ISO"
|| name == "RPI_EX"
|| name == "DRIVE_NAME"
) {
if (name == "KV_QUIT") {
KV_QUIT = value.c_str();
} else if (name == "KV_RUN") {
KV_RUN = value.c_str();
} else if (name == "KV_LEFT") {
KV_LEFT = value.c_str();
} else if (name == "KV_RIGHT") {
KV_RIGHT = value.c_str();
} else if (name == "KV_UP") {
KV_UP = value.c_str();
} else if (name == "KV_DOWN") {
KV_DOWN = value.c_str();
} else if (name == "KV_STOP") {
KV_STOP = value.c_str();
} else if (name == "KV_REFRESH") {
KV_REFRESH = value.c_str();
} else if (name == "KV_S_UP_UP") {
KV_S_UP_UP = value.c_str();
} else if (name == "KV_S_DOWN_DOWN") {
KV_S_DOWN_DOWN = value.c_str();
} else if (name == "KV_S_UP") {
KV_S_UP = value.c_str();
} else if (name == "KV_S_DOWN") {
KV_S_DOWN = value.c_str();
} else if (name == "KV_ISO") {
KV_ISO = value.c_str();
} else if (name == "RPI_EX") {
RPI_EX = value;
} else if (name == "DRIVE_NAME") {
DRIVE_NAME = value;
}
} else {
std::cerr << "Did not recognize entry " << name << " in config file, skipping" << std::endl;
}
Expand Down
25 changes: 23 additions & 2 deletions LunAero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,29 @@ inline int RVD_XCORN = 0;
* Y value for top left corner for preview window application
*/
inline int RVD_YCORN = 0;


/**
* Divisor for the number pixels on the top and bottom edges to warrant a move. Customizable from
* settings.cfg.
*/
inline int EDGE_DIVISOR_W = 20;
/**
* Divisor for the number pixels on the left and right edges to warrant a move. Customizable from
* settings.cfg.
*/
inline int EDGE_DIVISOR_H = 20;
/**
* Drive name given to the external video storage drive. Customizable from settings.cfg.
*/
inline std::string DRIVE_NAME = "MOON1";
/**
* Number of cycles the moon is lost for before stopping LunAero. Customizable from settings.cfg.
*/
inline int LOST_THRESH = 30;
/**
* Milliseconds an emergency messeage should remain on the desktop in event of a crash. Customizable
* from settings.cfg
*/
inline int EMG_DUR = 10000;


inline std::string FILEPATH;
Expand Down
39 changes: 27 additions & 12 deletions camera_LunAero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int confirm_mmal_safety(int error_cnt) {
LOGGING.close();
}
// If the retry attempts are way too high, don't even bother
if (error_cnt > 100) {
if (error_cnt > MMAL_ERROR_THRESH) {
if (DEBUG_COUT) {
LOGGING.open(LOGOUT, std::ios_base::app);
LOGGING
Expand Down Expand Up @@ -98,7 +98,7 @@ int confirm_mmal_safety(int error_cnt) {
<< "WARNING: LunAero detected an MMAL problem with raspivid. Retrying" << std::endl;
LOGGING.close();
}
if (error_cnt > 100) {
if (error_cnt > MMAL_ERROR_THRESH) {
sem_wait(&LOCK);
*val_ptr.ABORTaddr = 1;
sem_post(&LOCK);
Expand Down Expand Up @@ -193,11 +193,16 @@ std::string command_cam_preview() {
std::string commandstring;
// Get the current unix timestamp as a string
TSBUFF = std::to_string((unsigned long)time(NULL));
commandstring = "raspivid -v -t 0 -w 1920 -h 1080 -fps 30 -b 8000000 -ISO "
commandstring = "raspivid -v -t 0 -w 1920 -h 1080 -fps "
+ std::to_string(RPI_FPS)
+ " -b "
+ std::to_string(RPI_BR)
+ " -ISO "
+ std::to_string(*val_ptr.ISO_VALaddr)
+ " -ss "
+ std::to_string(*val_ptr.SHUTTER_VALaddr)
+ " --exposure auto "
+ " --exposure "
+ RPI_EX
+ " -p "
+ std::to_string(RVD_XCORN)
+ ","
Expand Down Expand Up @@ -227,11 +232,16 @@ std::string command_cam_start() {
std::string commandstring;
// Get the current unix timestamp as a string
TSBUFF = current_time(0);
commandstring = "raspivid -v -t 0 -w 1920 -h 1080 -fps 30 -b 8000000 -ISO "
commandstring = "raspivid -v -t 0 -w 1920 -h 1080 -fps "
+ std::to_string(RPI_FPS)
+ " -b "
+ std::to_string(RPI_BR)
+ " -ISO "
+ std::to_string(*val_ptr.ISO_VALaddr)
+ " -ss "
+ std::to_string(*val_ptr.SHUTTER_VALaddr)
+ " --exposure auto "
+ " --exposure "
+ RPI_EX
+ " -p "
+ std::to_string(RVD_XCORN)
+ ","
Expand Down Expand Up @@ -279,9 +289,14 @@ void write_video_id() {
<< " Shutter Speed: "
<< std::to_string(*val_ptr.SHUTTER_VALaddr)
<< std::endl
<< " Bitrate: 8000000"
<< " Bitrate: "
<< std::to_string(RPI_BR)
<< std::endl
<< " Framerate: 30"
<< " Framerate: "
<< std::to_string(RPI_EX)
<< std::endl
<< " Exposure Mode: "
<< RPI_BR
<< std::endl;

idfile.close();
Expand Down Expand Up @@ -345,7 +360,7 @@ void refresh_camera() {
void shutter_up() {
if (*val_ptr.SHUTTER_VALaddr < 32901) {
sem_wait(&LOCK);
*val_ptr.SHUTTER_VALaddr = *val_ptr.SHUTTER_VALaddr + 100;
*val_ptr.SHUTTER_VALaddr = *val_ptr.SHUTTER_VALaddr + SHUT_JUMP;
sem_post(&LOCK);
} else {
sem_wait(&LOCK);
Expand All @@ -369,7 +384,7 @@ void shutter_up() {
void shutter_down() {
if (*val_ptr.SHUTTER_VALaddr > 110) {
sem_wait(&LOCK);
*val_ptr.SHUTTER_VALaddr = *val_ptr.SHUTTER_VALaddr - 100;
*val_ptr.SHUTTER_VALaddr = *val_ptr.SHUTTER_VALaddr - SHUT_JUMP;
sem_post(&LOCK);
} else {
sem_wait(&LOCK);
Expand All @@ -393,7 +408,7 @@ void shutter_down() {
void shutter_up_up() {
if (*val_ptr.SHUTTER_VALaddr < 32001) {
sem_wait(&LOCK);
*val_ptr.SHUTTER_VALaddr = *val_ptr.SHUTTER_VALaddr + 1000;
*val_ptr.SHUTTER_VALaddr = *val_ptr.SHUTTER_VALaddr + SHUT_JUMP_BIG;
sem_post(&LOCK);
} else {
sem_wait(&LOCK);
Expand All @@ -417,7 +432,7 @@ void shutter_up_up() {
void shutter_down_down() {
if (*val_ptr.SHUTTER_VALaddr > 1010) {
sem_wait(&LOCK);
*val_ptr.SHUTTER_VALaddr = *val_ptr.SHUTTER_VALaddr - 1000;
*val_ptr.SHUTTER_VALaddr = *val_ptr.SHUTTER_VALaddr - SHUT_JUMP_BIG;
sem_post(&LOCK);
} else {
sem_wait(&LOCK);
Expand Down
27 changes: 27 additions & 0 deletions camera_LunAero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,33 @@
// User Includes
#include "LunAero.hpp"

/**
* Threshold of MMAL errors encountered sequentially before ending the run. Customizable from
* settings.cfg
*/
inline int MMAL_ERROR_THRESH = 100;
/**
* Framerate to record video at. Customizable from settings.cfg
*/
inline int RPI_FPS = 30;
/**
* Bitrate to record video at. Customizable from settings.cfg
*/
inline int RPI_BR = 8000000;
/**
* Raspivid exposure mode to use. Customizable from settings.cfg
*/
inline std::string RPI_EX = "auto";
/**
* Shutter speed increase and decrease when using the up or down buttons. Customziable from settings.cfg
*/
inline int SHUT_JUMP = 100;
/**
* Large shutter speed increase and decrease when using the up_up or down_down buttons. Customizable
* from settings.cfg
*/
inline int SHUT_JUMP_BIG = 1000;

// Function Prototypes
int confirm_filespace();
int confirm_mmal_safety(int error_cnt);
Expand Down
Loading

0 comments on commit a99fe4c

Please sign in to comment.