void Sample_XTalkCalibrate(void) { VL6180xDev_t myDev; VL6180x_RangeData_t Range; int XTalkRate; int i, status; /* init device */ MyDev_Init(myDev); status = Sample_Init(myDev); if( status <0 ){ HandleError("Sample_Init fail"); } /* run calibration */ XTalkRate = Sample_XTalkRunCalibration(myDev); /*TODO when possible reset re-init device else set back required scaling/filter*/ VL6180x_FilterSetState(myDev, 1); // turn on wrap around filter again VL6180x_UpscaleSetScaling(myDev, 3); // set scaling /* apply cross talk */ status = VL6180x_SetXTalkCompensationRate(myDev, XTalkRate); if( status<0 ){ /* ignore warning but not error */ HandleError("VL6180x_WrWord fail"); } for( i=0; i< 10; i++){ status = VL6180x_RangePollMeasurement(myDev, &Range); MyDev_ShowRange(myDev, Range.range_mm); } }
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG msg; HANDLE hAccelTable; // Other instances of app running? if (!hPrevInstance) { // Initialize shared things if (!InitApplication(hInstance)) { return (FALSE); // Exits if unable to initialize } } // Perform initializations that apply to a specific instance if (!InitInstance(hInstance, nCmdShow)) { return (FALSE); } //****************** NEW CODE START ********* Sample_Init ( ); //****************** NEW CODE END ********* hAccelTable = LoadAccelerators (hInstance, szAppName); // Acquire and dispatch messages until a WM_QUIT message is received. while (GetMessage(&msg, // message structure NULL, // handle of window receiving the message 0, // lowest message to examine 0)){ // highest message to examine if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg);// Translates virtual key codes DispatchMessage(&msg); // Dispatches message to window } } //****************** NEW CODE START ********* Sample_Shutdown ( ); //****************** NEW CODE END ********* // Returns the value from PostQuitMessage return (msg.wParam); // This will prevent 'unused formal parameter' warnings lpCmdLine; }
//initialize estimator with c samplers and k counters (used by Misra-Gries alg) Estimator_type * Estimator_Init(int c, int k) { Estimator_type* est = (Estimator_type*) safe_malloc(sizeof(Estimator_type)); est->c=c; est->k=k; est->count = 0; est->two_distinct_tokens=0; est->prng=prng_Init(drand48(), 2); // initialize the random number generator est->freq=Freq_Init((float)1.0/k); est->samplers = (Sample_type**) safe_malloc(sizeof(Sample_type*) * c); for(int i = 0; i < c; i++) { est->samplers[i]=Sample_Init(); } est->hashtable=new_symtab(2*c); est->prim_heap = new_heap(prim_cmp, c); est->bheap = new_bheap(b_cmp, c); return est; }