#include <stdio.h>
#include "main.h"
#include "gui.h"
#include "error_management.h"
#include <richedit.h>
Go to the source code of this file.
Defines | |
#define | DELAY 50 |
#define | GRAPH_HEIGHT (YSCREEN-30) |
#define | GRAPH_MARGIN 30 |
#define | GRAPH_WIDTH (XSCREEN-30) |
#define | ITEM_GRAPH gui_main_layout._gui_item[1] |
#define | MAX(x, y) (((x) > (y))?(x):(y)) |
#define | MAX_DATA 8000 |
Functions | |
void | get_config (char *_path) |
void | get_data (char *_path) |
LRESULT CALLBACK | GraphProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) |
LRESULT CALLBACK | WindowProcedure (HWND, UINT, WPARAM, LPARAM) |
int WINAPI | WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) |
Variables | |
float | _data [MAX_DATA] |
char * | _filename |
int | cur_i = 0 |
s_gui_tab_layout | gui_main_layout |
HWND | main_hwnd |
int | N_ARG |
int | n_data = 0 |
float | scale_x |
float | scale_y |
#define DELAY 50 |
#define GRAPH_HEIGHT (YSCREEN-30) |
Definition at line 41 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
Referenced by GraphProcedure(), and WindowProcedure().
#define GRAPH_MARGIN 30 |
Definition at line 42 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
Referenced by GraphProcedure().
#define GRAPH_WIDTH (XSCREEN-30) |
Definition at line 40 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
Referenced by GraphProcedure(), and WindowProcedure().
#define ITEM_GRAPH gui_main_layout._gui_item[1] |
Definition at line 39 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
#define MAX | ( | x, | |||
y | ) | (((x) > (y))?(x):(y)) |
Definition at line 47 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
Referenced by GraphProcedure().
#define MAX_DATA 8000 |
void get_config | ( | char * | _path | ) |
void get_data | ( | char * | _path | ) |
Definition at line 134 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
References _data, ASSERT, cur_i, MAX_DATA, and n_data.
00135 { 00136 int n; 00137 FILE *_file; 00138 char temp[255]; 00139 static int file_pointer = 0; 00140 float f; 00141 00142 // Make sure all is set 00143 ASSERT(_data); 00144 ASSERT(_path); 00145 00146 // Open the file 00147 _file = fopen(_path, "rb"); 00148 if (!_file) 00149 return; 00150 00151 fseek(_file, 0, SEEK_END); 00152 00153 // Get the length of the file 00154 // If the length has not changed since the last time, 00155 // quit this function 00156 if (ftell(_file) == file_pointer) 00157 { 00158 fclose(_file); 00159 return; 00160 } 00161 00162 // Else set the file pointer at the previous posistion 00163 fseek(_file, file_pointer, SEEK_SET); 00164 00165 // Read the new information from the file 00166 while(!feof(_file)) 00167 { 00168 // Get a line from the file 00169 fgets(temp, sizeof(temp) - 1, _file); 00170 00171 // If this line is empty, continue 00172 if (!*temp) 00173 continue; 00174 00175 // Get the first float on this line 00176 n = sscanf(temp, "%f", &f); 00177 if (n != 1) 00178 continue; 00179 00180 // add this float to a circular buffer 00181 _data[cur_i++] = f; 00182 if (cur_i == MAX_DATA) 00183 cur_i = 0; 00184 00185 // Set the size of this buffer and saturate it if the maximum size is reached 00186 if (n_data < MAX_DATA) 00187 n_data++; 00188 } 00189 00190 // Update the file_pointer variable 00191 file_pointer = ftell(_file); 00192 00193 // Close the file 00194 fclose(_file); 00195 }
LRESULT CALLBACK GraphProcedure | ( | HWND | hwnd, | |
UINT | message, | |||
WPARAM | wParam, | |||
LPARAM | lParam | |||
) |
Definition at line 198 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
References _data, cur_i, GRAPH_HEIGHT, GRAPH_MARGIN, GRAPH_WIDTH, MAX, min(), and n_data.
Referenced by WindowProcedure().
00199 { 00200 HDC hdc; 00201 hdc = (HDC) wParam; 00202 static float max = 0., min = 0.; 00203 float temp_max, temp_min; 00204 float cur_data; 00205 float offset, scale, y; 00206 float x, inc; 00207 int i, j; 00208 float dy; 00209 int start_i; 00210 char temp[32]; 00211 HBRUSH hbRed, hbrOld; 00212 HPEN hp2px, hpOld; 00213 SIZE sz; 00214 00215 // Draw a white rectangle on the default Device Context 00216 Rectangle(hdc, 0, 0, GRAPH_WIDTH, GRAPH_HEIGHT); 00217 00218 // Initialize data 00219 start_i = cur_i - n_data; 00220 if (start_i < 0) 00221 start_i += n_data; 00222 i = n_data; 00223 j = start_i; 00224 temp_max = _data[j]; 00225 temp_min = temp_max; 00226 00227 // Calculate the minimum and the maximum of the graph 00228 while(i--) 00229 { 00230 cur_data = _data[j++]; 00231 if (temp_max < cur_data) 00232 temp_max = cur_data; 00233 if (temp_min > cur_data) 00234 temp_min = cur_data; 00235 if (j == n_data) 00236 j = 0; 00237 } 00238 00239 // Update the maximum 00240 if (max < temp_max) 00241 max = temp_max; 00242 else 00243 max = temp_max + (max - temp_max)*0.9; 00244 00245 // Update the minimum 00246 if (min > temp_min) 00247 min = temp_min; 00248 else 00249 min = temp_min - (temp_min - min)*0.9; 00250 00251 // Set the scaling of the graph 00252 scale = (GRAPH_HEIGHT-GRAPH_MARGIN*2)/(max-min); 00253 // Set the offset of the graph 00254 offset = GRAPH_MARGIN + max*scale; 00255 00256 // Draw the vertical axis 00257 MoveToEx(hdc, GRAPH_MARGIN, GRAPH_MARGIN, NULL); 00258 LineTo(hdc, GRAPH_MARGIN, GRAPH_HEIGHT - GRAPH_MARGIN); 00259 00260 // Draw the horizontal axis 00261 MoveToEx(hdc, GRAPH_MARGIN, offset, NULL); 00262 LineTo(hdc, GRAPH_WIDTH - GRAPH_MARGIN, offset); 00263 00264 // Gradations 00265 // Initialization 00266 inc = ((float) GRAPH_WIDTH - 2*GRAPH_MARGIN)/((float) n_data); 00267 MoveToEx(hdc, GRAPH_MARGIN, offset - _data[0]*scale, NULL); 00268 x = GRAPH_MARGIN; 00269 i = n_data; 00270 j = start_i; 00271 00272 // Use a new pen 00273 hp2px = CreatePen(PS_SOLID, 1, 0xFF0000); 00274 hpOld = SelectObject(hdc, hp2px); 00275 00276 // Draw the graph 00277 while(i--) 00278 { 00279 y = offset - _data[j++]*scale; 00280 LineTo(hdc, (int) x, y); 00281 x += inc; 00282 if (j == n_data) 00283 j = 0; 00284 } 00285 // Delete the pen 00286 DeleteObject(hp2px); 00287 00288 // Use another pen 00289 hp2px = CreatePen(PS_DOT, 1, 0xAAAAAA); 00290 SelectObject(hdc, hp2px); 00291 00292 // Change the color of the text 00293 SetTextColor(hdc, 0xAAAAAA); 00294 SetBkMode(hdc, TRANSPARENT); 00295 // Draw the gradations 00296 for(i=-(GRAPH_HEIGHT - GRAPH_MARGIN); i<(GRAPH_HEIGHT - GRAPH_MARGIN); i += (GRAPH_HEIGHT - 2*GRAPH_MARGIN)/5) 00297 { 00298 sprintf(temp, "%.1e", (offset-i)/scale); 00299 GetTextExtentPoint32(hdc, temp, strlen(temp) , &sz); 00300 00301 TextOut(hdc, 0, i-sz.cy/2, temp, strlen(temp)); 00302 00303 MoveToEx(hdc, MAX(GRAPH_MARGIN, sz.cx) + 2, i, NULL); 00304 LineTo(hdc, GRAPH_WIDTH - GRAPH_MARGIN, i); 00305 } 00306 00307 // Delete the pen 00308 SelectObject(hdc, hpOld); 00309 DeleteObject(hp2px); 00310 00311 return DefWindowProc(hwnd, message, wParam, lParam); 00312 }
LRESULT CALLBACK WindowProcedure | ( | HWND | hwnd, | |
UINT | message, | |||
WPARAM | wParam, | |||
LPARAM | lParam | |||
) |
Definition at line 315 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
References _data, _filename, ASSERT, FALSE, get_data(), GRAPH_HEIGHT, GRAPH_WIDTH, GraphProcedure(), gui_create(), gui_new_tab_layout(), gui_proc(), gui_rescale(), GUI_TAB_ADD_ENTRY, GUI_TYPE_PAINT, scale_x, scale_y, TRUE, XSCREEN, and YSCREEN.
Referenced by WinMain().
00316 { 00317 LRESULT result; 00318 RECT rect; 00319 char _config[MAX_PATH]; 00320 00321 switch (message) 00322 { 00323 // On create event 00324 case WM_CREATE: 00325 // Create a 1-object layout 00326 gui_new_tab_layout(&gui_main_layout, 1); 00327 // Create one graph object 00328 GUI_TAB_ADD_ENTRY(gui_main_layout, 00329 (XSCREEN - GRAPH_WIDTH)/2, 00330 (XSCREEN - GRAPH_WIDTH)/2, 00331 GRAPH_WIDTH, GRAPH_HEIGHT, 00332 0, GUI_TYPE_PAINT, "", 0, GraphProcedure); 00333 // Create the layout 00334 gui_create(&gui_main_layout, hwnd); 00335 break; 00336 00337 // On timer event 00338 case WM_TIMER: 00339 // Read new data 00340 get_data(_filename); 00341 // Update the view 00342 GetClientRect(hwnd, &rect); 00343 InvalidateRect(hwnd, &rect, FALSE); 00344 break; 00345 00346 // On resize event 00347 case WM_SIZE: 00348 // Calculate the scale values of the display 00349 scale_x = ((float) LOWORD(lParam))/((float) XSCREEN); 00350 scale_y = ((float) HIWORD(lParam))/((float) YSCREEN); 00351 // Rescale the display 00352 gui_rescale(&gui_main_layout, scale_x, scale_y, FALSE); 00353 // Update the view 00354 GetClientRect(hwnd, &rect); 00355 InvalidateRect(hwnd, &rect, TRUE); 00356 break; 00357 } 00358 00359 // Switch events to the sub event handler functions 00360 result = gui_proc(&gui_main_layout, hwnd, message, wParam, lParam); 00361 00362 switch(message) 00363 { 00364 // On destroy event 00365 case WM_DESTROY: 00366 // Delete data 00367 ASSERT(_data); 00368 free(_data); 00369 // Quit the application 00370 PostQuitMessage(0); 00371 result = 1; 00372 break; 00373 } 00374 00375 if (!result) 00376 result = DefWindowProc(hwnd, message, wParam, lParam); 00377 00378 return result; 00379 }
int WINAPI WinMain | ( | HINSTANCE | hThisInstance, | |
HINSTANCE | hPrevInstance, | |||
LPSTR | lpszArgument, | |||
int | nFunsterStil | |||
) |
Definition at line 64 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
References _filename, ASSERT, BACKGROUND_COLOR, DELAY, main_hwnd, SET_ERROR, TITLE, WindowProcedure(), XSCREEN, and YSCREEN.
00065 { 00066 MSG messages; 00067 WNDCLASSEX wincl; 00068 HBRUSH hbrush; 00069 char szClassName[] = "c_" TITLE; 00070 HWND hwnd_temp; 00071 00072 // if no argument is passed to this function, return a usage message 00073 if (!*lpszArgument) 00074 { 00075 SET_ERROR("Usage: DataPrinter filename"); 00076 return messages.wParam; 00077 } 00078 00079 // Else assumed that the argument is the filename 00080 _filename = lpszArgument; 00081 00082 // Create the class that will support this application 00083 wincl.hInstance = hThisInstance; 00084 wincl.lpszClassName = szClassName; 00085 wincl.lpfnWndProc = WindowProcedure; 00086 wincl.style = CS_DBLCLKS; 00087 wincl.cbSize = sizeof(WNDCLASSEX); 00088 00089 wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); 00090 wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); 00091 wincl.hCursor = LoadCursor(NULL, IDC_ARROW); 00092 wincl.lpszMenuName = "MAINMENU"; 00093 wincl.cbClsExtra = 0; 00094 wincl.cbWndExtra = 0; 00095 00096 hbrush = CreateSolidBrush(BACKGROUND_COLOR); 00097 wincl.hbrBackground = (HBRUSH) hbrush; 00098 00099 // Register this class 00100 ASSERT(RegisterClassEx(&wincl)); 00101 00102 // Create the window 00103 main_hwnd = CreateWindowEx( 00104 0, 00105 szClassName, 00106 TITLE, 00107 WS_OVERLAPPED | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, 00108 CW_USEDEFAULT, 00109 CW_USEDEFAULT, 00110 XSCREEN + GetSystemMetrics(SM_CXFIXEDFRAME)*2, 00111 YSCREEN + GetSystemMetrics(SM_CYFIXEDFRAME)*2 + GetSystemMetrics(SM_CYCAPTION), 00112 HWND_DESKTOP, 00113 NULL, 00114 hThisInstance, 00115 NULL); 00116 00117 // Show the window 00118 ShowWindow(main_hwnd, nFunsterStil); 00119 00120 // Create the timer that will refresh the graph 00121 SetTimer(main_hwnd, 0, DELAY, NULL); 00122 00123 // Message handler loop 00124 while(GetMessage(&messages, NULL, 0, 0)) 00125 { 00126 TranslateMessage(&messages); 00127 DispatchMessage(&messages); 00128 } 00129 00130 return messages.wParam; 00131 }
float _data[MAX_DATA] |
Definition at line 57 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
Referenced by format_data(), get_data(), GraphProcedure(), and WindowProcedure().
char* _filename |
Definition at line 61 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
Referenced by main(), WindowProcedure(), and WinMain().
int cur_i = 0 |
Definition at line 58 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
Referenced by get_data(), and GraphProcedure().
Definition at line 55 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
HWND main_hwnd |
int N_ARG |
Definition at line 60 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
int n_data = 0 |
Definition at line 59 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
Referenced by format_data(), get_data(), and GraphProcedure().
float scale_x |
Definition at line 56 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
Referenced by gui_buffer_print_dsp16_bars(), gui_buffer_print_dsp16_signal(), and WindowProcedure().
float scale_y |
Definition at line 56 of file UTILS/PROGRAMS/WINDOWS/DATA_PRINT/main.c.
Referenced by gui_buffer_print_dsp16_bars(), gui_buffer_print_dsp16_signal(), and WindowProcedure().