⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_menu.c

📁 OBDII的ScanTool源码,对此有兴趣的朋友可以参考一下
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <string.h>
#include "globals.h"
#include "trouble_code_reader.h"
#include "about.h"
#include "sensors.h"
#include "options.h"
#include "serial.h"
#include "custom_gui.h"
#include "main_menu.h"

#define LOGO                       1
#define INEXPENSIVE_ALTERNATIVES   2
#define SUNFIRE                    3
#define READ_CODES                 5
#define SENSOR_DATA                6
#define FREEZE_FRAME               7
#define TESTS                      8
#define OPTIONS                    9
#define ABOUT                      10
#define EXIT                       11


// procedure declarations
static int read_codes_proc(int msg, DIALOG *d, int c);
static int sensor_data_proc(int msg, DIALOG *d, int c);
static int freeze_frame_proc(int msg, DIALOG *d, int c);
static int tests_proc(int msg, DIALOG *d, int c);
static int options_proc(int msg, DIALOG *d, int c);
static int about_proc(int msg, DIALOG *d, int c);
static int exit_proc(int msg, DIALOG *d, int c);
static int button_desc_proc(int msg, DIALOG *d, int c);
static int reset_proc(int msg, DIALOG *d, int c);

static char button_description[256];
static char current_description[256];
static char welcome_message[256];

static char reset_status_msg[64];

static DIALOG main_dialog[] =
{
   /* (proc)            (x)  (y)  (w)  (h)  (fg)         (bg)     (key) (flags) (d1) (d2) (dp)                 (dp2) (dp3) */
   { d_clear_proc,      0,   0,   0,   0,   0,           C_WHITE, 0,    0,      0,   0,   NULL,                NULL, NULL },
   { d_bitmap_proc,     25,  25,  58,  430, 0,           0,       0,    0,      0,   0,   NULL,                NULL, NULL },
   { d_bitmap_proc,     115, 25,  260, 106, 0,           0,       0,    0,      0,   0,   NULL,                NULL, NULL },
   { d_bitmap_proc,     115, 141, 260, 142, 0,           0,       0,    0,      0,   0,   NULL,                NULL, NULL },
   { button_desc_proc,  115, 283, 260, 147, C_DARK_GRAY, C_WHITE, 0,    0,      0,   0,   current_description, NULL, NULL },
   { read_codes_proc,   408, 25,  207, 57,  0,           0,       0,    D_EXIT, 0,   0,   NULL,                NULL, NULL },
   { sensor_data_proc,  408, 87,  207, 57,  0,           0,       0,    D_EXIT, 0,   0,   NULL,                NULL, NULL },
   { freeze_frame_proc, 408, 149, 207, 57,  0,           0,       0,    D_EXIT, 0,   0,   NULL,                NULL, NULL },
   { tests_proc,        408, 211, 207, 57,  0,           0,       0,    D_EXIT, 0,   0,   NULL,                NULL, NULL },
   { options_proc,      408, 273, 207, 57,  0,           0,       0,    D_EXIT, 0,   0,   NULL,                NULL, NULL },
   { about_proc,        408, 335, 207, 57,  0,           0,       0,    D_EXIT, 0,   0,   NULL,                NULL, NULL },
   { exit_proc,         408, 397, 207, 57,  0,           0,       'x',  D_EXIT, 0,   0,   NULL,                NULL, NULL },
   { NULL,              0,   0,   0,   0,   0,           0,       0,    0,      0,   0,   NULL,                NULL, NULL }
};

static DIALOG reset_chip_dialog[] =
{
   /* (proc)            (x)  (y) (w)  (h) (fg)     (bg)          (key) (flags) (d1) (d2) (dp)              (dp2) (dp3) */
   { d_shadow_box_proc, 0,   0,  300, 64, C_BLACK, C_LIGHT_GRAY, 0,    0,      0,   0,   NULL,             NULL, NULL },
   { caption_proc,      150, 24, 138, 16, C_BLACK, C_TRANSP,     0,    0,      0,   0,   reset_status_msg, NULL, NULL },
   { reset_proc,        0,   0,  0,   0,  0,       0,            0,    0,      0,   0,   NULL,             NULL, NULL },
   { NULL,              0,   0,  0,   0,  0,       0,            0,    0,      0,   0,   NULL,             NULL, NULL }
};


int display_main_menu()
{
   // load all the buttons:
   // dp = original image
   // dp2 = mouseover image
   // dp3 = clicked image
   main_dialog[LOGO].dp = datafile[LOGO_BMP].dat;
   main_dialog[INEXPENSIVE_ALTERNATIVES].dp = datafile[INEXPENSIVE_ALTERNATIVES_BMP].dat;
   main_dialog[SUNFIRE].dp = datafile[SUNFIRE_BMP].dat;
   main_dialog[READ_CODES].dp = datafile[READ_CODES1_BMP].dat;
   main_dialog[SENSOR_DATA].dp = datafile[SENSOR_DATA1_BMP].dat;
   main_dialog[FREEZE_FRAME].dp = datafile[FREEZE_FRAME1_BMP].dat;
   main_dialog[TESTS].dp = datafile[TESTS1_BMP].dat;
   main_dialog[OPTIONS].dp = datafile[OPTIONS1_BMP].dat;
   main_dialog[ABOUT].dp = datafile[ABOUT1_BMP].dat;
   main_dialog[EXIT].dp = datafile[EXIT1_BMP].dat;

   main_dialog[READ_CODES].dp2 = datafile[READ_CODES2_BMP].dat;
   main_dialog[SENSOR_DATA].dp2 = datafile[SENSOR_DATA2_BMP].dat;
   main_dialog[FREEZE_FRAME].dp2 = datafile[FREEZE_FRAME2_BMP].dat;
   main_dialog[TESTS].dp2 = datafile[TESTS2_BMP].dat;
   main_dialog[OPTIONS].dp2 = datafile[OPTIONS2_BMP].dat;
   main_dialog[ABOUT].dp2 = datafile[ABOUT2_BMP].dat;
   main_dialog[EXIT].dp2 = datafile[EXIT2_BMP].dat;

   main_dialog[READ_CODES].dp3 = datafile[READ_CODES3_BMP].dat;
   main_dialog[SENSOR_DATA].dp3 = datafile[SENSOR_DATA3_BMP].dat;
   main_dialog[FREEZE_FRAME].dp3 = datafile[FREEZE_FRAME3_BMP].dat;
   main_dialog[TESTS].dp3 = datafile[TESTS3_BMP].dat;
   main_dialog[OPTIONS].dp3 = datafile[OPTIONS3_BMP].dat;
   main_dialog[ABOUT].dp3 = datafile[ABOUT3_BMP].dat;
   main_dialog[EXIT].dp3 = datafile[EXIT3_BMP].dat;

   sprintf(welcome_message, "Roll mouse cursor over menu buttons to see their descriptions.");
   strcpy(button_description, welcome_message);

   return do_dialog(main_dialog, -1);
}


void reset_chip()
{
   centre_dialog(reset_chip_dialog);
   popup_dialog(reset_chip_dialog, -1);
}


// Reset states
#define RESET_START        0
#define RESET_WAIT_RX      1
#define RESET_ECU_TIMEOUT  2
#define RESET_WAIT_0100    3

int reset_proc(int msg, DIALOG *d, int c)
{
   static int state = RESET_START;
   static int device = 0;
   static char response[256];
   char buf[128];
   int status;
   
   switch (msg)
   {
      case MSG_START:
         strcpy(reset_status_msg, "Resetting hardware interface...");
         state = RESET_START;
         break;
   
      case MSG_IDLE:
         switch (state)
         {
            case RESET_START:
               if (serial_timer_running) // and if serial timer is running
               {
                  // wait until we either get a prompt or the timer times out
                  while ((read_comport(buf) != PROMPT) && !serial_time_out)
                     ;
               }
               send_command("atz"); // reset the chip
               start_serial_timer(ATZ_TIMEOUT);  // start serial timer
               response[0] = 0;
               state = RESET_WAIT_RX;
               break;

            case RESET_WAIT_RX:
               status = read_comport(buf);  // read comport

               if(status == DATA) // if new data detected in com port buffer
                  strcat(response, buf); // append contents of buf to response
               else if(status == PROMPT) // if '>' detected
               {
                  stop_serial_timer();
                  strcat(response, buf);
                  device = process_response("atz", response);
                  if (device == INTERFACE_ELM323 || device == INTERFACE_ELM327)
                  {
                     start_serial_timer(ECU_TIMEOUT);
                     strcpy(reset_status_msg, "Waiting for ECU timeout...");
                     state = RESET_ECU_TIMEOUT;
                     return D_REDRAW;
                  }
                  else
                     return D_CLOSE;
               }
               else if (serial_time_out) // if the timer timed out
               {
                  alert("Interface was not found", NULL, NULL, "OK", NULL, 0, 0);
                  stop_serial_timer(); // stop the timer
                  return D_CLOSE; // close dialog
               }
               break;
               
            case RESET_ECU_TIMEOUT:
               if (serial_time_out) // if the timer timed out
               {
                  stop_serial_timer(); // stop the timer
                  if (device == INTERFACE_ELM327)
                  {
                     send_command("0100");
                     start_serial_timer(OBD_REQUEST_TIMEOUT);  // start serial timer
                     response[0] = 0;
                     strcpy(reset_status_msg, "Detecting OBD protocol...");
                     state = RESET_WAIT_0100;
                     return D_REDRAW;
                  }
                  else
                     return D_CLOSE; // close dialog
               }
               break;
               
            case RESET_WAIT_0100:
               status = read_comport(buf);

               if(status == DATA) // if new data detected in com port buffer
                  strcat(response, buf); // append contents of buf to response
               else if (status == PROMPT)  // if we got the prompt
               {
                  stop_serial_timer();
                  strcat(response, buf);
                  status = process_response("0100", response);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -