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