/* ############################################## ##Int ModuleResize(Int argc, Char *argv[]) ############################################## */ Int ModuleResize(Int argc, Char *argv[]) { Uns initMask = 0; Int status = EXIT_SUCCESS; Rendezvous_Attrs rzvAttrs = Rendezvous_Attrs_DEFAULT; Fifo_Attrs fAttrs = Fifo_Attrs_DEFAULT; Rendezvous_Handle hRendezvousInit = NULL; Rendezvous_Handle hRendezvousWriter = NULL; Rendezvous_Handle hRendezvousCleanup = NULL; Int numThreads = 0; pthread_t id_listen[5] = {0}; Void *ret; char devicebuf[16] = {0}; CaptureEnv captureEnv; WriterEnv writerEnv; WriterEnv writerLowRateEnv; DetectEnv detectEnv; VideoEnv videoEnv; VideoEnv videoLowRateEnv;//dd VideoEnv LowRateResize; AudioEnv audioEnv; CtrlEnv ctrlEnv; char box_version[64] = {0}; OutputVideoInfo outputhandle; textinfo *texthandle; int DHCPVAL = 0, tmp = 0; char gateway[255] = {0}; struct sched_param schedParam; pthread_t captureThread; pthread_t detectThread; pthread_t writerThread; pthread_t writerLowThread; pthread_t videoThread; pthread_t audioThread; pthread_t videoLowThread; pthread_t resizeLowThread; #ifdef DSS_ENC_1100_1200 pthread_t webListenThread; #endif pthread_attr_t attr; int index = 0; int result = 0; char ts_version[128] = {0}; /* Zero out the thread environments */ Dmai_clear(captureEnv); Dmai_clear(writerEnv); Dmai_clear(videoEnv); Dmai_clear(audioEnv); Dmai_clear(ctrlEnv); mid_task_init(); trace_init(); open_gpio_port(); ts_build_get_version(ts_version, sizeof(ts_version)); strcpy(box_version, BOX_VER); strcat(box_version, CODE_TYPE); strcat(box_version, DEUBG); printf("[%s] Module Encode Program %s V%s\n", CODE_COND, BOARD_TYPE, box_version); printf("the build time is %s,the git vesion is %s.the ts version is %s\n\n", g_make_build_date, _VERSION, ts_version); initMutexPthread(); InitgblCommonMutex(); InitSysParams(); initOutputVideoParam(); InitHVTable(&gHVTable); // webgetDHCPFlag(tmp, &DHCPVAL); // readDHCPValue(DHCPCONFIG_FILE, &DHCPVAL); // setDHCPFlag(DHCPVAL); gLogoinfo = initLogoMod(); initTextinfo(); ReadEncodeParamTable(CONFIG_NAME, &gSysParaT); DHCPVAL = gSysParaT.sysPara.nTemp[0]; printf("----mic=%x:%x:%x:%x:%x:%x\n",gSysParaT.sysPara.szMacAddr[0],gSysParaT.sysPara.szMacAddr[1],gSysParaT.sysPara.szMacAddr[2], gSysParaT.sysPara.szMacAddr[3],gSysParaT.sysPara.szMacAddr[4],gSysParaT.sysPara.szMacAddr[5]); ReadLowbitParamTable(LOWBIT_PARAM, &gSysParaT); memset(&outputhandle, 0, sizeof(OutputVideoInfo)); getOutputvideohandle(&outputhandle); readOutputVideoParam(VIDEOENCODE_FILE, &outputhandle); setOutputvideohandle(&outputhandle); //sleep(10); ReadLogoinfo(LOGOCONFIGNAME, gLogoinfo); //setLogoInfoHandle(logoEnv); //sleep(10); texthandle = getTextInfoHandle(); readTextFromfile(ADDTEXT_FILE, texthandle); // DEBUG(DL_DEBUG, "%d,%d,%d,%d,%d,%d,%s\n", DHCPVAL, texthandle->xpos, texthandle->ypos, // texthandle->enable, texthandle->showtime, texthandle->alpha, texthandle->msgtext); // sleep(10); #ifdef DSS_ENC_1100_1200 ReadProtocolIni(PROTOCOL_NAME, &gProtocol); #endif ReadRemoteCtrlIndex(REMOTE_NAME, &index); /*Read I frames Interval*/ ReadIframeInterval(IFRAMES_NAME); /*green Save Module*/ app_init_green_adjust_module(); #ifdef CL4000_DVI app_init_screen_adjust_module(); #endif gblSetRemoteIndex(index); ReadHVTable(&gHVTable, 0); ReadHVTable(&gHVTable, 1); #ifdef CL4000_DVI_SDI ReadIPParamTable(IP_PARAM, &gSysParaT); #endif if(DHCPVAL) { printf("i will set dhcp.\n"); #if 1 system("kill -1 `cat /var/run/dhcpcd-eth0.pid`"); system("/sbin/dhcpcd eth0"); system("ifconfig eth0"); #endif gSysParaT.sysPara.dwNetMark = GetNetmask("eth0"); gSysParaT.sysPara.dwAddr = GetIPaddr("eth0"); get_gateway(gateway); gSysParaT.sysPara.dwGateWay = get_gateway(gateway); DEBUG(DL_DEBUG, "gateway =%s\n", gateway); } else { printf("i will set static ip.\n"); SetEthConfigIP(gSysParaT.sysPara.dwAddr, gSysParaT.sysPara.dwNetMark); SetEthConfigGW(gSysParaT.sysPara.dwGateWay); } system("ifconfig"); strcpy(gSysParaT.sysPara.strVer, box_version); initSetParam(); DEBUG(DL_DEBUG, "logo=%d text=%d ,texthandle->enable=%d,texthandle->showtime=%d\n", outputhandle.logo_show, outputhandle.text_show, texthandle->enable, texthandle->showtime); #ifdef DSS_ENC_1100_1200 /*open lcd initial*/ OpenLCDCom(); //matchbox ++ gblLoadIDX(); //matchbox ++ if(-2 == ReadDeviceType(DTYPECONFIG_NAME, 1)) { ReadDeviceType(DTYPECONFIG_NAME, 0); } GetDeviceType(devicebuf); DEBUG(DL_DEBUG, "DTYPECONFIG_NAME gDeviceType = %s\n", devicebuf); #endif /*取消PIPE坏的信号*/ Signal(SIGPIPE, SIG_IGN); /* Set the priority of this whole process to max (requires root) */ setpriority(PRIO_PROCESS, 0, -20); /*初始化高码流视频编码库参数*/ InitVideoEncParams(&gSysParaT.videoPara[PORT_ONE]); /*初始化低码流视频编码库参数*/ InitLowRateParams(&gSysParaT.videoPara[PORT_TWO]); /*初始化音频编码库参数*/ InitAudioEncParams(&gSysParaT.audioPara[PORT_ONE]); /* Initialize the mutex which protects the global data */ pthread_mutex_init(&gbl.mutex, NULL); /* Initialize Codec Engine runtime */ CERuntime_init(); /* Initialize Davinci Multimedia Application Interface */ Dmai_init(); closeWatchDog(); mid_timer_init(); initWatchDog(); #ifdef CL4000_DVI_SDI if(gblGetRemoteIndex() < MAX_FAR_CTRL_NUM) { result = InitRemoteStruct(gblGetRemoteIndex()); } gRemoteFD = CameraCtrlInit(PORT_COM2); if(gRemoteFD <= 0) { DEBUG(DL_ERROR, "Initial CameraCtrlInit() Error\n"); } #else #ifndef ENABLE_DEUBG if(gblGetRemoteIndex() < MAX_FAR_CTRL_NUM) { result = InitRemoteStruct(gblGetRemoteIndex()); } gRemoteFD = CameraCtrlInit(PORT_COM1); if(gRemoteFD <= 0) { DEBUG(DL_ERROR, "Initial CameraCtrlInit() Error\n"); } #endif #endif CreateTCPTask(id_listen); /* Initialize the logs. Must be done after CERuntime_init() */ /* if(TraceUtil_start(engine->engineName) != TRACEUTIL_SUCCESS) { ERR("Failed to TraceUtil_start\n"); cleanup(EXIT_FAILURE); } */ //initMask |= LOGSINITIALIZED; app_set_logoshow_flag(outputhandle.logo_show); app_set_textshow_flag(outputhandle.text_show) ; //setShowLogoTextFlag(outputhandle->logotext); addtextdisplay(texthandle); /* Determine the number of threads needing synchronization */ numThreads = 1; /*视频线程个数*/ numThreads += 7; /*音频线程个数*/ numThreads += 1; /* Create the objects which synchronizes the thread init and cleanup */ hRendezvousInit = Rendezvous_create(numThreads, &rzvAttrs); hRendezvousCleanup = Rendezvous_create(numThreads, &rzvAttrs); hRendezvousWriter = Rendezvous_create(3, &rzvAttrs); if(hRendezvousInit == NULL || hRendezvousCleanup == NULL || hRendezvousWriter == NULL) { ERR("Failed to create Rendezvous objects\n"); cleanup(EXIT_FAILURE); } /* Initialize the thread attributes */ if(pthread_attr_init(&attr)) { ERR("Failed to initialize thread attrs\n"); cleanup(EXIT_FAILURE); } /* Force the thread to use custom scheduling attributes */ if(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) { ERR("Failed to set schedule inheritance attribute\n"); cleanup(EXIT_FAILURE); } /* Set the thread to be fifo real time scheduled */ if(pthread_attr_setschedpolicy(&attr, SCHED_FIFO)) { ERR("Failed to set FIFO scheduling policy\n"); cleanup(EXIT_FAILURE); } /* Create the capture fifos */ captureEnv.to_video_c = Fifo_create(&fAttrs); captureEnv.from_video_c = Fifo_create(&fAttrs); captureEnv.to_resize_c = Fifo_create(&fAttrs); captureEnv.from_resize_c = Fifo_create(&fAttrs); if(captureEnv.to_video_c == NULL || captureEnv.from_video_c == NULL || captureEnv.to_resize_c == NULL || captureEnv.from_resize_c == NULL) { ERR("Failed to open display fifos\n"); cleanup(EXIT_FAILURE); } LowRateResize.to_videoresize_c = Fifo_create(&fAttrs); LowRateResize.from_videoresize_c = Fifo_create(&fAttrs); if(LowRateResize.to_videoresize_c == NULL || LowRateResize.from_videoresize_c == NULL) { ERR("Failed to open Resize fifos\n"); cleanup(EXIT_FAILURE); } /* Set the capture thread priority */ schedParam.sched_priority = CAPTURE_THREAD_PRIORITY; if(pthread_attr_setschedparam(&attr, &schedParam)) { ERR("Failed to set scheduler parameters\n"); cleanup(EXIT_FAILURE); } /* Create the capture thread */ captureEnv.hRendezvousInit = hRendezvousInit; captureEnv.hRendezvousCleanup = hRendezvousCleanup; DEBUG(DL_DEBUG, "captureThrFxn thread!!!!\n"); if(pthread_create(&captureThread, &attr, captureThrFxn, &captureEnv)) { ERR("Failed to create capture thread\n"); cleanup(EXIT_FAILURE); } /* Create the writer fifos */ writerEnv.to_video_c = Fifo_create(&fAttrs); writerEnv.from_video_c = Fifo_create(&fAttrs); writerLowRateEnv.to_writelow_c = Fifo_create(&fAttrs); writerLowRateEnv.from_writelow_c = Fifo_create(&fAttrs); if(writerEnv.to_video_c == NULL || writerEnv.from_video_c == NULL || writerLowRateEnv.to_writelow_c == NULL || writerLowRateEnv.from_writelow_c == NULL) { ERR("Failed to open display fifos\n"); cleanup(EXIT_FAILURE); } initMask |= CAPTURETHREADCREATED ; /*detect thread*/ detectEnv.hRendezvousInit = hRendezvousInit; detectEnv.hRendezvousCleanup = hRendezvousCleanup; /* Set the video thread priority */ schedParam.sched_priority = DETECT_THREAD_PRIORITY; if(pthread_attr_setschedparam(&attr, &schedParam)) { ERR("Failed to set scheduler parameters\n"); cleanup(EXIT_FAILURE); } if(pthread_create(&detectThread, &attr, detectThrFxn, &detectEnv)) { ERR("Failed to create detect thread\n"); cleanup(EXIT_FAILURE); } initMask |= DETECTTHREADCREATED ; /* Set the video thread priority */ schedParam.sched_priority = VIDEO_THREAD_PRIORITY; if(pthread_attr_setschedparam(&attr, &schedParam)) { ERR("Failed to set scheduler parameters\n"); cleanup(EXIT_FAILURE); } DEBUG(DL_DEBUG, "videoThrFxn thread!!!!\n"); /* Create the video thread */ videoEnv.hRendezvousInit = hRendezvousInit; videoEnv.hRendezvousCleanup = hRendezvousCleanup; videoEnv.hRendezvousWriter = hRendezvousWriter; videoEnv.to_capture = captureEnv.from_video_c; videoEnv.from_capture = captureEnv.to_video_c; videoEnv.to_writer = writerEnv.from_video_c; videoEnv.from_writer = writerEnv.to_video_c; videoEnv.videoEncoder = engine->videoEncoders->codecName; videoEnv.engineName = engine->engineName; if(pthread_create(&videoThread, &attr, videoThrFxn, &videoEnv)) { ERR("Failed to create video thread\n"); cleanup(EXIT_FAILURE); } initMask |= VIDEOTHREADCREATED; /* Create the videoResize thread */ videoLowRateEnv.hRendezvousInit = hRendezvousInit; videoLowRateEnv.hRendezvousCleanup = hRendezvousCleanup; videoLowRateEnv.hRendezvousWriter = hRendezvousWriter; videoLowRateEnv.to_resize = LowRateResize.from_videoresize_c; videoLowRateEnv.from_resize = LowRateResize.to_videoresize_c; videoLowRateEnv.from_writer = writerLowRateEnv.to_writelow_c; videoLowRateEnv.to_writer = writerLowRateEnv.from_writelow_c; videoLowRateEnv.videoEncoder = engine->videoEncoders->codecName; videoLowRateEnv.engineName = engine->engineName; DEBUG(DL_DEBUG, "videoLowRateThrFxn thread!!!!\n"); if(pthread_create(&videoLowThread, &attr, videoLowRateThrFxn, &videoLowRateEnv)) { ERR("Failed to create video thread\n"); cleanup(EXIT_FAILURE); } initMask |= VIDEOLOWRATETHREAD; /* Create the video thread */ LowRateResize.hRendezvousInit = hRendezvousInit; LowRateResize.hRendezvousCleanup = hRendezvousCleanup; LowRateResize.hRendezvousWriter = hRendezvousWriter; LowRateResize.from_capture = captureEnv.to_resize_c; LowRateResize.to_capture = captureEnv.from_resize_c; LowRateResize.videoEncoder = engine->videoEncoders->codecName; LowRateResize.engineName = engine->engineName; /* Set the video thread priority */ schedParam.sched_priority = VIDEO_THREAD_PRIORITY; if(pthread_attr_setschedparam(&attr, &schedParam)) { ERR("Failed to set scheduler parameters\n"); cleanup(EXIT_FAILURE); } DEBUG(DL_DEBUG, "ResizeLowThrFxn thread!!!!\n"); if(pthread_create(&resizeLowThread, &attr, ResizeLowThrFxn, &LowRateResize)) { ERR("Failed to create video thread\n"); cleanup(EXIT_FAILURE); } initMask |= RESIZELOWRATETHREAD; Rendezvous_meet(hRendezvousWriter); /* Set the writer thread priority */ schedParam.sched_priority = WRITER_THREAD_PRIORITY; if(pthread_attr_setschedparam(&attr, &schedParam)) { ERR("Failed to set scheduler parameters\n"); cleanup(EXIT_FAILURE); } /* Create the writer thread */ writerEnv.hRendezvousInit = hRendezvousInit; writerEnv.hRendezvousCleanup = hRendezvousCleanup; writerEnv.outBufSize = videoEnv.outBufSize; DEBUG(DL_DEBUG, "writerThrFxn thread!!!!\n"); if(pthread_create(&writerThread, &attr, writerThrFxn, &writerEnv)) { ERR("Failed to create writer thread\n"); cleanup(EXIT_FAILURE); } initMask |= WRITERTHREADCREATED; /* Create the writer thread */ writerLowRateEnv.hRendezvousInit = hRendezvousInit; writerLowRateEnv.hRendezvousCleanup = hRendezvousCleanup; writerLowRateEnv.outBufSize = videoLowRateEnv.outBufSize; DEBUG(DL_DEBUG, "writerLowThrFxn thread!!!!\n"); if(pthread_create(&writerLowThread, &attr, writerLowThrFxn, &writerLowRateEnv)) { ERR("Failed to create writerResize thread\n"); cleanup(EXIT_FAILURE); } initMask |= WRITELOWRATETHREAD; /* Set the thread priority */ schedParam.sched_priority = AUDIO_THREAD_PRIORITY; if(pthread_attr_setschedparam(&attr, &schedParam)) { ERR("Failed to set scheduler parameters\n"); cleanup(EXIT_FAILURE); } DEBUG(DL_DEBUG, "Audio thread Function!!!!\n"); /* Create the audio thread */ audioEnv.hRendezvousInit = hRendezvousInit; audioEnv.hRendezvousCleanup = hRendezvousCleanup; audioEnv.engineName = engine->engineName; audioEnv.audioEncoder = engine->audioEncoders->codecName; if(pthread_create(&audioThread, &attr, audioThrFxn, &audioEnv)) { ERR("Failed to create speech thread\n"); cleanup(EXIT_FAILURE); } initMask |= AUDIOTHREADCREATED; #ifdef DSS_ENC_1100_1200 if(pthread_create(&webListenThread, &attr, weblistenThrFxn, NULL)) { ERR("Failed to create web listen thread\n"); cleanup(EXIT_FAILURE); } initMask |= WEBLISTENCREATED; #endif /* Main thread becomes the control thread */ ctrlEnv.hRendezvousInit = hRendezvousInit; ctrlEnv.hRendezvousCleanup = hRendezvousCleanup; ctrlEnv.engineName = engine->engineName; ret = ctrlThrFxn(&ctrlEnv); if(ret == THREAD_FAILURE) { status = EXIT_FAILURE; } DEBUG(DL_DEBUG, "Exit All Thread!!\n"); cleanup: /* Make sure the other threads aren't waiting for init to complete */ if(hRendezvousWriter) { Rendezvous_force(hRendezvousWriter); } if(hRendezvousInit) { Rendezvous_force(hRendezvousInit); } DEBUG(DL_DEBUG, "EXIT Common Mutex!!!\n"); DestorygblCommonMutex(); DEBUG(DL_DEBUG, "EXIT pthread Mutex!!!\n"); DestroyMutexPthread(); if(initMask & AUDIOTHREADCREATED) { if(pthread_join(audioThread, &ret) == 0) { if(ret == THREAD_FAILURE) { status = EXIT_FAILURE; } } } DEBUG(DL_DEBUG, "EXIT audio pThread!!!\n"); if(initMask & VIDEOTHREADCREATED) { if(pthread_join(videoThread, &ret) == 0) { if(ret == THREAD_FAILURE) { status = EXIT_FAILURE; } } } DEBUG(DL_DEBUG, "EXIT video pThread!!!\n"); if(initMask & WRITERTHREADCREATED) { if(pthread_join(writerThread, &ret) == 0) { if(ret == THREAD_FAILURE) { status = EXIT_FAILURE; } } } DEBUG(DL_DEBUG, "EXIT write pThread!!!\n"); if(initMask & CAPTURETHREADCREATED) { if(pthread_join(captureThread, &ret) == 0) { if(ret == THREAD_FAILURE) { status = EXIT_FAILURE; } } } DEBUG(DL_DEBUG, "EXIT capture pThread!!!\n"); if(initMask & VIDEOLOWRATETHREAD) { if(pthread_join(videoLowThread, &ret) == 0) { if(ret == THREAD_FAILURE) { status = EXIT_FAILURE; } } } if(initMask & RESIZELOWRATETHREAD) { if(pthread_join(resizeLowThread, &ret) == 0) { if(ret == THREAD_FAILURE) { status = EXIT_FAILURE; } } } if(initMask & WRITELOWRATETHREAD) { if(pthread_join(writerLowThread, &ret) == 0) { if(ret == THREAD_FAILURE) { status = EXIT_FAILURE; } } } if(pthread_join(id_listen[PORT_ONE], &ret) == 0) { if(ret == THREAD_FAILURE) { status = EXIT_FAILURE; } } if(captureEnv.to_video_c) { Fifo_delete(captureEnv.to_video_c); } if(captureEnv.from_video_c) { Fifo_delete(captureEnv.from_video_c); } if(captureEnv.to_resize_c) { Fifo_delete(captureEnv.to_resize_c); } if(captureEnv.from_resize_c) { Fifo_delete(captureEnv.from_resize_c); } if(writerEnv.to_video_c) { Fifo_delete(writerEnv.to_video_c); } if(writerEnv.from_video_c) { Fifo_delete(writerEnv.from_video_c); } if(writerLowRateEnv.from_writelow_c) { Fifo_delete(writerLowRateEnv.from_video_c); } if(writerLowRateEnv.to_writelow_c) { Fifo_delete(writerLowRateEnv.to_writelow_c); } if(LowRateResize.to_videoresize_c) { Fifo_delete(LowRateResize.to_videoresize_c); } if(LowRateResize.from_videoresize_c) { Fifo_delete(LowRateResize.from_videoresize_c); } DEBUG(DL_DEBUG, "EXIT Rendezvous cleanup pThread!!!\n"); if(hRendezvousCleanup) { Rendezvous_delete(hRendezvousCleanup); } DEBUG(DL_DEBUG, "EXIT Rendezvous init pThread!!!\n"); if(hRendezvousInit) { Rendezvous_delete(hRendezvousInit); } DEBUG(DL_DEBUG, "EXIT Rendezvous cleanup pThread!!!\n"); /* if (initMask & LOGSINITIALIZED) { TraceUtil_stop(); } */ DEBUG(DL_DEBUG, "EXIT TraceUtil_stop !!!\n"); pthread_mutex_destroy(&gbl.mutex); DEBUG(DL_DEBUG, "process EXIT!!!\n"); exit(1); }
int main (void) { //Set Pin Modes // pinMode(PIN_RaspiReset, OUTPUT); // pinMode(PIN_IHTempSensor, INPUT/*_ANALOG*/); // pinMode(PIN_MotorPosSensor, INPUT_PULLUP); pinMode(PIN_Ventil, OUTPUT); // pinMode(PIN_SafetyChain, OUTPUT); pinMode(PIN_PusherLocked, INPUT_PULLUP); pinMode(PIN_LidLocked, INPUT_PULLUP); pinMode(PIN_LidClosed, INPUT_PULLUP); // pinMode(PIN_SimulateButton0, OUTPUT); // pinMode(PIN_IHOff, OUTPUT); // pinMode(PIN_isIHOn, INPUT_PULLUP); // pinMode(PIN_IHOn, OUTPUT); // pinMode(PIN_MotorPWM, OUTPUT/*_PWM*/); // pinMode(PIN_IHPowerPWM, OUTPUT/*_PWM*/); // pinMode(PIN_IHFanPWM, OUTPUT/*_PWM*/); Motor_init(); Heating_init(); initTime(); //Init LoL-Shield // #ifdef GRAYSCALE LedSign_Init(DOUBLE_BUFFER | GRAYSCALE); //Initializes the screen // #else // LedSign_Init(DOUBLE_BUFFER); //Initializes the screen // #endif LedSign_Clear(0); LedSign_Flip(false); //initialize time messurement //initTime(); //Init SPI SPI_init(wdtRestart); //Disable JTAG interface MCUCR = _BV(JTD); MCUCR = _BV(JTD); //Need to write twice to disable it (Atmega_644.pdf, page 267, 23.8.1) #ifdef DEBUG_MODE if (isExternalReset){ wdtRestartCount = wdtRestartCount + 1; } //TODO remove, test was WTD reset if (wdtRestart && wdtRestartLast){ wdtRestart = false; } wdtRestartLast = wdtRestart; digitalWrite(PIN_Ventil, wdtRestart); wdtRestart = false; char valueAsString[10]; sprintf(valueAsString, "R%X", wdtRestartCount); //HEX //sprintf(valueAsString, "%d", wdtRestartCount); //DEC DisplayHandler_setText2(valueAsString); DisplayHandler_displayText(false); _delay_ms(50); #endif LedSign_Clear(PIXEL_HALF); LedSign_Flip(true); _delay_ms(100); LedSign_Clear(PIXEL_OFF); LedSign_Flip(true); /* digitalWrite(PIN_Ventil, HIGH); _delay_ms(5000); digitalWrite(PIN_Ventil, LOW); */ if (isStartup){ //Was power On reset LedSign_Clear(PIXEL_OFF); LedSign_Flip(true); DisplayHandler_setText("EveryCook is starting"); currentMode = SPI_MODE_DISPLAY_TEXT; } else { //is other than power on reset DisplayHandler_setPicture(&picture_hi[0]); DisplayHandler_DisplayBitMap(); } initWatchDog(); while(1){ Motor_motorControl(); Heating_heatControl(); Heating_controlIHTemp(); checkLocks(); if (!LidClosed) Motor_setMotor(0); if (availableSPI() > 0) { triggerWatchDog(true); uint8_t data; uint8_t newMode = readSPI(true); char* newText; uint8_t readAmount = 0; boolean setOn = false; boolean setOff = false; switch(newMode){ case SPI_MODE_IDLE: //DisplayHandler_setPicture(&picture_0[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_GET_STATUS: nextResponse = StatusByte; //DisplayHandler_setPicture(&picture_1[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_DISPLAY_CLEAR: LedSign_Clear(0); LedSign_Flip(true); currentMode = 0; nextResponse = SPI_CommandOK; break; case SPI_MODE_MOTOR: data = readSPI(true); wdt_reset(); if(LidClosed){ Motor_setMotor(data); }else{ Motor_setMotor(0); } nextResponse = SPI_CommandOK; //DisplayHandler_setPicture(&picture_2[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_HEATING: data = readSPI(true); wdt_reset(); Heating_setHeating(data); nextResponse = SPI_CommandOK; //DisplayHandler_setPicture(&picture_3[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_GET_DEBUG: nextResponse = Vdebug; //DisplayHandler_setPicture(&picture_18[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_VENTIL: VentilState = readSPI(true); wdt_reset(); digitalWrite(PIN_Ventil, VentilState); nextResponse = SPI_CommandOK; //DisplayHandler_setPicture(&picture_10[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_DISPLAY_PERCENT: case SPI_MODE_DISPLAY_PERCENT_TEXT: data = readSPI(true); wdt_reset(); DisplayHandler_displayProgress(data, newMode == SPI_MODE_DISPLAY_PERCENT_TEXT); lastPercentValue = data; if (newMode != SPI_MODE_DISPLAY_PERCENT_TEXT){ nextResponse = SPI_CommandOK; currentMode = newMode; break; } case SPI_MODE_DISPLAY_TEXT: case SPI_MODE_DISPLAY_TEXT_SMALL: if (DisplayHandler_readText()) {//[01]<textlen 1 Byte><text>[00<control byte>] if (newMode == SPI_MODE_DISPLAY_TEXT){ DisplayHandler_displayText(false); } else { DisplayHandler_displayText(true); } lastTextUpdate = millis(); if (newMode == SPI_MODE_DISPLAY_PERCENT_TEXT){ updatePercentAgain = true; } nextResponse = SPI_CommandOK; currentMode = newMode; } else { nextResponse = SPI_Error_Text_Invalid; } break; case SPI_MODE_DISPLAY_PICTURE: readAmount=0; while (readAmount < 9){ if (availableSPI() >= 2) { data = readSPI(true); picture[readAmount] = data << 8; data = readSPI(true); picture[readAmount] |= data; readAmount++; wdt_reset(); } else { _delay_ms(1); } } if (availableSPI() == 0) { _delay_ms(10); if (availableSPI() == 0) { _delay_ms(20); } } if (availableSPI() > 0 && peekSPI() == 0x00) { readSPI(false); DisplayHandler_setPicture(&picture[0]); DisplayHandler_DisplayBitMap(); currentMode = newMode; nextResponse = SPI_CommandOK; } else { DisplayHandler_setPicture(&picture[0]); DisplayHandler_DisplayBitMap(); currentMode = newMode; nextResponse = SPI_Error_Picture_Invalid; } break; case SPI_MODE_MAINTENANCE: data = readSPI(true); if (data == 0x99) { setOn = true; } else if (data == 0x22){ setOff = true; } //be sure its change to maintenance, it has the be send 2 times data = readSPI(true); if (data == SPI_MODE_MAINTENANCE) { data = readSPI(true); if (setOn && data != 0x99) { setOn = false; } else if (setOff && data != 0x22){ setOff = false; } data = readSPI(true); //00 as command end mark if (data == 0x00){ if (setOn){ isMaintenanceMode = true; nextResponse = SPI_CommandOK; } else if (setOff){ isMaintenanceMode = false; nextResponse = SPI_CommandOK; } else { nextResponse = SPI_Error_Unknown_Command; } } else { nextResponse = SPI_Error_Unknown_Command; } } else { nextResponse = SPI_Error_Unknown_Command; } break; case SPI_MODE_GET_MOTOR_SPEED: nextResponse = outputValueMotor; //DisplayHandler_setPicture(&picture_12[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_GET_IGBT_TEMP: nextResponse = ihTemp8bit; //DisplayHandler_setPicture(&picture_hi[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_GET_FAN_PWM: nextResponse = lastIHFanPWM; //DisplayHandler_setPicture(&picture_17[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_GET_HEATING_OUTPUT_LEVEL: nextResponse = 0; //nextResponse = Heating_getLastOnPWM(); //DisplayHandler_setPicture(&picture_14[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_GET_MOTOR_POS_SENSOR: nextResponse = lastSensorValue; //DisplayHandler_setPicture(&picture_15[0]); //DisplayHandler_DisplayBitMap(); break; case SPI_MODE_GET_MOTOR_RPM: nextResponse = rpm; //DisplayHandler_setPicture(&picture_16[0]); //DisplayHandler_DisplayBitMap(); break; default: nextResponse = SPI_Error_Unknown_Command; } } else { triggerWatchDog(false); switch(currentMode){ case SPI_MODE_IDLE: break; case SPI_MODE_DISPLAY_PERCENT_TEXT: if (updatePercentAgain) { DisplayHandler_displayProgress(lastPercentValue, true); updatePercentAgain = false; } case SPI_MODE_DISPLAY_TEXT: case SPI_MODE_DISPLAY_TEXT_SMALL: if ((millis() - lastTextUpdate) > TEXT_UPDATE_TIMEOUT){ lastTextUpdate = millis(); if(!DisplayHandler_displayText(currentMode != SPI_MODE_DISPLAY_TEXT)){ currentMode = 0; } } break; } //DisplayHandler_setPicture(&picture_0[0]); //DisplayHandler_DisplayBitMap(); } } return 0; }
void setup() { #if !defined(GPS_PROMINI) UARTInit(115200); #endif LEDPIN_PINMODE; SHIELDLED_PINMODE; //POWERPIN_PINMODE; //BUZZERPIN_PINMODE; //STABLEPIN_PINMODE; //POWERPIN_OFF; /* Initialize GPIO (sets up clock) */ GPIOInit(); init_microsec(); enable_microsec(); init_timer16PWM(); enable_PWMtimer(); /******** special version of MultiWii to calibrate all attached ESCs ************/ #if defined(ESC_CALIB_CANNOT_FLY) writeAllMotors(ESC_CALIB_HIGH); delayMs(3000); writeAllMotors(ESC_CALIB_LOW); delayMs(500); while (1) { delayMs(5000); blinkLED(2,20, 2); } // statement never reached #endif writeAllMotors(MINCOMMAND); delayMs(300); readEEPROM(); checkFirstTime(); configureReceiver(); #if defined(OPENLRSv2MULTI) initOpenLRS(); #endif initSensors(); #if defined(I2C_GPS) || defined(GPS_SERIAL) || defined(GPS_FROM_OSD)||defined(I2C_NAV) GPS_set_pids(); #endif previousTime = micros(); #if defined(GIMBAL) calibratingA = 400; #endif calibratingG = 400; calibratingB = 200; // 10 seconds init_delay + 200 * 25 ms = 15 seconds before ground pressure settles #if defined(POWERMETER) for(uint8_t i=0;i<=PMOTOR_SUM;i++) pMeter[i]=0; #endif #if defined(ARMEDTIMEWARNING) ArmedTimeWarningMicroSeconds = (ARMEDTIMEWARNING *1000000); #endif /************************************/ #if defined(GPS_SERIAL) SerialOpen(GPS_SERIAL,GPS_BAUD); delay(400); for(uint8_t i=0;i<=5;i++){ GPS_NewData(); LEDPIN_ON delay(20); LEDPIN_OFF delay(80); } if(!GPS_Present){ SerialEnd(GPS_SERIAL); SerialOpen(0,SERIAL_COM_SPEED); } #if !defined(GPS_PROMINI) GPS_Present = 1; #endif GPS_Enable = GPS_Present; #endif /************************************/ #if defined(I2C_GPS) || defined(TINY_GPS) || defined(GPS_FROM_OSD)|| defined(I2C_NAV) GPS_Enable = 1; #endif #if defined(LCD_ETPP) || defined(LCD_LCD03) || defined(OLED_I2C_128x64) initLCD(); #endif #ifdef LCD_TELEMETRY_DEBUG telemetry_auto = 1; #endif #ifdef LCD_CONF_DEBUG configurationLoop(); #endif #ifdef LANDING_LIGHTS_DDR init_landing_lights(); #endif #if defined(LED_FLASHER) init_led_flasher(); led_flasher_set_sequence(LED_FLASHER_SEQUENCE); #endif f.SMALL_ANGLES_25=1; // important for gyro only conf //initialise median filter structures #ifdef MEDFILTER #ifdef SONAR initMedianFilter(&SonarFilter, 5); #endif #endif initWatchDog(); }