217 lines
4.4 KiB
C
Raw Permalink Normal View History

2025-05-10 16:03:55 +08:00
#ifndef _APP_TEMPERATURE_H_
#define _APP_TEMPERATURE_H_
#include <rtthread.h>
#include <finsh.h>
#include "common.h"
#include "param_config.h"
#include "ble_pub.h"
#include "drv_oled.h"
#include "belon_ble.h"
#if (CFG_BLE_VERSION == BLE_VERSION_5_2)
#include "app_ble.h"
#include "app_sdp.h"
#include "app_ble_init.h"
#endif
#if (BLE_APP_SEC)
#include "app_sec.h"
#endif
#include "kernel_mem.h"
2025-07-14 09:29:18 +08:00
2025-05-10 16:03:55 +08:00
/**
* iT12
*/
#define BLE_TEMPERATURE_DEVICE_IT12 "iT12"
/**
* iT22
2025-05-10 16:03:55 +08:00
*/
#define BLE_TEMPERATURE_DEVICE_IT22 "iT22"
2025-05-24 17:25:09 +08:00
/**
* ID iT18
*/
#define PRODUCTID "iT18"
/**
* ID
*/
#define DEVICEID "iT18_C8478C428848"
2025-05-10 16:03:55 +08:00
/**
*
*/
#define BLE_TEMPERATURE_DETECT_DEVICE_INTERVAL 1000
/**
* LOW
*/
#define BLE_TEMPERATURE_LIMIT_MIN 3200
/**
* HIGH
*/
2025-05-24 17:25:09 +08:00
#define BLE_TEMPERATURE_LIMIT_MAX 4290
2025-05-10 16:03:55 +08:00
/**
*
*/
#define BLE_TEMPERATURE_MIN 2000
/**
*
*/
#define BLE_TEMPERATURE_MAX 5000
/**
* GPIO
*/
#define BLE_TEMPERATURE_BOX_RESET_LCD 37
2025-05-10 16:03:55 +08:00
/**
* GPIO
*/
#define BLE_TEMPERATURE_HALL_DETECT_PIN 38
/**
* GPIO
*/
#define BLE_TEMPERATURE_BOX_POWER_CTR 39
/**
*
*/
#define BLE_TEMPERATURE_POWEROFF_TIMEOUT 3000 //ms
/**
* BLE
*/
#define BLE_TEMPERATURE_BIND_MODE_TIMEOUT 8000 //ms
/**
*
*/
#define BLE_TEMPERATURE_HALL_DETECT_INTERVAL 50 //ms
/**
2025-07-14 09:29:18 +08:00
* 25s 广
2025-05-10 16:03:55 +08:00
*/
2025-07-14 09:29:18 +08:00
#define BLE_TEMPERATURE_IDLE_MODE_TIMEOUT 25000 //ms
2025-05-10 16:03:55 +08:00
/**
* easyflah KEY
*/
#define BLE_TEMPERATURE_FLASH_CONFIG_KEY "dev_cfg"
/**
* easyflah KEY
*/
#define BLE_TEMPERATURE_FLASH_RECORD_KEY "dev_record"
2025-05-24 17:25:09 +08:00
/**
* MQTT ID and KEY
*/
#define SECUREID_MQTT "pokaAdmin"
#define SECUREKEY_MQTT "poka@123456"
2025-05-10 16:03:55 +08:00
/**
* easyflah KEY BIND MAC
*/
#define BLE_TEMPERATURE_FLASH_CONFIG_KEY_BIND_MAC "bind_mac"
/**
* easyflah KEY temperature
*/
#define BLE_TEMPERATURE_FLASH_RECORD_KEY_TEMPERATURE "m1_temperature"
/**
* easyflah KEY time
*/
#define BLE_TEMPERATURE_FLASH_RECORD_KEY_TIMESTAMP "m1_timestamp"
typedef enum
{
APP_MODE_NORMAL,
APP_MODE_BIND,
} app_temperature_mode_t;
typedef struct
{
uint8_t device_name[16];
uint8_t device_mac[6];
uint16_t temperature_body;
uint16_t temperature_obj;
uint16_t temperature_env;
uint16_t batt_percent;
2025-05-10 16:03:55 +08:00
uint16_t batt_val;
uint16_t device_state;
}app_temperature_info_t;
/**
*
*/
typedef struct
{
uint16_t battery_value;
/**
* 1 -- 0 --
*/
uint16_t charge_state;
/**
* 0 -- 1 --
*/
uint16_t hall_state;
}app_box_info_t;
typedef enum
{
//正在测量
STATE_DETECT_ING,
//测量完成
STATE_DETECT_FINISH,
} app_detect_state_t;
/**
* BOX
*/
typedef struct
{
uint8_t bind_mac[6];
uint16_t detect_interval;
}app_dev_info_t;
typedef struct
{
uint8_t timestamp[8];
uint16_t temperature_value;
}app_detect_record_t;
typedef enum
{
UI_IDLE,
UI_WAIT_TEMPERATURE,
UI_BOX_BATTERY,
UI_BOX_BIND,
UI_SHOW_TEMPERATURE,
UI_SHOW_DEVICE_INFO,
2025-05-24 17:25:09 +08:00
UI_SHOW_MEMORY_INFO,
UI_SHOW_LOW_BAT_INFO,
2025-05-10 16:03:55 +08:00
}app_ui_mode;
2025-05-16 18:06:38 +08:00
2025-05-10 16:03:55 +08:00
void temperature_init(void);
void temperature_adv_callback(recv_adv_t *r_ind);
void app_enter_bind_mode(bool enter);
2025-05-24 17:25:09 +08:00
void mqtt_upload_temperature(uint16_t t_value);
int mqtt_start(char username[],char password[]);
void poka_client_password();
void poka_client_username();
2025-05-16 18:06:38 +08:00
void connnect_wifi(char *oob_ssid,char *connect_key);
2025-05-24 17:25:09 +08:00
2025-05-10 16:03:55 +08:00
/**
*
*/
void temperature_save_record(app_detect_record_t *record);
//void temperature_save_record(uint16_t t_value);
/**
*
*/
void temperature_read_record(app_detect_record_t *record);
void temperature_led_ble(bool onoff);
void app_enter_ui(app_ui_mode mode);
#endif //_APP_TEMPERATURE_H_