int main() { CyGlobalIntEnable; /* Enable global interrupts. */ init(); /* Place your initialization/startup code here (e.g. MyInst_Start()) */ setSpeed(30000,MOTOR_A); setSpeed(30000,MOTOR_B); for(;;) { goForward(); CyDelay(2000); stop_all(); CyDelay(2000); goBackward(); CyDelay(2000); stop_all(); CyDelay(2000); goLeft(); CyDelay(2000); stop_all(); CyDelay(2000); goRight(); CyDelay(2000); stop_all(); CyDelay(2000); } }
static int target_event_stop_handler(struct target *target) { int cnt; enum app_type_t app_type = target->app_type; LOGI("target[%p] close, pid(%d) : (remaining %d target)\n", target, target_get_pid(target), target_cnt_get() - 1); ecore_main_fd_handler_del(target->handler); target_wait(target); target_dtor(target); // all target client are closed cnt = target_cnt_sub_and_fetch(); if (0 == cnt) { switch (app_type) { case APP_TYPE_TIZEN: case APP_TYPE_COMMON: LOGI("all targets are stopped\n"); if (stop_all() != ERR_NO) LOGE("Stop failed\n"); return -11; } } return 0; }
bool SamplePlayer::_set(const StringName& p_name, const Variant& p_value) { String name=p_name; if (name=="play/play") { if (library.is_valid()) { String what=p_value; if (what=="") stop_all(); else play(what); played_back=what; } } else if (name=="config/samples") set_sample_library(p_value); else if (name=="config/voices") set_voice_count(p_value); else if (name.begins_with("default/")) { String what=name.right(8); if (what=="volume_db") set_default_volume_db(p_value); else if (what=="pitch_scale") set_default_pitch_scale(p_value); else if (what=="pan") _default.pan=p_value; else if (what=="depth") _default.depth=p_value; else if (what=="height") _default.height=p_value; else if (what=="filter/type") _default.filter_type=FilterType(p_value.operator int()); else if (what=="filter/cutoff") _default.filter_cutoff=p_value; else if (what=="filter/resonance") _default.filter_resonance=p_value; else if (what=="filter/gain") _default.filter_gain=p_value; else if (what=="reverb_room") _default.reverb_room=ReverbRoomType(p_value.operator int()); else if (what=="reverb_send") _default.reverb_send=p_value; else if (what=="chorus_send") _default.chorus_send=p_value; else return false; } else return false; return true; }
server_general::~server_general() { stop_all(); for (auto sh : _socks) { delete sh.second; } // delete _handler; }
static void kill_kids(void) { struct kid_t *tmp = kid_list; stop_all(SIGINT); trigger(C_STOP, 0, 0, 0); while(tmp) { pthread_kill(tmp->k_pthread, SIGTERM); tmp = tmp->k_next; } }
void AnimationPlayer::rename_animation(const StringName& p_name,const StringName& p_new_name) { ERR_FAIL_COND(!animation_set.has(p_name) ); ERR_FAIL_COND( String(p_new_name).find("/")!=-1 || String(p_new_name).find(":")!=-1 ); ERR_FAIL_COND( animation_set.has(p_new_name) ); //print_line("Rename anim: "+String(p_name)+" name: "+String(p_new_name)); stop_all(); AnimationData ad = animation_set[p_name]; ad.name=p_new_name; animation_set.erase(p_name); animation_set[p_new_name]=ad; List<BlendKey> to_erase; Map<BlendKey,float> to_insert; for(Map<BlendKey, float >::Element *E=blend_times.front();E;E=E->next()) { BlendKey bk=E->key(); BlendKey new_bk=bk; bool erase=false; if (bk.from==p_name) { new_bk.from=p_new_name; erase=true; } if (bk.to==p_name) { new_bk.to=p_new_name; erase=true; } if (erase) { to_erase.push_back(bk); to_insert[new_bk]=E->get(); } } while(to_erase.size()) { blend_times.erase(to_erase.front()->get()); to_erase.pop_front();; } while(to_insert.size()) { blend_times[to_insert.front()->key()]=to_insert.front()->get(); to_insert.erase(to_insert.front()); } if (autoplay==p_name) autoplay=p_new_name; clear_caches(); _change_notify(); }
void AnimationPlayer::remove_animation(const StringName &p_name) { ERR_FAIL_COND(!animation_set.has(p_name)); stop_all(); _unref_anim(animation_set[p_name].animation); animation_set.erase(p_name); clear_caches(); _change_notify(); }
void MainObject::on_quit(){ stop_all(); settings->saveWindow(launcherWindow); settings->saveWindow(fgxDebugWidget); settings->saveWindow(viewLogsWidget); settings->saveWindow(propertiesBrowser); settings->sync(); QApplication::quit(); }
void facade::handle_stop() { if(!bDestroying_) { //boost::recursive_mutex::scoped_lock guard(lock); boost::detail::lightweight_mutex::scoped_lock guard(lock); if(!bDestroying_) { bDestroying_ = true; stop_all(); } } }
void AnimationPlayer::_notification(int p_what) { switch(p_what) { case NOTIFICATION_ENTER_SCENE: { if (!processing) { //make sure that a previous process state was not saved //only process if "processing" is set set_fixed_process(false); set_process(false); } //_set_process(false); clear_caches(); } break; case NOTIFICATION_READY: { if (!get_scene()->is_editor_hint() && animation_set.has(autoplay)) { play(autoplay); } } break; case NOTIFICATION_PROCESS: { if (animation_process_mode==ANIMATION_PROCESS_FIXED) break; if (processing) _animation_process( get_process_delta_time() ); } break; case NOTIFICATION_FIXED_PROCESS: { if (animation_process_mode==ANIMATION_PROCESS_IDLE) break; if (processing) _animation_process( get_fixed_process_delta_time() ); } break; case NOTIFICATION_EXIT_SCENE: { stop_all(); clear_caches(); } break; } }
bool SamplePlayer2D::_set(const StringName& p_name, const Variant& p_value) { String name=p_name; if (name=="play/play") { if (library.is_valid()) { String what=p_value; if (what=="") stop_all(); else play(what); played_back=what; } } else return false; return true; }
int set_nvram_param(rtapi_u32 addr, rtapi_u32 value){ rtapi_u32 buff; if (stop_all() < 0) goto fail0; if (setup_start() < 0) goto fail0; if (nv_access(LBPNONVOLEEPROM) < 0) goto fail0; // value to set HM2WRITE(remote->reg_0_addr, value); buff = WRITE_REM_WORD_CMD | addr; HM2WRITE(remote->reg_cs_addr, buff); if (doit() < 0) goto fail0; if (nv_access(LBPNONVOLCLEAR) < 0) goto fail0; return 0; fail0: // It's all gone wrong buff=0x800; //Stop HM2WRITE(remote->command_reg_addr, buff); rtapi_print_msg(RTAPI_MSG_ERR, "Problem with Smart Serial parameter setting, see dmesg\n"); return -1; }
void Tween::_notification(int p_what) { switch(p_what) { case NOTIFICATION_ENTER_TREE: { if (!processing) { //make sure that a previous process state was not saved //only process if "processing" is set set_fixed_process(false); set_process(false); } } break; case NOTIFICATION_READY: { } break; case NOTIFICATION_PROCESS: { if (tween_process_mode==TWEEN_PROCESS_FIXED) break; if (processing) _tween_process( get_process_delta_time() ); } break; case NOTIFICATION_FIXED_PROCESS: { if (tween_process_mode==TWEEN_PROCESS_IDLE) break; if (processing) _tween_process( get_fixed_process_delta_time() ); } break; case NOTIFICATION_EXIT_TREE: { stop_all(); } break; } }
ThreadPool::~ThreadPool() { stop_all(); }
void play_hmi (void * arg) { int i; int pos = 0x308; int n_chunks = 0; int low_dtime; int low_chunk; int csec, lcsec; int qid; int ipc_read = 0; int k=0; struct msgbuf *rcv; Track_info *t_info; con_printf(CON_DEBUG,"play_hmi\n"); stop = 0; ipc_read=0; rcv=malloc(sizeof(long) + 16); rcv->mtype=1; rcv->mtext[0]='0'; qid=msgget ((key_t) ('l'<<24) | ('d'<<16) | ('e'<<8) | 's', 0660); if(qid == -1) { return; } do { ipc_read=do_ipc(qid,rcv,0); } while(rcv->mtext[0] != 'p'); stop=0; rcv->mtext[0] = '0'; seq_init(); n_chunks=data[0x30]; t_info = malloc(sizeof(Track_info)*n_chunks); while(1) { for(i=0;i<n_chunks;i++) { t_info[i].position = pos + 12; t_info[i].status = PLAYING; t_info[i].time = get_dtime(data,&t_info[i].position); pos += (( (0xff & data[pos + 5]) << 8 ) + (0xff & data[pos + 4])); } lcsec = 0; SEQ_START_TIMER(); do { low_chunk = -1; k++; i=0; do { if (t_info[i].status == PLAYING) low_chunk = i; i++; } while((low_chunk <=0) && (i<n_chunks)); if (low_chunk == -1) break; low_dtime = t_info[low_chunk].time; for(i=1;i<n_chunks;i++) { if ((t_info[i].time < low_dtime) && (t_info[i].status == PLAYING)) { low_dtime = t_info[i].time; low_chunk = i; } } if (low_dtime < 0) con_printf(CON_URGENT,"Serious warning: d_time negative!!!!!!\n"); csec = 0.86 * low_dtime; //flush sequencer buffer after 20 events if (k == 20) { ioctl(seqfd, SNDCTL_SEQ_SYNC); k = 0; } #ifdef WANT_AWE32 cut_trough(); #endif if (csec != lcsec) { SEQ_WAIT_TIME(csec); } lcsec = csec; t_info[low_chunk].status = do_track_event(data,&t_info[low_chunk].position); if (t_info[low_chunk].status == 3) { con_printf(CON_URGENT,"Error playing data in chunk %d\n",low_chunk); t_info[low_chunk].status = STOPPED; } if (t_info[low_chunk].status == PLAYING) t_info[low_chunk].time += get_dtime(data,&t_info[low_chunk].position); //Check if the song has reached the end stop = t_info[0].status; for(i=1;i<n_chunks;i++) stop &= t_info[i].status; if((do_ipc(qid,rcv,IPC_NOWAIT) > 0) && (rcv->mtext[0]=='p')) { n_chunks=data[0x30]; t_info = realloc(t_info,sizeof(Track_info)*n_chunks); stop = 1; rcv->mtext[0] = '0'; stop_all(); } } while(!stop); SEQ_STOP_TIMER(); if( stop == 2) { stop_all(); do { ipc_read=do_ipc(qid,rcv,0); } while(rcv->mtext[0] != 'p'); rcv->mtext[0] = '0'; n_chunks=data[0x30]; t_info = realloc(t_info,sizeof(Track_info)*n_chunks); stop = 0; } pos=0x308; } free(data); free(t_info); free(rcv); }
void mpijob_manager::run_master() { #ifdef __MPI__ time.start(); // print info string prefix = "master: "; cout << prefix << "world has " << jslots << " slots (excluding master)." << endl; cout << prefix << jobs.size() << " jobs to process." << endl; // ask each slave if available boost::mpi::request *reqs = new boost::mpi::request[world.size()]; int *running = new int[world.size()]; for (int i = 1; i < world.size(); ++i) { world.isend(i, CMD_RUNNING, 0); running[i] = -1; // not running initially reqs[i] = world.irecv(i, CMD_RUNNING, running[i]); } jinfos(running); unstarted = jobs.size(); // loop until all jobs are finished while (nalive || unfinished > 0) { // if there are jobs waiting to be started, start them if possible for (uint i = 0; i < jobs.size(); ++i) { // check status of job i from files jobs[i]->check_finished(); jobs[i]->check_started(); jobs[i]->check_running(); // start job if not finished and not alive if (!jobs[i]->finished() && !jobs[i]->running()) { for (int j = 1; j < world.size(); ++j) { // check if this slot has answered and what its answer is if (reqs[j].test() && running[j] == -1) { // answer and free cout << prefix << j << " is free" << endl; if (!assign(i, j)) cerr << "failed to assign job " << i << " to slot " << j << endl; else { cout << "master: assigned job " << i << " to slot " << j << endl; running[j] = i; // re-ask if slot j is available for when its done world.isend(j, CMD_RUNNING, 0); reqs[j] = world.irecv(j, CMD_RUNNING, running[j]); jinfos(running); break ; // move to next job } } } } } jobs_info(); jinfos(running); secsleep(swait); report(); } stop_all(); last_report(); delete running; // deleting reqs makes the program crash //delete reqs; cout << "MPI master is finished after " << time.elapsed() << endl; exit(0); #endif }
int main (int argc, char * argv[]) { parse_opts(argc,argv); if(!doInit()) { printf("Error Initializing Stuff.\n"); exit(EXIT_FAILURE); } else { //o calibrar colores o seguir la linea //bool rotate = true; double pval; bool stop = true; int left, right; while(!ag_psh_is_pushed(&push, &pval)); UDELAY(750000); printf("pval is: %.2f\n", pval); ag_lgt_set_led(&lright, true); ag_lgt_set_led(&lleft, true); if (mode) { //calibrar colores int i = 0; double acumr [calib], minr, maxr, upr, lowr; double acuml [calib], minl, maxl, upl, lowl; for (;i<calib;i++) { acumr[i] = (double)ag_read_int(&lright); acuml[i] = (double)ag_read_int(&lleft); UDELAY(100); } gsl_stats_minmax(&minr, &maxr, acumr, 1, calib); gsl_stats_minmax(&minl, &maxl, acuml, 1, calib); gsl_sort (acumr,1,calib); gsl_sort (acuml,1,calib); upl = gsl_stats_quantile_from_sorted_data (acuml,1,calib,0.95);//uq lowl = gsl_stats_quantile_from_sorted_data (acuml,1,calib,0.05);//lq upr = gsl_stats_quantile_from_sorted_data (acumr,1,calib,0.95);//uq lowr = gsl_stats_quantile_from_sorted_data (acumr,1,calib,0.05);//lq for (i = 0 ; i < 2; i++){ printf("COLOR: %s, SENSOR: %s\n", white ? "WHITE" : "BLACK", i == 0 ? "LEFT" : "RIGHT"); printf("min_v: %d, max_v: %d\n", i == 0 ? (int)minl : (int)minr, i == 0 ? (int)maxl : (int)maxr); printf("low_q: %d, up_q :%d\n", i == 0 ? (int)lowl : (int)lowr, i == 0 ? (int)upl : (int)upr); printf("\n"); } } else { //seguir linea while(!ag_psh_is_pushed(&push, &pval)) { //printf("pval is: %.2f\n", pval); if (stop){ stop = false; move_all(MY_FWD,vel); } right = ag_read_int(&lright); left = ag_read_int(&lleft); if(! IS_WHITE(right) || ! IS_WHITE(left)){ stop_all(); stop = true; if (IS_BLACK(left)){ rotate_robot(vel, true); while(IS_BLACK(ag_read_int(&lleft))); UDELAY(TDELAY); stop_all(); } else if (IS_BLACK(right)) { rotate_robot(vel, false); while(IS_BLACK(ag_read_int(&lright))); UDELAY(TDELAY); stop_all(); } } } } } lego_shutdown(); exit(EXIT_SUCCESS); }
static void setup_signals() { struct sigaction sigact = { .sa_handler = terminate, .sa_flags = 0 }; sigemptyset(&sigact.sa_mask); sigaction(SIGTERM, &sigact, 0); sigaction(SIGINT, &sigact, 0); signal(SIGHUP, SIG_IGN); signal(SIGPIPE,SIG_IGN); } // main function int main() { if (!ensure_singleton(SINGLETON_LOCKFILE)) return 1; if (initialize_log() != 0) { LOGE("Init log failed. uninit\n"); terminate0(); LOGE("Daemon terminated\n"); exit(0); } LOGI("da_started\n"); atexit(terminate0); //for terminal exit setup_signals(); daemon(0, 1); LOGI("--- daemonized (pid %d) ---\n", getpid()); FILE *portfile = fopen(PORTFILE, "w"); if (!portfile) { LOGE("cannot create portfile"); return 1; } int err = initializeManager(portfile); fclose(portfile); if (err) return 1; //init all file descriptors init_system_file_descriptors(); //daemon work //FIX ME remove samplingThread it is only for debug //samplingThread(NULL); daemonLoop(); LOGI("daemon loop finished\n"); stop_all(); finalizeManager(); close_system_file_descriptors(); //DO NOT USE THIS FUNCTION FOR RELEASE IT IS TOO SLOW #ifdef MALLOC_DEBUG_LEVEL msg_swap_free_all_data(&prof_session.user_space_inst); #endif LOGI("main finished\n"); print_malloc_list(NULL, 0); return 0; }
TimerSDL::~TimerSDL() { stop_all(); }
int main (int argc, char* argv[]) { MMAL_STATUS_T status; int i, max, fd, length, cam_setting; unsigned long int cam_setting_long; char readbuf[20]; char *filename_temp, *filename_temp2, *cmd_temp; bcm_host_init(); // // read arguments // unsigned char of_set = 0; for(i=1; i<argc; i++) { if(strcmp(argv[i], "--version") == 0) { printf("RaspiMJPEG Version "); printf(VERSION); printf("\n"); exit(0); } else if(strcmp(argv[i], "-w") == 0) { i++; width = atoi(argv[i]); } else if(strcmp(argv[i], "-h") == 0) { i++; height = atoi(argv[i]); } else if(strcmp(argv[i], "-wp") == 0) { i++; width_pic = atoi(argv[i]); } else if(strcmp(argv[i], "-hp") == 0) { i++; height_pic = atoi(argv[i]); } else if(strcmp(argv[i], "-q") == 0) { i++; quality = atoi(argv[i]); } else if(strcmp(argv[i], "-d") == 0) { i++; divider = atoi(argv[i]); } else if(strcmp(argv[i], "-p") == 0) { mp4box = 1; } else if(strcmp(argv[i], "-ic") == 0) { i++; image2_cnt = atoi(argv[i]); } else if(strcmp(argv[i], "-vc") == 0) { i++; video_cnt = atoi(argv[i]); } else if(strcmp(argv[i], "-of") == 0) { i++; jpeg_filename = argv[i]; of_set = 1; } else if(strcmp(argv[i], "-if") == 0) { i++; jpeg2_filename = argv[i]; of_set = 1; } else if(strcmp(argv[i], "-cf") == 0) { i++; pipe_filename = argv[i]; } else if(strcmp(argv[i], "-vf") == 0) { i++; h264_filename = argv[i]; } else if(strcmp(argv[i], "-sf") == 0) { i++; status_filename = argv[i]; } else if(strcmp(argv[i], "-pa") == 0) { autostart = 0; idle = 1; } else if(strcmp(argv[i], "-md") == 0) { motion_detection = 1; } else if(strcmp(argv[i], "-fp") == 0) { preview_mode = RES_4_3; } else if(strcmp(argv[i], "-audio") == 0) { audio_mode = 1; } else error("Invalid arguments"); } if(!of_set) error("Output file not specified"); // // init // if(autostart) start_all(); if(motion_detection) { if(system("motion") == -1) error("Could not start Motion"); } // // run // if(autostart) { if(pipe_filename != 0) printf("MJPEG streaming, ready to receive commands\n"); else printf("MJPEG streaming\n"); } else { if(pipe_filename != 0) printf("MJPEG idle, ready to receive commands\n"); else printf("MJPEG idle\n"); } struct sigaction action; memset(&action, 0, sizeof(struct sigaction)); action.sa_handler = term; sigaction(SIGTERM, &action, NULL); sigaction(SIGINT, &action, NULL); if(status_filename != 0) { status_file = fopen(status_filename, "w"); if(!status_file) error("Could not open/create status-file"); if(autostart) { if(!motion_detection) { fprintf(status_file, "ready"); } else fprintf(status_file, "md_ready"); } else fprintf(status_file, "halted"); fclose(status_file); } while(running) { if(pipe_filename != 0) { fd = open(pipe_filename, O_RDONLY | O_NONBLOCK); if(fd < 0) error("Could not open PIPE"); fcntl(fd, F_SETFL, 0); length = read(fd, readbuf, 20); close(fd); if(length) { if((readbuf[0]=='p') && (readbuf[1]=='m')) { stop_all(); readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; if(strcmp(readbuf, " 4_3") == 0) preview_mode = RES_4_3; else if(strcmp(readbuf, " 16_9_STD") == 0) preview_mode = RES_16_9_STD; else if(strcmp(readbuf, " 16_9_WIDE") == 0) preview_mode = RES_16_9_WIDE; start_all(); printf("Changed preview mode\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "ready"); fclose(status_file); } } else if((readbuf[0]=='c') && (readbuf[1]=='a')) { if(readbuf[3]=='1') { if(!capturing) { status = mmal_component_enable(h264encoder); if(status != MMAL_SUCCESS) error("Could not enable h264encoder"); pool_h264encoder = mmal_port_pool_create(h264encoder->output[0], h264encoder->output[0]->buffer_num, h264encoder->output[0]->buffer_size); if(!pool_h264encoder) error("Could not create pool"); status = mmal_connection_create(&con_cam_h264, camera->output[1], h264encoder->input[0], MMAL_CONNECTION_FLAG_TUNNELLING | MMAL_CONNECTION_FLAG_ALLOCATION_ON_INPUT); if(status != MMAL_SUCCESS) error("Could not create connecton camera -> video converter"); status = mmal_connection_enable(con_cam_h264); if(status != MMAL_SUCCESS) error("Could not enable connection camera -> video converter"); currTime = time(NULL); localTime = localtime (&currTime); if(mp4box) { asprintf(&filename_temp, h264_filename, video_cnt, localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday, localTime->tm_hour, localTime->tm_min, localTime->tm_sec); asprintf(&filename_temp2, "%s.h264", filename_temp); } else { asprintf(&filename_temp2, h264_filename, video_cnt, localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday, localTime->tm_hour, localTime->tm_min, localTime->tm_sec); } h264output_file = fopen(filename_temp2, "wb"); free(filename_temp2); if(mp4box) { if(audio_mode) { asprintf(&cmd_temp, "/usr/bin/arecord -q -D hw:1,0 -f S16_LE -t wav | /usr/bin/lame - %s.mp3 -S &", filename_temp); printf("Audio recording with \"%s\\n", cmd_temp); if(system(cmd_temp) == -1) error("Could not start audio recording"); } free(filename_temp); } if(!h264output_file) error("Could not open/create video-file"); status = mmal_port_enable(h264encoder->output[0], h264encoder_buffer_callback); if(status != MMAL_SUCCESS) error("Could not enable video port"); max = mmal_queue_length(pool_h264encoder->queue); for(i=0;i<max;i++) { MMAL_BUFFER_HEADER_T *h264buffer = mmal_queue_get(pool_h264encoder->queue); if(!h264buffer) error("Could not create video pool header"); status = mmal_port_send_buffer(h264encoder->output[0], h264buffer); if(status != MMAL_SUCCESS) error("Could not send buffers to video port"); } mmal_port_parameter_set_boolean(camera->output[1], MMAL_PARAMETER_CAPTURE, 1); if(status != MMAL_SUCCESS) error("Could not start capture"); printf("Capturing started\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); if(!motion_detection) fprintf(status_file, "video"); else fprintf(status_file, "md_video"); fclose(status_file); } capturing = 1; } } else { if(capturing) { mmal_port_parameter_set_boolean(camera->output[1], MMAL_PARAMETER_CAPTURE, 0); if(status != MMAL_SUCCESS) error("Could not stop capture"); status = mmal_port_disable(h264encoder->output[0]); if(status != MMAL_SUCCESS) error("Could not disable video port"); status = mmal_connection_destroy(con_cam_h264); if(status != MMAL_SUCCESS) error("Could not destroy connection camera -> video encoder"); mmal_port_pool_destroy(h264encoder->output[0], pool_h264encoder); if(status != MMAL_SUCCESS) error("Could not destroy video buffer pool"); status = mmal_component_disable(h264encoder); if(status != MMAL_SUCCESS) error("Could not disable video converter"); fclose(h264output_file); h264output_file = NULL; printf("Capturing stopped\n"); if(mp4box) { printf("Boxing started\n"); status_file = fopen(status_filename, "w"); if(!motion_detection) fprintf(status_file, "boxing"); else fprintf(status_file, "md_boxing"); fclose(status_file); asprintf(&filename_temp, h264_filename, video_cnt, localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday, localTime->tm_hour, localTime->tm_min, localTime->tm_sec); if(audio_mode) { asprintf(&cmd_temp, "/usr/bin/killall arecord > /dev/null"); if(system(cmd_temp) == -1) error("Could not stop audio recording"); free(cmd_temp); asprintf(&cmd_temp, "MP4Box -fps 25 -add %s.h264 -add %s.mp3 %s > /dev/null", filename_temp, filename_temp, filename_temp); } else { asprintf(&cmd_temp, "MP4Box -fps 25 -add %s.h264 %s > /dev/null", filename_temp, filename_temp); } if(system(cmd_temp) == -1) error("Could not start MP4Box"); asprintf(&filename_temp2, "%s.h264", filename_temp); remove(filename_temp2); free(filename_temp2); if (audio_mode) { asprintf(&filename_temp2, "%s.mp3", filename_temp); remove(filename_temp2); free(filename_temp2); } free(filename_temp); free(cmd_temp); printf("Boxing stopped\n"); } video_cnt++; if(status_filename != 0) { status_file = fopen(status_filename, "w"); if(!motion_detection) fprintf(status_file, "ready"); else fprintf(status_file, "md_ready"); fclose(status_file); } capturing = 0; } } } else if((readbuf[0]=='i') && (readbuf[1]=='m')) { capt_img(); } else if((readbuf[0]=='t') && (readbuf[1]=='l')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; time_between_pic = atoi(readbuf); if(time_between_pic) { if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "timelapse"); fclose(status_file); } timelapse = 1; printf("Timelapse started\n"); } else { if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "ready"); fclose(status_file); } timelapse = 0; printf("Timelapse stopped\n"); } } else if((readbuf[0]=='s') && (readbuf[1]=='h')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); MMAL_RATIONAL_T value = {cam_setting, 100}; status = mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_SHARPNESS, value); if(status != MMAL_SUCCESS) error("Could not set sharpness"); printf("Sharpness: %d\n", cam_setting); } else if((readbuf[0]=='c') && (readbuf[1]=='o')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); MMAL_RATIONAL_T value = {cam_setting, 100}; status = mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_CONTRAST, value); if(status != MMAL_SUCCESS) error("Could not set contrast"); printf("Contrast: %d\n", cam_setting); } else if((readbuf[0]=='b') && (readbuf[1]=='r')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); MMAL_RATIONAL_T value = {cam_setting, 100}; status = mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_BRIGHTNESS, value); if(status != MMAL_SUCCESS) error("Could not set brightness"); printf("Brightness: %d\n", cam_setting); } else if((readbuf[0]=='s') && (readbuf[1]=='a')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); MMAL_RATIONAL_T value = {cam_setting, 100}; status = mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_SATURATION, value); if(status != MMAL_SUCCESS) error("Could not set saturation"); printf("Saturation: %d\n", cam_setting); } else if((readbuf[0]=='i') && (readbuf[1]=='s')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); status = mmal_port_parameter_set_uint32(camera->control, MMAL_PARAMETER_ISO, cam_setting); if(status != MMAL_SUCCESS) error("Could not set ISO"); printf("ISO: %d\n", cam_setting); } else if((readbuf[0]=='v') && (readbuf[1]=='s')) { if(readbuf[3]=='1') { status = mmal_port_parameter_set_boolean(camera->control, MMAL_PARAMETER_VIDEO_STABILISATION, 1); printf("Video Stabilisation ON\n"); } else { status = mmal_port_parameter_set_boolean(camera->control, MMAL_PARAMETER_VIDEO_STABILISATION, 0); printf("Video Stabilisation OFF\n"); } if(status != MMAL_SUCCESS) error("Could not set video stabilisation"); } else if((readbuf[0]=='e') && (readbuf[1]=='c')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); status = mmal_port_parameter_set_int32(camera->control, MMAL_PARAMETER_EXPOSURE_COMP, cam_setting); if(status != MMAL_SUCCESS) error("Could not set exposure compensation"); printf("Exposure Compensation: %d\n", cam_setting); } else if((readbuf[0]=='e') && (readbuf[1]=='m')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; MMAL_PARAM_EXPOSUREMODE_T mode = MMAL_PARAM_EXPOSUREMODE_OFF; if(strcmp(readbuf, " auto") == 0) mode = MMAL_PARAM_EXPOSUREMODE_AUTO; else if(strcmp(readbuf, " night") == 0) mode = MMAL_PARAM_EXPOSUREMODE_NIGHT; else if(strcmp(readbuf, " nightpreview") == 0) mode = MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW; else if(strcmp(readbuf, " backlight") == 0) mode = MMAL_PARAM_EXPOSUREMODE_BACKLIGHT; else if(strcmp(readbuf, " spotlight") == 0) mode = MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT; else if(strcmp(readbuf, " sports") == 0) mode = MMAL_PARAM_EXPOSUREMODE_SPORTS; else if(strcmp(readbuf, " snow") == 0) mode = MMAL_PARAM_EXPOSUREMODE_SNOW; else if(strcmp(readbuf, " beach") == 0) mode = MMAL_PARAM_EXPOSUREMODE_BEACH; else if(strcmp(readbuf, " verylong") == 0) mode = MMAL_PARAM_EXPOSUREMODE_VERYLONG; else if(strcmp(readbuf, " fixedfps") == 0) mode = MMAL_PARAM_EXPOSUREMODE_FIXEDFPS; else if(strcmp(readbuf, " antishake") == 0) mode = MMAL_PARAM_EXPOSUREMODE_ANTISHAKE; else if(strcmp(readbuf, " fireworks") == 0) mode = MMAL_PARAM_EXPOSUREMODE_FIREWORKS; MMAL_PARAMETER_EXPOSUREMODE_T exp_mode = {{MMAL_PARAMETER_EXPOSURE_MODE,sizeof(exp_mode)}, mode}; status = mmal_port_parameter_set(camera->control, &exp_mode.hdr); if(status != MMAL_SUCCESS) error("Could not set exposure mode"); printf("Exposure mode changed\n"); } else if((readbuf[0]=='w') && (readbuf[1]=='b')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; MMAL_PARAM_AWBMODE_T awb_mode = MMAL_PARAM_AWBMODE_OFF; if(strcmp(readbuf, " auto") == 0) awb_mode = MMAL_PARAM_AWBMODE_AUTO; else if(strcmp(readbuf, " auto") == 0) awb_mode = MMAL_PARAM_AWBMODE_AUTO; else if(strcmp(readbuf, " sun") == 0) awb_mode = MMAL_PARAM_AWBMODE_SUNLIGHT; else if(strcmp(readbuf, " cloudy") == 0) awb_mode = MMAL_PARAM_AWBMODE_CLOUDY; else if(strcmp(readbuf, " shade") == 0) awb_mode = MMAL_PARAM_AWBMODE_SHADE; else if(strcmp(readbuf, " tungsten") == 0) awb_mode = MMAL_PARAM_AWBMODE_TUNGSTEN; else if(strcmp(readbuf, " fluorescent") == 0) awb_mode = MMAL_PARAM_AWBMODE_FLUORESCENT; else if(strcmp(readbuf, " incandescent") == 0) awb_mode = MMAL_PARAM_AWBMODE_INCANDESCENT; else if(strcmp(readbuf, " flash") == 0) awb_mode = MMAL_PARAM_AWBMODE_FLASH; else if(strcmp(readbuf, " horizon") == 0) awb_mode = MMAL_PARAM_AWBMODE_HORIZON; MMAL_PARAMETER_AWBMODE_T param = {{MMAL_PARAMETER_AWB_MODE,sizeof(param)}, awb_mode}; status = mmal_port_parameter_set(camera->control, ¶m.hdr); if(status != MMAL_SUCCESS) error("Could not set white balance"); printf("White balance changed\n"); } else if((readbuf[0]=='r') && (readbuf[1]=='o')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); status = mmal_port_parameter_set_int32(camera->output[0], MMAL_PARAMETER_ROTATION, cam_setting); if(status != MMAL_SUCCESS) error("Could not set rotation (0)"); status = mmal_port_parameter_set_int32(camera->output[1], MMAL_PARAMETER_ROTATION, cam_setting); if(status != MMAL_SUCCESS) error("Could not set rotation (1)"); status = mmal_port_parameter_set_int32(camera->output[2], MMAL_PARAMETER_ROTATION, cam_setting); if(status != MMAL_SUCCESS) error("Could not set rotation (2)"); printf("Rotation: %d\n", cam_setting); } else if((readbuf[0]=='q') && (readbuf[1]=='u')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); status = mmal_port_parameter_set_uint32(jpegencoder2->output[0], MMAL_PARAMETER_JPEG_Q_FACTOR, cam_setting); if(status != MMAL_SUCCESS) error("Could not set quality"); printf("Quality: %d\n", cam_setting); } else if((readbuf[0]=='b') && (readbuf[1]=='i')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting_long = strtoull(readbuf, NULL, 0); h264encoder->output[0]->format->bitrate = cam_setting_long; status = mmal_port_format_commit(h264encoder->output[0]); if(status != MMAL_SUCCESS) error("Could not set bitrate"); printf("Bitrate: %lu\n", cam_setting_long); } else if((readbuf[0]=='r') && (readbuf[1]=='u')) { if(readbuf[3]=='0') { stop_all(); idle = 1; printf("Stream halted\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "halted"); fclose(status_file); } } else { start_all(); idle = 0; printf("Stream continued\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "ready"); fclose(status_file); } } } else if((readbuf[0]=='m') && (readbuf[1]=='d')) { if(readbuf[3]=='0') { motion_detection = 0; if(system("killall motion") == -1) error("Could not stop Motion"); printf("Motion detection stopped\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "ready"); fclose(status_file); } } else { motion_detection = 1; if(system("motion") == -1) error("Could not start Motion"); printf("Motion detection started\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "md_ready"); fclose(status_file); } } } } } if(timelapse) { tl_cnt++; if(tl_cnt >= time_between_pic) { if(capturing == 0) { capt_img(); tl_cnt = 0; } } } usleep(100000); } printf("SIGINT/SIGTERM received, stopping\n"); // // tidy up // if(!idle) stop_all(); return 0; }
static void sig_master(int unused) { stop_all(SIGINT); //jt_quit(0, NULL); }
int main (int argc, char* argv[]) { monitor(); int i, fd, length; int watchdog = 0, watchdog_errors = 0; int onesec_check = 0; time_t last_pv_time = 0, pv_time; char readbuf[MAX_COMMAND_LEN]; bcm_host_init(); // // read arguments // for(i=1; i<argc; i++) { if(strcmp(argv[i], "--version") == 0) { printf("RaspiMJPEG Version %s\n", VERSION); exit(0); } else if(strcmp(argv[i], "-md") == 0) { cfg_val[c_motion_detection] = 1; } } //default base media path asprintf(&cfg_stru[c_media_path], "%s", "/var/www/media"); // // read configs and init // read_config("/etc/raspimjpeg", 1); if (cfg_stru[c_user_config] != 0) read_config(cfg_stru[c_user_config], 0); createPath(cfg_stru[c_log_file], cfg_stru[c_base_path]); if (cfg_stru[c_boxing_path] != NULL) { char *bpath; asprintf(&bpath, "%s/temp", cfg_stru[c_boxing_path]); createPath(bpath, cfg_stru[c_base_path]); free(bpath); } printLog("RaspiMJPEG Version %s\n", VERSION); if(cfg_val[c_autostart]) start_all(0); // // run // if(cfg_val[c_autostart]) { if(cfg_stru[c_control_file] != 0){ printLog("MJPEG streaming, ready to receive commands\n"); //kick off motion detection at start if required. if(cfg_val[c_motion_detection] && cfg_val[c_motion_external]) { printLog("Autostart external motion kill any runnng motion\n"); if(system("killall motion") == -1) error("Could not stop external motion", 1); sleep(1); printLog("Autostart external motion start external motion\n"); if(system("motion") == -1) error("Could not start external motion", 1); } } else { printLog("MJPEG streaming\n"); } } else { if(cfg_stru[c_control_file] != 0) printLog("MJPEG idle, ready to receive commands\n"); else printLog("MJPEG idle\n"); } updateStatus(); struct sigaction action; memset(&action, 0, sizeof(struct sigaction)); action.sa_handler = term; sigaction(SIGTERM, &action, NULL); sigaction(SIGINT, &action, NULL); //Clear out anything in FIFO first do { fd = open(cfg_stru[c_control_file], O_RDONLY | O_NONBLOCK); if(fd < 0) error("Could not open PIPE", 1); fcntl(fd, F_SETFL, 0); length = read(fd, readbuf, 60); close(fd); } while (length != 0); //Send restart signal to scheduler send_schedulecmd("9"); // Main forever loop while(running) { if(cfg_stru[c_control_file] != 0) { fd = open(cfg_stru[c_control_file], O_RDONLY | O_NONBLOCK); if(fd < 0) error("Could not open PIPE", 1); fcntl(fd, F_SETFL, 0); length = read(fd, readbuf, MAX_COMMAND_LEN -2); close(fd); if(length) { process_cmd(readbuf, length); } } if(timelapse) { tl_cnt++; if(tl_cnt >= cfg_val[c_tl_interval]) { if(i_capturing == 0) { capt_img(); tl_cnt = 0; } } } // check to see if image preview changing if (!idle && cfg_val[c_watchdog_interval] > 0) { if(watchdog++ > cfg_val[c_watchdog_interval]) { watchdog = 0; pv_time = get_mtime(cfg_stru[c_preview_path]); if (pv_time == 0) { watchdog_errors++; } else { if (pv_time > last_pv_time) { watchdog_errors = 0; } else { watchdog_errors++; } last_pv_time = pv_time; } if (watchdog_errors >= cfg_val[c_watchdog_errors]) { printLog("Watchdog detected problem. Stopping"); running = 0; } } } else { watchdog_errors = 0; } if (++onesec_check >= 10) { //run check on background boxing every 10 ticks and check for video timer if capturing onesec_check = 0; check_box_files(); if (v_capturing && video_stoptime > 0) { if (time(NULL) >= video_stoptime) { printLog("Stopping video from timer\n"); stop_video(0); } } } usleep(100000); } if(system("killall motion") == -1) error("Could not stop external motion", 1); printLog("SIGINT/SIGTERM received, stopping\n"); // // tidy up // if(!idle) stop_all(); return 0; }
void samples_device::device_reset() { stop_all(); }
void QUrlQueueServer::dispatch(msgpack::rpc::request req) { try { std::string method; req.method().convert(&method); if(method == "push") { msgpack::type::tuple<int, std::string, std::string> params; req.params().convert(¶ms); push_url(req, params.get<0>(), params.get<1>(), params.get<2>()); } else if(method == "pop") { pop_url(req); } else if(method == "push_url_front") { msgpack::type::tuple<int, std::string, std::string> params; req.params().convert(¶ms); push_url_front(req, params.get<0>(), params.get<1>(), params.get<2>()); } else if(method == "start_dump_all") { start_dump_all(req); } else if(method == "dump_all") { dump_all(req); } else if(method == "stats") { stats(req); } else if(method == "set_default_interval") { msgpack::type::tuple<int> params; req.params().convert(¶ms); set_default_interval(req, params.get<0>()); } else if(method == "set_site_interval") { msgpack::type::tuple<std::string, int> params; req.params().convert(¶ms); set_site_interval(req, params.get<0>(), params.get<1>()); } else if(method == "stat_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); stat_site(req, params.get<0>()); } else if(method == "dump_ordered_site") { msgpack::type::tuple<int> params; req.params().convert(¶ms); dump_ordered_site(req, params.get<0>()); } else if(method == "start_all") { start_all(req); } else if(method == "stop_all") { stop_all(req); } else if(method == "start_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); start_site(req, params.get<0>()); } else if(method == "stop_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); stop_site(req, params.get<0>()); } else if(method == "clear_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); clear_site(req, params.get<0>()); } else if(method == "start_dump_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); start_dump_site(req, params.get<0>()); } else if(method == "dump_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); dump_site(req, params.get<0>()); } else if(method == "clear_empty_site") { clear_empty_site(req); } else { req.error(msgpack::rpc::NO_METHOD_ERROR); } } catch (msgpack::type_error& e) { req.error(msgpack::rpc::ARGUMENT_ERROR); return; } catch (std::exception& e) { req.error(std::string(e.what())); return; } }
void play_hmi (void * arg) { int i; int pos = 0x308; int n_chunks = 0; int low_dtime; int low_chunk; int csec; // pid_t loc_pid; int qid; int ipc_read = 0; int k=0; struct msgbuf *rcv; Track_info *t_info; //printf ("play_hmi\n");//######### stop = 0; ipc_read=0; // loc_pid=fork(); /* switch (loc_pid) { case 0: break; case -1: return -1; default: atexit(kill_ipc); return loc_pid; }*/ // signal(SIGTERM, my_quit); rcv=d_malloc(sizeof(long) + 16); rcv->mtype=1; rcv->mtext[0]='0'; sleep(2); qid=msgget ((key_t) ('l'<<24) | ('d'<<16) | ('e'<<8) | 's', 0660); if(qid == -1) { return; } do { ipc_read=do_ipc(qid,rcv,0); } while(rcv->mtext[0] != 'p'); stop=0; rcv->mtext[0] = '0'; seq_init(); n_chunks=data[0x30]; t_info = d_malloc(sizeof(Track_info)*n_chunks); while(1) { for(i=0;i<n_chunks;i++) { t_info[i].position = pos + 12; t_info[i].status = PLAYING; t_info[i].time = get_dtime(data,&t_info[i].position); pos += (( (0xff & data[pos + 5]) << 8 ) + (0xff & data[pos + 4]); } SEQ_START_TIMER(); do { low_chunk = -1; k++; i=0; do { if (t_info[i].status == PLAYING) low_chunk = i; i++; } while((low_chunk <=0) && (i<n_chunks); if (low_chunk == -1) break; low_dtime = t_info[low_chunk].time; for(i=1;i<n_chunks;i++) { if ((t_info[i].time < low_dtime) && (t_info[i].status == PLAYING)) { low_dtime = t_info[i].time; low_chunk = i; } } //if (low_dtime < 0) //printf("Serious warning: d_time negative!!!!!!\n"); csec = 0.86 * low_dtime; //flush sequencer buffer after 20 events if (k == 20) { ioctl(seqfd, SNDCTL_SEQ_SYNC); k = 0; } SEQ_WAIT_TIME(csec); t_info[low_chunk].status = do_track_event(data,&t_info[low_chunk].position); if (t_info[low_chunk].status == 3) { //printf("Error playing data in chunk %d\n",low_chunk); t_info[low_chunk].status = STOPPED; } if (t_info[low_chunk].status == PLAYING) t_info[low_chunk].time += get_dtime(data,&t_info[low_chunk].position); //Check if the song has reached the end stop = t_info[0].status; for(i=1;i<n_chunks;i++) stop &= t_info[i].status; if((do_ipc(qid,rcv,IPC_NOWAIT) > 0) && (rcv->mtext[0]=='p')) { n_chunks=data[0x30]; t_info = realloc(t_info,sizeof(Track_info)*n_chunks); stop = 1; rcv->mtext[0] = '0'; stop_all(); } } while(!stop); SEQ_STOP_TIMER(); if( stop == 2) { stop_all(); do { ipc_read=do_ipc(qid,rcv,0); } while(rcv->mtext[0] != 'p'); rcv->mtext[0] = '0'; n_chunks=data[0x30]; t_info = realloc(t_info,sizeof(Track_info)*n_chunks); stop = 0; } pos=0x308; } d_free(data); d_free(t_info); d_free(rcv); }
void process_cmd(char *readbuf, int length) { typedef enum pipe_cmd_type{ca,im,tl,px,bo,tv,an,as,at,ac,ab,sh,co,br,sa,is,vs,rl,ec,em,wb,mm,ie,ce,ro,fl,ri,ss,qu,pv,bi,ru,md,sc,rs,bu,mn,mt,mi,mb,me,mx,mf,vm,vp,wd,sy,cn,st} pipe_cmd_type; char pipe_cmds[] = "ca,im,tl,px,bo,tv,an,as,at,ac,ab,sh,co,br,sa,is,vs,rl,ec,em,wb,mm,ie,ce,ro,fl,ri,ss,qu,pv,bi,ru,md,sc,rs,bu,mn,mt,mi,mb,me,mx,mf,vm,vp,wd,sy,cn,st"; pipe_cmd_type pipe_cmd; int parcount; char pars[128][10]; long int par0; char cmd[3]; char par[MAX_COMMAND_LEN]; char *parstring=0, *temp; int key = -1; if (length < 2 || length > (MAX_COMMAND_LEN - 2)) return; //Get cmd strncpy(cmd, readbuf, 2); //find 2 letter command and translate into enum temp = strstr(pipe_cmds, cmd); if (temp == NULL) return; pipe_cmd = (pipe_cmd_type)((temp - pipe_cmds) / 3); if(length > 3) { strcpy(par, readbuf + 3); par[length-3] = 0; //extract space separated numeric parameters // and make separate string parameter (strtok changes the original) asprintf(&parstring, "%s", par); parcount = 0; temp = strtok(par, " "); while(parcount<10 && temp != NULL) { strcpy(pars[parcount], temp); parcount++; temp = strtok(NULL, " "); } par0 = strtol(pars[0], NULL, 10); } else { par0 = 0; } switch(pipe_cmd) { case ca: if(par0 == 1) { if (parcount > 1) { long vtime = strtol(pars[1], NULL, 10); video_stoptime = time(NULL) + vtime; printLog("Capturing %d seconds\n", vtime); } start_video(0); } else { stop_video(0); } break; case im: capt_img(); break; case tl: if(par0) { timelapse = 1; lapse_cnt = 1; updateStatus(); printLog("Timelapse started\n"); } else { image2_cnt++; timelapse = 0; updateStatus(); printLog("Timelapse stopped\n"); } break; case px: stop_all(); addUserValue(c_video_width, pars[0]); addUserValue(c_video_height, pars[1]); addUserValue(c_video_fps, pars[2]); addUserValue(c_MP4Box_fps, pars[3]); addUserValue(c_image_width, pars[4]); addUserValue(c_image_height, pars[5]); start_all(0); break; case bo: addUserValue(c_MP4Box, pars[0]); break; case tv: addUserValue(c_tl_interval, pars[0]); break; case an: addUserValue(c_annotation, parstring); break; case as: addUserValue(c_anno_text_size, pars[0]); break; case at: addUserValue(c_anno3_custom_text_colour, pars[0]); addUserValue(c_anno3_custom_text_Y, pars[1]); addUserValue(c_anno3_custom_text_U, pars[2]); addUserValue(c_anno3_custom_text_V, pars[3]); break; case ac: addUserValue(c_anno3_custom_background_colour, pars[0]); addUserValue(c_anno3_custom_background_Y, pars[1]); addUserValue(c_anno3_custom_background_U, pars[2]); addUserValue(c_anno3_custom_background_V, pars[3]); break; case ab: addUserValue(c_anno_background, pars[0]); break; case sh: key = c_sharpness; break; case co: key = c_contrast; break; case br: key = c_brightness; break; case sa: key = c_saturation; break; case is: key = c_iso; break; case vs: key = c_video_stabilisation; break; case rl: key = c_raw_layer; break; case ec: key = 1000 + c_exposure_compensation; break; case em: key = 1000 + c_exposure_mode; break; case wb: key = 1000 + c_white_balance; break; case mm: key = 1000 + c_metering_mode; break; case ie: key = 1000 + c_image_effect; break; case ce: addUserValue(c_colour_effect_u, pars[1]); addUserValue(c_colour_effect_v, pars[2]); key = c_colour_effect_en; break; case ro: key = c_rotation; break; case fl: if(par0 & 1) addUserValue(c_hflip, "1"); else addUserValue(c_hflip, "0"); if((par0 >> 1) & 1) addUserValue(c_vflip, "1"); else addUserValue(c_vflip, "0"); cam_set(c_hflip); break; case ri: addUserValue(c_sensor_region_y, pars[1]); addUserValue(c_sensor_region_w, pars[2]); addUserValue(c_sensor_region_h, pars[3]); key = c_sensor_region_x; break; case ss: addUserValue(c_shutter_speed, pars[0]); key = c_shutter_speed; break; case qu: key = c_image_quality; break; case pv: stop_all(); addUserValue(c_quality, pars[0]); addUserValue(c_width, pars[1]); addUserValue(c_divider, pars[2]); start_all(0); break; case bi: stop_all(); addUserValue(c_video_bitrate, pars[0]); start_all(0); break; case st: stop_all(); addUserValue(c_stat_pass, pars[0]); start_all(0); break; case wd: addUserValue(c_watchdog_interval, pars[0]); addUserValue(c_watchdog_errors, pars[1]); break; case ru: if (par0 == 0) { stop_all(); idle = 1; printLog("Stream halted\n"); } else { start_all(1); idle = 0; printLog("Stream continued\n"); } updateStatus(); break; case mx: key = c_motion_external; //If switching to internal with motion detection on then try to kill external motion if (cfg_val[c_motion_detection] != 0 && !par0) { if(system("killall motion") == -1) error("Could not stop external motion", 1); printLog("External motion detection stopped\n"); } break; case md: exec_macro(cfg_stru[c_do_cmd], readbuf); stop_all(); if (cfg_val[c_motion_external]) { if(par0 == 0) { if(system("killall motion") == -1) error("Could not stop external motion", 1); printLog("External motion detection stopped\n"); } else { if (cfg_val[c_motion_detection] == 0) { if(system("motion") == -1) error("Could not start external motion", 1); printLog("External motion detection started\n"); } else { printLog("Motion already running. md 1 ignored\n"); } } } else { if(par0 == 0) { printLog("Internal motion detection stopped\n"); } else { printLog("Internal motion detection started\n"); } } cfg_val[c_motion_detection] = par0?1:0; start_all(0); updateStatus(); break; case sc: set_counts(); printLog("Scan for highest count\n"); break; case rs: printLog("Reset settings to defaults\n"); stop_all(); read_config("/etc/raspimjpeg", 1); saveUserConfig(cfg_stru[c_user_config]); start_all(0); break; case bu: key = c_video_buffer; break; case vp: stop_all(); addUserValue(c_vector_preview, pars[0]); start_all(0); break; case mn: key = c_motion_noise; break; case mt: key = c_motion_threshold; break; case mi: key = c_motion_image + 1000; break; case mb: key = c_motion_startframes; break; case me: key = c_motion_stopframes; break; case mf: key = c_motion_file; break; case vm: key = c_vector_mode; break; case sy: exec_macro(parstring, NULL); break; case cn: stop_all(); addUserValue(c_camera_num, pars[0]); start_all(0); break; default: printLog("Unrecognised pipe command\n"); break; }