extern "C" void Battery_Initialise(void) { s_currentState = Battery_Off; s_currentVoltage = 0; memset(s_notifications, 0, sizeof(s_notifications)); ConfigureBatteryPins(); Timer_Create(timerBattery, NULL, BATTERY_UPDATE, 1); }
static int timerBattery(TimerHandle timer, void *context) { // Initiate battery charging control BAT_CHARGE_OUT |= BAT_CHARGE_OPEN_DRAIN_BITS; BATTERY_CHARGE_ENABLE(); // Fire off another timer, to wait a while Timer_Create(timerChargingControl, NULL, 50, 0); return 0; }
int main() { Timer_Create(&timer); Counter_Create(&counter); Flow_Create(&flow, &counter, &timer, 1); // 1 pulse = 1 keypress / second Timer_SetIntervalAlarm(&timer, 5 * 1000, DisplayFlowRate); FlowSensor_Listen(Pulse); printf("Press ctrl-c to exit...\n"); Console_WaitUntilTerminated(); return 0; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { FILE *log; Options_Interface *o; Void *timer; MCP *m; MCP_Termination t; Information info; double *tempZ; double *status, *tot_time; double dnnz; int i, len; mat_install_error(); mat_install_memory(); log = fopen("logfile.tmp", "w"); Output_SetLog(log); /* Options. 1. Get options associated with the algorithm 2. Set to default values 3. Read in an options file 4. Print out the options */ o = Options_Create(); Path_AddOptions(o); Options_Default(o); if (nrhs < 7) { Error("Not enough input arguments.\n"); } if (nlhs < 2) { Error("Not enough output arguments.\n"); } nMax = (int) mxGetScalar(prhs[0]); nnzMax = (int) mxGetScalar(prhs[1]); plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL); if (nlhs > 2) { plhs[2] = mxCreateDoubleMatrix(nMax,1,mxREAL); } if (nlhs > 3) { plhs[3] = mxCreateDoubleMatrix(nMax,1,mxREAL); } /* Create a timer and start it. */ timer = Timer_Create(); Timer_Start(timer); /* Derefencing to get the status argument. */ status = mxGetPr(plhs[0]); tot_time = mxGetPr(plhs[1]); /* First print out some version information. */ Output_Printf(Output_Log | Output_Status | Output_Listing, "%s: Matlab Link\n", Path_Version()); /* Now check the arguments. If the dimension of the problem is 0, there is nothing to do. */ if (nMax == 0) { Output_Printf(Output_Log | Output_Status, "\n ** EXIT - solution found (degenerate model).\n"); (*status) = 1.0; (*tot_time) = Timer_Query(timer); Timer_Destroy(timer); Options_Destroy(o); fclose(log); return; } /* Check size of the jacobian. nnz < n*n. Need to convert to double so we do not run out of integers. dnnz - max number of nonzeros as a double */ dnnz = MIN(1.0*nnzMax, 1.0*nMax*nMax); if (dnnz > INT_MAX) { Output_Printf(Output_Log | Output_Status, "\n ** EXIT - model too large.\n"); (*status) = 0.0; (*tot_time) = Timer_Query(timer); Timer_Destroy(timer); Options_Destroy(o); fclose(log); return; } nnzMax = (int) dnnz; /* Have correct number of nonzeros. Print some statistics. Print out the density. */ Output_Printf(Output_Log | Output_Status | Output_Listing, "%d row/cols, %d non-zeros, %3.2f%% dense.\n\n", nMax, nnzMax, 100.0*nnzMax/(1.0*nMax*nMax)); if (nnzMax == 0) { nnzMax++; } zp = mxGetPr(prhs[2]); lp = mxGetPr(prhs[3]); up = mxGetPr(prhs[4]); m_start = mxGetJc(prhs[5]); m_row = mxGetIr(prhs[5]); m_data = mxGetPr(prhs[5]); m_len = (int *)Memory_Allocate(nMax*sizeof(int)); for (i = 0; i < nMax; i++) { m_len[i] = m_start[i+1] - m_start[i]; m_start[i]++; } actualNnz = m_start[nMax]; for (i = 0; i < actualNnz; i++) { m_row[i]++; } q = mxGetPr(prhs[6]); /* Create a structure for the problem. */ m = MCP_Create(nMax, nnzMax); MCP_Jacobian_Structure_Constant(m, 1); MCP_Jacobian_Data_Contiguous(m, 1); install_interface(m); Options_Read(o, "path.opt"); Options_Display(o); info.generate_output = Output_Log | Output_Status | Output_Listing; info.use_start = True; info.use_basics = True; /* Solve the problem. m - MCP to solve, info - information, t - termination */ t = Path_Solve(m, &info); /* Read in the results. First get the solution vector. The report. */ tempZ = MCP_GetX(m); for (i = 0; i < nMax; i++) { zp[i] = tempZ[i]; } /* If the final function evaluation is wanted, report it. */ if (nlhs > 2) { double *fval = mxGetPr(plhs[2]); tempZ = MCP_GetF(m); for (i = 0; i < nMax; i++) { fval[i] = tempZ[i]; } } /* If the final basis is wanted, report it. */ if (nlhs > 3) { double *bval = mxGetPr(plhs[3]); int *tempB; tempB = MCP_GetB(m); for (i = 0; i < nMax; i++) { switch(tempB[i]) { case Basis_LowerBound: bval[i] = -1; break; case Basis_UpperBound: bval[i] = 1; break; default: bval[i] = 0; break; } } } switch(t) { case MCP_Solved: *status = 1.0; break; default: *status = 0.0; break; } /* Stop the timer and report the results. */ (*tot_time) = Timer_Query(timer); Timer_Destroy(timer); /* Clean up. Deallocate memory used and close the log. */ MCP_Destroy(m); Memory_Free(m_len); Options_Destroy(o); fclose(log); return; }
void Initiate(void) { LIGHT_SENSOR_L_GAIN(); // Let the light sensor stabilise Timer_Create(DelayStartAdc, this, 10, false); }
void TimeFace::OnShow(int type) { WatchFace::OnShow(type); if (Visible() && (m_timer == NULL)) m_timer = Timer_Create(TimerCallback, this, 1000, true); }