📄 ctrl.c
字号:
val = strtok(NULL, " ");
if (!val) {
fclose(fptr);
return FAILURE;
}
csTime = atoi(val);
}
if (fclose(fptr) != 0) {
return FAILURE;
}
total = user + nice + sys + idle;
proc = uTime + sTime + cuTime + csTime;
/* Check if this is the first time, if so init the prev_* values */
if (prevIdle == 0) {
prevIdle = idle;
prevTotal = total;
prevProc = proc;
return SUCCESS;
}
deltaIdle = idle - prevIdle;
deltaTotal = total - prevTotal;
deltaProc = proc - prevProc;
prevIdle = idle;
prevTotal = total;
prevProc = proc;
*cpuLoad = 100 - (deltaIdle / (deltaTotal / 100));
*procLoad = deltaProc / (deltaTotal / 100);
return SUCCESS;
}
/******************************************************************************
* drawDynamicData
******************************************************************************/
static void drawDynamicData(Engine_Handle hEngine, int osdFd, int *time,
int *displayIdx, int *workingIdx)
{
static unsigned long firstTime = 0;
static unsigned long prevTime;
unsigned long newTime;
unsigned long deltaTime;
struct timeval tv;
struct tm *timePassed;
time_t spentTime;
char tempString[9];
int procLoad;
int armLoad;
int dspLoad;
int fps;
int videoKbps;
*time = 0;
if (gettimeofday(&tv, NULL) == -1) {
ERR("Failed to get os time\n");
return;
}
newTime = tv.tv_sec * 1000 + tv.tv_usec / 1000;
if (!firstTime) {
firstTime = newTime;
prevTime = newTime;
return;
}
/* Only update OSD every second */
deltaTime = newTime - prevTime;
if (deltaTime <= 1000) {
return;
}
prevTime = newTime;
spentTime = (newTime - firstTime) / 1000;
if (spentTime <= 0) {
return;
}
*time = spentTime;
fps = getAndResetFrames() * 1000 / deltaTime;
videoKbps = getAndResetVideoBytesEncoded() * 8 / deltaTime;
uiClearScreen(COLUMN_2, 0, COLUMN_3 - COLUMN_2, YSCALE(220), *workingIdx);
if (getArmCpuLoad(&procLoad, &armLoad) != -1) {
sprintf(tempString, "%d%%", procLoad);
uiDrawText(tempString, COLUMN_2, ROW_1, *workingIdx);
}
else {
ERR("Failed to get ARM CPU load\n");
}
dspLoad = Engine_getCpuLoad(hEngine);
if (dspLoad > -1) {
sprintf(tempString, "%d%%", dspLoad);
uiDrawText(tempString, COLUMN_2, ROW_2, *workingIdx);
}
else {
ERR("Failed to get DSP CPU load\n");
}
sprintf(tempString, "%d fps", fps);
uiDrawText(tempString, COLUMN_2, ROW_3, *workingIdx);
sprintf(tempString, "%d kbps", videoKbps);
uiDrawText(tempString, COLUMN_2, ROW_4, *workingIdx);
timePassed = localtime(&spentTime);
if (timePassed == NULL) {
return;
}
sprintf(tempString, "%.2d:%.2d:%.2d", timePassed->tm_hour,
timePassed->tm_min,
timePassed->tm_sec);
uiDrawText(tempString, COLUMN_2, ROW_5, *workingIdx);
*displayIdx = (*displayIdx + 1) % NUM_BUFS;
*workingIdx = (*workingIdx + 1) % NUM_BUFS;
flipOsdBuffers(osdFd, *displayIdx);
}
/******************************************************************************
* keyAction
******************************************************************************/
static int keyAction(enum msp430lib_keycode key, int displayIdx,
int *osdTransPtr)
{
static int osdVisible = TRUE;
switch(key) {
case MSP430LIB_KEYCODE_PLAY:
DBG("Play button pressed\n");
setPlay(TRUE);
if (uiPressButton(CTRLPLAY, displayIdx) == FAILURE) {
return FAILURE;
}
break;
case MSP430LIB_KEYCODE_PAUSE:
DBG("Pause button pressed\n");
setPlay(FALSE);
if (uiPressButton(CTRLPAUSE, displayIdx) == FAILURE) {
return FAILURE;
}
break;
case MSP430LIB_KEYCODE_STOP:
DBG("Stop button pressed, quitting demo..\n");
setQuit();
break;
case MSP430LIB_KEYCODE_VOLINC:
DBG("Chan inc button pressed\n");
if (*osdTransPtr < 0x77) {
*osdTransPtr += 0x11;
setOsdTransparency(*osdTransPtr);
}
if (uiPressButton(NAVPLUS, displayIdx) == FAILURE) {
return FAILURE;
}
break;
case MSP430LIB_KEYCODE_VOLDEC:
DBG("Chan dec button pressed\n");
if (*osdTransPtr > 0x11) {
*osdTransPtr -= 0x11;
setOsdTransparency(*osdTransPtr);
}
if (uiPressButton(NAVMINUS, displayIdx) == FAILURE) {
return FAILURE;
}
break;
case MSP430LIB_KEYCODE_INFOSELECT:
DBG("Menu done or info/select command received.\n");
if (osdVisible) {
setOsdTransparency(0x0);
osdVisible = FALSE;
}
else {
setOsdTransparency(*osdTransPtr);
osdVisible = TRUE;
}
break;
default:
DBG("Unknown button pressed.\n");
/*
if (uiPressButton(WRONG, displayIdx) == FAILURE) {
return FAILURE;
}
*/
}
return SUCCESS;
}
/******************************************************************************
* ctrlThrFxn
******************************************************************************/
void *ctrlThrFxn(void *arg)
{
enum InitLevels initLevel = 0;
int osdTransparency = OSD_TRANSPARENCY;
DemoEnv *envp = (DemoEnv *) arg;
void *status = THREAD_SUCCESS;
int displayIdx = 0;
int workingIdx = 1;
enum msp430lib_keycode key;
Engine_Handle hEngine;
int osdFd;
unsigned int timeSpent;
char *osdDisplays[NUM_BUFS];
#if 1
osdFd = osdInit(osdDisplays);
if (osdFd == -1) {
CLEANUP(THREAD_FAILURE);
}
initLevel = OSDINITIALIZED;
if (setOsdTransparency(osdTransparency) == -1) {
CLEANUP(THREAD_FAILURE);
}
#if 1
/* Reset, load, and start DSP Engine */
if ((hEngine = Engine_open(ENGINE_NAME, NULL, NULL)) == NULL) {
ERR("Failed to open codec engine %s\n", ENGINE_NAME);
CLEANUP(THREAD_FAILURE);
}
initLevel = ENGINEOPENED;
/*
if (msp430lib_init() == MSP430LIB_FAILURE) {
ERR("Failed to initialize msp430lib.\n");
CLEANUP(THREAD_FAILURE);
}
*/
initLevel = MSP430LIBINITIALIZED;
if (uiCreate(envp, osdDisplays) == -1) {
CLEANUP(THREAD_FAILURE);
}
initLevel = UICREATED;
if (uiDraw() == -1) {
CLEANUP(THREAD_FAILURE);
}
#endif
#endif
/* Signal all threads that all the initialization is done */
MET_CONDITION(allMutex, allInit);
/* Initialize the ARM cpu load */
getArmCpuLoad(NULL, NULL);
DBG("Entering control main loop.\n");
while (!getQuit()) {
#if 1
/* Dump the Codec Engine trace from DSP */
dspTraceDump(hEngine);
/* Draw the cpu load on the OSD */
drawDynamicData(hEngine, osdFd, &timeSpent, &displayIdx, &workingIdx);
if (envp->time > 0 && timeSpent > envp->time) {
BREAK_LOOP(THREAD_SUCCESS);
}
/* See if an IR remote key has been pressed */
/*
if (msp430lib_get_ir_key(&key) == MSP430LIB_FAILURE) {
DBG("Failed to get IR value.\n");
}
DBG("Got IR key %#x from the MSP430\n", key);
*/
/* If an IR key had been pressed, service it */
/*
if (key != 0) {
if (keyAction(key, displayIdx, &osdTransparency) == FAILURE) {
BREAK_LOOP(THREAD_FAILURE);
}
}
*/
#endif
usleep(500000);
}
cleanup:
if (initLevel >= UICREATED) {
uiDelete();
}
if (initLevel >= MSP430LIBINITIALIZED) {
msp430lib_exit();
}
if (initLevel >= ENGINEOPENED) {
dspTraceDump(hEngine);
Engine_close(hEngine);
}
if (initLevel >= OSDINITIALIZED) {
osdExit(osdFd);
}
return status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -