
#include "APPDEF.H"
#include "math.h"
extern void HMICMDInit(void);
extern uint8_t MaxWeight;
extern uint8_t MaxTemp;
extern float Resolution;
extern float ResolutionWater;

#include <stdio.h>

int main(void)
{
    // 必须要先开时钟，再重映射；如果先重映射再开时钟，会重新恢复默认功能，重映射失败
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); // 关闭jtag，使能swd。

    GPIO_InPutset();
    AC_CTRL_Init();
    MAX6675_Init();
    FM24Init();
    //    INIT_CS555X();
    osDelay(1000); // 3秒
    AD7190_Init();
    switch (InstrumentTypeRead()) {
        case 0x01: // 国产 40-180 铝 0.005-50 0.02
            MaxWeight       = 50;
            Resolution      = 0.005;
            ResolutionWater = 0.02;
            MaxTemp         = 180;
            break;
        case 0x02: // 国产 40-180 铝 0.002-90 0.01
            MaxWeight       = 90;
            Resolution      = 0.002;
            ResolutionWater = 0.01;
            MaxTemp         = 180;
            break;
        case 0x03: // 国产 40-180 铝 0.001-100 0.01
            MaxWeight       = 120;
            Resolution      = 0.001;
            ResolutionWater = 0.01;
            MaxTemp         = 180;
            break;
        case 0x04: // HBM 40-200 不锈钢 0.005-50 0.02
            MaxWeight       = 50;
            Resolution      = 0.005;
            ResolutionWater = 0.02;
            MaxTemp         = 200;
            break;
        case 0x05: // HBM 40-200 不锈钢 0.002-100 0.01
            MaxWeight       = 100;
            Resolution      = 0.002;
            ResolutionWater = 0.01;
            MaxTemp         = 200;
            break;
        case 0x06: // HBM 40-200 不锈钢 0.001-200 0.01
            MaxWeight       = 200;
            Resolution      = 0.001;
            ResolutionWater = 0.01;
            MaxTemp         = 200;
            break;
        case 0x07: // HBM 40-180 铝 0.005-120 0.01
            MaxWeight       = 120;
            Resolution      = 0.005;
            ResolutionWater = 0.01;
            MaxTemp         = 180;
            break;
        case 0x08: // HBM 40-180 铝 0.002-120 0.01
            MaxWeight       = 120;
            Resolution      = 0.002;
            ResolutionWater = 0.01;
            MaxTemp         = 180;
            break;
        case 0x09: // HBM 40-180 铝 0.001-120 0.01
            MaxWeight       = 120;
            Resolution      = 0.001;
            ResolutionWater = 0.01;
            MaxTemp         = 180;
            break;
        default:
            MaxWeight       = 0;
            Resolution      = 0.005;
            ResolutionWater = 0.02;
            MaxTemp         = 0;
            break;
    }

    USARTHMIInit();
    HMICMDInit();
    while (1) {
        osDelay(1000);
    }
}
