stm32_ota/HARDWARE/SCREEN/screen.c

254 lines
9.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "screen.h"
#include <string.h>
/*************************************************************************************************************************
* @file screen.c
* @author 晏诚科技 Mr.Wang
* @version V1.0.0
* @date 11-Dec-2018
* @brief 提供LED语音显示屏主控板相关硬件驱动。实现LED内容显示、语音播报功能
******************************************************************************
* @使用方法:
* 先调用Screen_Init对LED语音显示屏主控板初始化然后使用驱动相关“对外接口函数"实现显示播报功能
************************************************************************************************************************/
/*********应用层外部调用文件*******************************************************/
#include "usart.h" //#define UART_SCREEN COM5
#include "sysport.h"
#include "io.h"
/**********************************************************************************/
/**********************************************************************************
*驱动内部使用常变量
*********************************************************************************/
#define UART_SCREEN COM5
#define SCREEN_RS485_TX PDout(0) = 1
#define SCREEN_RS485_RX PDout(0) = 0
#define SCREEN_PORT PD
#define SCREEN_PIN PIN0
/**************************************************************************************************
* 名 称: void Screen_Init(void)
* 外部引用: UARTx_Init(UART_SCREEN, 9600, COM_IT_NO, INT_RANK_2) ;
* 功能说明: 1、对控制显示屏RS485的收发控制IOPD0进行初始化。
* 2、对RS485串口初始化
* 3、默认为485输出模式
***************************************************************************************************/
void Screen_Init(void)
{
}
/**************************************************************************************************
* 名 称: RunResult ScreenPrint(uint8_t LineNum, const char *pData, SCREENCOLOR_e eColor)
* 外部引用: UARTx_SendData(UART_SCREEN, &screenCmd, length+7) ;
* 入口参数: @param1 LineNum 显示屏区号
* @param2 *pData 显示缓冲区指针
* @param3 eColor 显示颜色
**************************************************************************************************/
RunResult ScreenPrint(uint8_t LineNum, const char *pData, SCREENCOLOR_e eColor) //0:紅色 1綠色 2黄色
{
// if( LineNum == 0x00 )
// {
// return (InParamErr) ;
// }
// uint8_t i = 0, j = 0, len = 0;
// uint8_t color = eColor-0x30 ;
// SCREEN_CMD *screenCmd;
// screenCmd = portMalloc(sizeof(SCREEN_CMD)) ;
// uint16_t length = 0 ;
// screenCmd->header = 0xA0 ;
// screenCmd->addr = 0x90 ;
// screenCmd->page = LineNum ;
// screenCmd->cmd = 0xA5 ;
// memset(screenCmd->data, 0, SCREEN_DATA_LEN) ;
// len = strlen((const char*)pData ) ;
// screenCmd->cheecksum = 0x00 ;
//
// for( i = 0; i < len ; i++ ) //提前计算长度信息
// {
// if( (*(uint8_t*)(pData+i)) > 0x7F )
// {
// screenCmd->data[j] = *(uint8_t*)(pData+i) ;
// screenCmd->data[j+1] = *(uint8_t*)(pData+i+1) ;
// screenCmd->data[j+2] = color ;
// screenCmd->cheecksum ^= (*(uint8_t*)(pData+i))^ color^ *(uint8_t*)(pData+i+1) ;
// length = j+3 ;
// i++ ;
// j=j+3 ;
// }
// else
// {
// screenCmd->data[j] = *(uint8_t*)(pData+i) ;
// screenCmd->data[j+1] = color ;
// length = j+2 ;
// j= j+2 ;
// screenCmd->cheecksum ^= (*(uint8_t*)(pData+i))^ color;
// }
// if( j >= SCREEN_DATA_LEN-1 )
// {
// portFree(screenCmd) ;
// return (RUNERR) ;
// }
// }
//
// screenCmd->lengthH = 0xFF &( length >> 8) ;
// screenCmd->lengthL = 0xFF & length ;
// screenCmd->cheecksum = screenCmd->cheecksum^ screenCmd->page^ screenCmd->cmd^ screenCmd->lengthH^ screenCmd->lengthL ;
// screenCmd->data[length] = screenCmd->cheecksum ;
// UARTx_SendData(UART_SCREEN, (char*)screenCmd, length+7) ;
// portFree(screenCmd) ;
return (RUNOK) ;
}
/**************************************************************************************************
* 名 称: RunResult ScreenPrint(uint8_t LineNum, const char *pData, SCREENCOLOR_e eColor)
* 外部引用: UARTx_SendData(UART_SCREEN,&screenCmd, length+7) ;
* 入口参数: @param1 LineNum 显示屏区号
* @param2 *pData 显示缓冲区指针
* @param3 eColor 显示颜色
**************************************************************************************************/
RunResult ScreenPrint2(uint8_t LineNum, SCREENCOLOR_e eColor, char *format, ... ) //0:紅色 1綠色 2黄色
{
// if( LineNum == 0x00 )
// {
// return (InParamErr) ;
// }
// uint8_t color = eColor - 0x30 ;
// char *pData = portMalloc(SCREEN_DATA_LEN) ;
// va_list ap;
// va_start(ap, format) ;
// int outLen = vsnprintf(pData, SCREEN_DATA_LEN, (const char*)format, ap); //vsprintf (temp, cmd, ap); //到此为止所有的参数情况已经汇总到temp了
// if((outLen<=0)||( outLen > SCREEN_DATA_LEN))
// {
// ErrorLogPrintf("pData 溢出!--增加SCREEN_DATA_LEN数值。") ;
// va_end (ap);
// portFree(pData) ;
// return RUNERR ;
// }
//
// uint8_t i = 0, j = 0, len = 0;
// SCREEN_CMD *screenCmd;
// screenCmd = portMalloc(sizeof(SCREEN_CMD)) ;
// uint16_t length = 0 ;
// screenCmd->header = 0xA0 ;
// screenCmd->addr = 0x90 ;
// screenCmd->page = LineNum ;
// screenCmd->cmd = 0xA5 ;
// memset(screenCmd->data, 0, SCREEN_DATA_LEN) ;
// len = strlen((const char*)pData ) ;
// screenCmd->cheecksum = 0x00 ;
//
// for( i = 0; i < len ; i++ ) //提前计算长度信息
// {
// if( (*(uint8_t*)(pData+i)) > 0x7F )
// {
// screenCmd->data[j] = *(uint8_t*)(pData+i) ;
// screenCmd->data[j+1] = *(uint8_t*)(pData+i+1) ;
// screenCmd->data[j+2] = color ;
// screenCmd->cheecksum ^= (*(uint8_t*)(pData+i))^ color^ *(uint8_t*)(pData+i+1) ;
// length = j+3 ;
// i++ ;
// j=j+3 ;
// }
// else
// {
// screenCmd->data[j] = *(uint8_t*)(pData+i) ;
// screenCmd->data[j+1] = color ;
// length = j+2 ;
// j= j+2 ;
// screenCmd->cheecksum ^= (*(uint8_t*)(pData+i))^ color;
// }
// if( j >= SCREEN_DATA_LEN-1 )
// {
// portFree(screenCmd) ;
// portFree(pData) ;
// return (RUNERR) ;
// }
// }
//
// screenCmd->lengthH = 0xFF &( length >> 8) ;
// screenCmd->lengthL = 0xFF & length ;
// screenCmd->cheecksum = screenCmd->cheecksum^ screenCmd->page^ screenCmd->cmd^ screenCmd->lengthH^ screenCmd->lengthL ;
// screenCmd->data[length] = screenCmd->cheecksum ; //实际将screenCmd->cheecksum 填充到screenCmd->data最后一位
// UARTx_SendData(UART_SCREEN, (char*)screenCmd, length+7) ;
// portFree(screenCmd) ;
// portFree(pData) ;
return (RUNOK) ;
}
/**************************************************************************************************
* 名 称: RunResult VoicePrint( uint8_t volumeRank, char *format, ... )
* 外部引用: UARTx_SendData(UART_SCREEN,(uint8_t*)&voiceCmd, voiceLength+10 ) ;
* 入口参数:
* @param1 volumeRank 语音播报音量
* @param2 *format 可变参格式
* @param3 ... 变参参数
**************************************************************************************************/
RunResult VoicePrint( uint8_t volumeRank, char *format, ... )
{
// char *pData = portMalloc(SCREEN_DATA_LEN) ;
// va_list ap;
// va_start(ap, format) ;
// int outLen = vsnprintf(pData, SCREEN_DATA_LEN, (const char*)format, ap); //vsprintf (temp, cmd, ap); //到此为止所有的参数情况已经汇总到temp了
// if((outLen<=0)||( outLen > SCREEN_DATA_LEN))
// {
// ErrorLogPrintf("pData 溢出!--增加SCREEN_DATA_LEN数值。") ;
// va_end (ap);
// portFree(pData) ;
// return RUNERR ;
// }
//
// uint8_t n = 0 ;
// VOICE_CMD *voiceCmd ;
// uint16_t voiceLength = 0 ;
// voiceCmd = portMalloc(sizeof(VOICE_CMD)) ;
// voiceCmd->header = 0xA0 ;
// voiceCmd->addr = 0x90 ;
// voiceCmd->page = 0x01 ;
// voiceCmd->cmd = 0x52 ;
// voiceCmd->cheecksum = 0x00 ;
//
// voiceLength = strlen( (const char*)pData )+2+4 ;
// voiceCmd->voiceLengthH = 0xFF &( voiceLength >> 8) ;
// voiceCmd->voiceLengthL = 0xFF & voiceLength ;
//
// voiceCmd->lengthH = voiceCmd->voiceLengthH ;
// voiceCmd->lengthL = voiceCmd->voiceLengthL+3 ;
//
// voiceCmd->voiceHeader = 0xFD ;
// voiceCmd->cmdVoice = 0x01 ;
// voiceCmd->voiceFormat = 0x00 ;
// memset(voiceCmd->data, 0, 64) ;
//
// snprintf((char*)voiceCmd->data, 5, "[v%c]", volumeRank) ;
// strcat( (char*)voiceCmd->data , (const char*)pData ) ;
////snprintf( (char*)voiceCmd.data2, 5, "[v%c]", volumeRank) ;
////snprintf( (char*)&voiceCmd.data2[5] ,SCREEN_DATA_LEN-5, "%s", (const char*)pData ) ;
// voiceCmd->cheecksum = voiceCmd->page^ voiceCmd->cmd^ voiceCmd->lengthH^ voiceCmd->lengthL^
// voiceCmd->voiceHeader^ voiceCmd->voiceLengthH^ voiceCmd->voiceLengthL^ voiceCmd->cmdVoice^ voiceCmd->voiceFormat ;
// for( n = 0; n < voiceLength; n++ )
// {
// voiceCmd->cheecksum = voiceCmd->cheecksum^ voiceCmd->data[n] ;
// }
// voiceCmd->data[voiceLength-2] = voiceCmd->cheecksum ;
// if( voiceLength >= SCREEN_DATA_LEN-10)
// {
// portFree(voiceCmd) ;
// portFree(pData) ;
// return (RUNERR) ;
// }
// UARTx_SendData(UART_SCREEN,(char*)voiceCmd, voiceLength+10 ) ;
// portFree(voiceCmd) ;
// portFree(pData) ;
return (RUNOK) ;
}