You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
62 lines
1.5 KiB
10 months ago
|
#include "app_screen_save.h"
|
||
|
#include "../msp/msp_eeprom.h"
|
||
10 months ago
|
|
||
10 months ago
|
//定义所使用内存的起始和结尾标志
|
||
10 months ago
|
#define HEAD0 0xa3
|
||
|
#define HEAD1 0xa4
|
||
|
#define TAIL0 0xa5
|
||
|
#define TAIL1 0xa6
|
||
|
|
||
10 months ago
|
SCREEN_SAVE screen_save_arr[SCREEN_SAVE_LEN] = {0};
|
||
10 months ago
|
|
||
10 months ago
|
//初始化存放重量数据的结构体数组screen_save_arr
|
||
10 months ago
|
void screen_save_init()
|
||
|
{
|
||
10 months ago
|
int i = 0;
|
||
10 months ago
|
for(i = 0;i < SCREEN_SAVE_LEN; i++)
|
||
|
{
|
||
|
screen_save_arr[i].head[0] = HEAD0;
|
||
|
screen_save_arr[i].head[1] = HEAD1;
|
||
|
screen_save_arr[i].available = 0;
|
||
10 months ago
|
screen_save_arr[i].kgx10_out = 0;
|
||
10 months ago
|
screen_save_arr[i].tail[0] = TAIL0;
|
||
|
screen_save_arr[i].tail[1] = TAIL1;
|
||
|
}
|
||
|
}
|
||
10 months ago
|
//存放重量数据到eeprom中
|
||
10 months ago
|
void screen_save_push(U16 weight)
|
||
|
{
|
||
|
int i = 0;
|
||
|
int free = 0;
|
||
|
// 从eeprom中取出数组
|
||
|
L0_Iap_Read_array(EEPROM_WEIGHT_ADDR, screen_save_arr,sizeof(screen_save_arr));
|
||
|
if(screen_save_arr[0].head[0] != HEAD0 || screen_save_arr[0].head[1] != HEAD1
|
||
|
|| screen_save_arr[0].tail[0] != TAIL0 || screen_save_arr[0].tail[1] != TAIL1)
|
||
|
{
|
||
|
screen_save_init();
|
||
|
}
|
||
|
// 遍历寻找空位
|
||
|
for(i = 0;i < SCREEN_SAVE_LEN; i++)
|
||
|
{
|
||
10 months ago
|
if(screen_save_arr[i].available != 0)
|
||
10 months ago
|
{
|
||
|
free = i;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
// 当都有数据时
|
||
|
if(i == SCREEN_SAVE_LEN)
|
||
|
{
|
||
10 months ago
|
for(i = 0; i < SCREEN_SAVE_LEN - 1; i++)
|
||
10 months ago
|
{
|
||
|
screen_save_arr[i] = screen_save_arr[i+1];
|
||
|
}
|
||
|
free = SCREEN_SAVE_LEN-1;
|
||
|
}
|
||
|
// 放到free位置
|
||
10 months ago
|
screen_save_arr[free].available = 0;
|
||
10 months ago
|
screen_save_arr[free].kgx10_out = weight;
|
||
|
// 把数组放回eeprom中
|
||
|
L0_Iap_Program_array(EEPROM_WEIGHT_ADDR, screen_save_arr,sizeof(screen_save_arr));
|
||
|
}
|