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

📄 s_toolssample.c

📁 dragon ball vz328 上的一个例子程序。 用于做手持仪表用。
💻 C
📖 第 1 页 / 共 4 页
字号:
            ttp += (0<<2);
        if (getbytebit(tmp, 0))
            ttp += 3;
        else
            ttp += 0;

        *addrFont++ = ttp;
        ttp = 0;
    }
}

void SRClearRec(U16 greyLevel, U16 xSrc, U16 ySrc, U16 width, U16 height, U16 style){
    U16 x, y; 
    U16 temp;
    U16 x1,y1;

    x1=xSrc;
    y1=ySrc;
    temp=x1;
    x1=y1;
    y1=240-temp;
    ClearRec(greyLevel,x1,y1-width,height,width,style);
} 

U32 Typing(U8 font, U8 style, U8 greylev, U16 xSrc, U16 ySrc, P_U8 str) // MWERKS_PPSMV311
{
    U32 tmp;
    U32 Cobit;
    U8  dsPtr[64];
    U8  upbit,downbit;  
    U16 sizex=0,sizey=0,offset=0;

    if ((font==SMALL_NORMAL_FONT) || (font==SMALL_ITALIC_FONT)) {
        sizex = 8;
        sizey = 10;
    } else if ((font==LARGE_NORMAL_FONT) || (font==LARGE_ITALIC_FONT)) {
        sizex = 16;
        sizey = 20;
    } else if (font==GB_NORMAL_FONT) {
        sizex = 16;
        sizey = 16;
    } else
        return PPSM_ERROR;   
    tmp=xSrc;
    xSrc=ySrc;
    ySrc=240-tmp;
    while ((upbit = *(str))!='\0') {
        if (upbit > 0xa1) {
            downbit = *(str+1);   
            Cobit = GB_FONT_ADDR+((upbit-0xa1)*94 + (downbit-0xa1))*32;
            Convert1bitTo2bit( (P_U8)Cobit,1, dsPtr);
            if ( ySrc > offset ) {
                offset+=sizey;
                if (PutRec((P_U8)dsPtr, xSrc, ySrc-offset, sizex, sizey,REPLACE_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
            } else
                break; 
            str++;
        } else {
            Cobit = SMALL_ENG_FONT_ADDR+((upbit)<<4);
            Convert1bitTo2bit( (P_U8)Cobit,0, dsPtr);
            if ( ySrc>offset) {
                offset+=8;
                if (PutRec((P_U8)dsPtr, xSrc, ySrc-offset, 16,8,REPLACE_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
            } else
                break;
        }   
        str++;
    }
    return(PPSM_OK);                 
} 



/*
 * Function2: Draw a 3D region with the input parameter:
 * U16      xSrc        the top-left corner of the TextButton
 * U16      ySrc
 * U16      xDest       the bottom-right corner of the TextButton
 * U16      yDest
 * U16      style       the style of the region
 */

STATUS Button3D(U16 xSrc, U16 ySrc, U16 xDest, U16 yDest, U16 style)
{
    if (DrawRec(BLACK, xSrc, ySrc, xDest, yDest, 0, REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;

    /* Fill the rectangular area by style */
    if (ClearRec(LIGHT_GREY, xSrc+4, ySrc+4, (xDest-3)-(xSrc+4), 
                 (yDest-11)-(ySrc-4), style)!= PPSM_OK) return PPSM_ERROR;
    if (DrawLine(LIGHT_GREY,xSrc+1,ySrc+1,xSrc+3,ySrc+3,0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawHorz(DARK_GREY,xSrc+1,yDest-1,(xDest)-(xSrc+1),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawVert(DARK_GREY,xDest-1,ySrc+1,(yDest-1)-(ySrc+1),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawHorz(DARK_GREY,xSrc+2,yDest-2,(xDest)-(xSrc+2),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawVert(DARK_GREY,xDest-2,ySrc+2,(yDest-1)-(ySrc+2),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawHorz(DARK_GREY,xSrc+3,yDest-3,(xDest)-(xSrc+3),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawVert(DARK_GREY,xDest-3,ySrc+3,(yDest-1)-(ySrc+3),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;

    return PPSM_OK;
}    

STATUS PutStr270(P_TEXT str, U16 xSrc, U16 ySrc, U16 sizex, U16 sizey)
{
    U32 tmp , i,j;
    U32 Cobit;
    U8  dsPtr[64];
    U8  upbit,downbit;
    /*tmp=xSrc;
    xSrc=ySrc;
    ySrc=240-xSrc;*/
    tmp=Strlen(str);
    for ( i = 0 ,j=0; i < tmp ; i++,j++) {
        if (*(str) > 0xa1a1) {
            downbit = *(str)&0x00ff;
            upbit = *(str)>>8;        
            Cobit = GB_FONT_ADDR+((upbit-0xa1)*94 + (downbit-0xa1))*32;
            Convert1bitTo2bit( (P_U8)Cobit,1, dsPtr);
            if ( ySrc > (i+1)*sizey ) {
                if (PutRec((P_U8)dsPtr, xSrc, ySrc-(i+1)*sizey, sizex, sizey,REPLACE_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
            } else
                break;
            j++;
        } else {
            downbit = *(str)&0x00ff;
            upbit = *(str)>>8;        
            Cobit = SMALL_ENG_FONT_ADDR+((upbit)<<4);
            Convert1bitTo2bit( (P_U8)Cobit,0, dsPtr);
            if ( ySrc > (j+1)*8 ) {
                if (PutRec((P_U8)dsPtr, xSrc, ySrc-(j+1)*8, 16, 8,REPLACE_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
            }
            Cobit = SMALL_ENG_FONT_ADDR+((downbit)<<4);
            Convert1bitTo2bit( (P_U8)Cobit,0, dsPtr);
            j=j+1;
            if ( ySrc > (j+1)*8 ) {
                if (PutRec((P_U8)dsPtr, xSrc, ySrc-(j+1)*8, 16, 8,REPLACE_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
            } else
                break;
        }      
        str++;
    }
    return(PPSM_OK);  
}


STATUS PutString270(P_TEXT str, U16 xSrc, U16 ySrc, U16 sizex, U16 sizey)
{
    U32 tmp , i,j;
    U32 Cobit;
    U8  dsPtr[64];
    U8  upbit,downbit;
    tmp=xSrc;
    xSrc=ySrc;
    ySrc=240-tmp;
    tmp=Strlen(str);
    for (i=0,j=0;i<tmp;i++,j++) {
        if (*(str) > 0xa1a1) {
            downbit = *(str)&0x00ff;
            upbit = *(str)>>8;        
            Cobit = GB_FONT_ADDR+((upbit-0xa1)*94 + (downbit-0xa1))*32;
            Convert1bitTo2bit( (P_U8)Cobit,1, dsPtr);
            if ( ySrc > (i+1)*sizey ) {
                if (PutRec((P_U8)dsPtr, xSrc, ySrc-(i+1)*sizey, sizex, sizey,REPLACE_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
            } else
                break;
            j++;
        } else {
            downbit = *(str)&0x00ff;
            upbit = *(str)>>8;        
            Cobit = SMALL_ENG_FONT_ADDR+((upbit)<<4);
            Convert1bitTo2bit( (P_U8)Cobit,0, dsPtr);
            if ( ySrc>(j+1)*8 ) {
                if (PutRec((P_U8)dsPtr, xSrc, ySrc-(j+1)*8, 16,8,REPLACE_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
            } else
                break;
            Cobit = SMALL_ENG_FONT_ADDR+((downbit)<<4);
            Convert1bitTo2bit( (P_U8)Cobit,0, dsPtr);
            j=j+1;
            if ( ySrc>(j+1)*8 ) {
                if (PutRec((P_U8)dsPtr, xSrc, ySrc-(j+1)*8, 16, 8,REPLACE_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
            } else
                break;
        }   
        str++;
    }
    return(PPSM_OK);  
}

STATUS Button3D270(U16 xSrc, U16 ySrc, U16 xDest, U16 yDest, U16 style)
{
    if (DrawRec(BLACK, xSrc, ySrc, xDest, yDest, 0, REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;

    /* Fill the rectangular area by style */
    /*if (ClearRec(LIGHT_GREY,xSrc+4, yDest+4,(xDest-3)-(xSrc+4),
        (ySrc-3)-(yDest+4),style)!= PPSM_OK) return PPSM_ERROR;*/
    if (DrawLine(LIGHT_GREY,xSrc+1,ySrc-1,xSrc+3,ySrc-3,0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawHorz(DARK_GREY,xSrc+1,yDest+1,(xDest-1) - (xSrc+1),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawVert(DARK_GREY,xDest-1,yDest+1,(ySrc) - (yDest+1),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawHorz(DARK_GREY,xSrc+2,yDest+2,(xDest) - (xSrc+2),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawVert(DARK_GREY,xDest-2,yDest+1,(ySrc-1) - (yDest+1),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawVert(DARK_GREY,xDest-3,yDest+1,(ySrc-3) - (yDest),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawHorz(DARK_GREY,xSrc+3,yDest+3,(xDest-1)-(xSrc+3),0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;

    return PPSM_OK;
}

STATUS Cirdraw(U16 xSrc, U16 ySrc, U16 width, U16 height){
    DrawCircle(BLACK, xSrc+(width/2), ySrc+(width/2), width/2, REPLACE_STYLE);
    ClearRec(WHITE, xSrc, ySrc+(width/2), width, (width/2)+1, REPLACE_STYLE);
    DrawCircle(BLACK, xSrc+(width/2), ySrc+height-(width/2), width/2, REPLACE_STYLE);
    ClearRec(WHITE, xSrc,ySrc+height-width, width, width/2, REPLACE_STYLE);
    if (DrawLine(BLACK,xSrc,ySrc+(width/2),xSrc,ySrc+height-width/2,0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
    if (DrawLine(BLACK,xSrc+width-1,ySrc+(width/2),xSrc+width-1,ySrc+height-width/2,0,REPLACE_STYLE)
        != PPSM_OK) return PPSM_ERROR;
}


STATUS CirTextButton(P_U32 areaId, U8 font, TEXT str[], U16 xSrc, U16 ySrc, U16 width, U16 height, U8 flag){

    U16 x, y; 
    U16 sizex, sizey;
    U16 temp;
    U16 x1,y1;

    x1=xSrc;
    y1=ySrc;
    temp=x1;
    x1=y1;
    y1=240-temp;
    /* Detetmine the font size */
    if ((font==SMALL_NORMAL_FONT) || (font==SMALL_ITALIC_FONT)) {
        sizex = 8;
        sizey = 10;
    } else if ((font==LARGE_NORMAL_FONT) || (font==LARGE_ITALIC_FONT)) {
        sizex = 16;
        sizey = 20;
    } else if (font==GB_NORMAL_FONT) {
        sizex = 16;
        sizey = 16;
    } else
        return PPSM_ERROR;

    Cirdraw(x1, y1-width, height, width);

    /* Activate the region if flag = 1 */   
    if (flag == 1)
        if (ActiveAreaEnable(areaId,ICON_AREA,CONTINUOUS_MODE, x1, y1-width, x1+height, y1)
            != PPSM_OK) return PPSM_ERROR;

        /* Calculate the co-ordinate for fonts */
        /* Calculate the co-ordinate for fonts */

    y = y1 - ((width - Strlen(str)*sizex) >> 1);   
    x = x1 + ((height - sizey) >> 1) + 1;

    /* Type text on the button */
    if (PutStr270(str, x, y, sizex, sizey) // MWERKS_PPSMV311
        != PPSM_OK) rv= PPSM_ERROR;

    return PPSM_OK;  


}

STATUS TextButton(P_U32 areaId, U8 font, TEXT str[], U16 xSrc, U16 ySrc, U16 width, U16 height, U8 flag)
{
    U16 x, y; 
    U16 sizex, sizey;
    U16 temp;
    U16 x1,y1;

    x1=xSrc;
    y1=ySrc;
    temp=x1;
    x1=y1;
    y1=240-temp;
    /* Detetmine the font size */
    if ((font==SMALL_NORMAL_FONT) || (font==SMALL_ITALIC_FONT)) {
        sizex = 8;
        sizey = 10;
    } else if ((font==LARGE_NORMAL_FONT) || (font==LARGE_ITALIC_FONT)) {
        sizex = 16;
        sizey = 20;
    } else if (font==GB_NORMAL_FONT) {
        sizex = 16;
        sizey = 16;
    } else
        return PPSM_ERROR;

    /* Draw a 3D button */
    if (Button3D270(x1, y1, x1+height, y1-width, REPLACE_STYLE) 
        != PPSM_OK) return PPSM_ERROR;

    /* Activate the region if flag = 1 */
    if (flag == 1)
        if (ActiveAreaEnable(areaId,ICON_AREA,CONTINUOUS_MODE, x1, y1-width, x1+height, y1)
            != PPSM_OK) return PPSM_ERROR;

        /* Calculate the co-ordinate for fonts */
        /* Calculate the co-ordinate for fonts */

    y = y1 - ((width - Strlen(str)*sizex) >> 1);   
    x = x1 + ((height - sizey) >> 1) + 1;

    /* Type text on the button */
    if (PutStr270(str, x, y, sizex, sizey) // MWERKS_PPSMV311
        != PPSM_OK) rv= PPSM_ERROR;

    return PPSM_OK;      
}

STATUS AredText(P_U32 areaId, U8 font, TEXT str[], U16 xSrc, U16 ySrc, U16 width, U16 height, U8 flag)
{
    U16 x, y; 
    U16 sizex, sizey;
    U16 temp;
    U16 x1,y1;

    x1=xSrc;
    y1=ySrc;
    temp=x1;
    x1=y1;
    y1=240-temp;
    /* Detetmine the font size */
    if ((font==SMALL_NORMAL_FONT) || (font==SMALL_ITALIC_FONT)) {
        sizex = 8;
        sizey = 10;
    } else if ((font==LARGE_NORMAL_FONT) || (font==LARGE_ITALIC_FONT)) {
        sizex = 16;
        sizey = 20;
    } else if (font==GB_NORMAL_FONT) {
        sizex = 16;
        sizey = 16;
    } else
        return PPSM_ERROR;

    /* Draw a 3D button */
    //if(Button3D270(x1, y1, x1+height, y1-width, REPLACE_STYLE) 
    //    != PPSM_OK) return PPSM_ERROR;

    /* Activate the region if flag = 1 */   
    if (flag == 1)
        if (ActiveAreaEnable(areaId,ICON_AREA,CONTINUOUS_MODE, x1, y1-width, x1+height, y1)
            != PPSM_OK) return PPSM_ERROR;

        /* Calculate the co-ordinate for fonts */
        /* Calculate the co-ordinate for fonts */

    y = y1 - ((width - Strlen(str)*sizex) >> 1);   
    x = x1 + ((height - sizey) >> 1) + 1;

    /* Type text on the button */
    if (PutStr270(str, x, y, sizex, sizey) // MWERKS_PPSMV311
        != PPSM_OK) rv= PPSM_ERROR;

    return PPSM_OK;      
}

void StrASCIIToTEXT(P_TEXT buffU16, P_U8 buffU8)
{
    U8 i; 
    for (i=0; *(P_U8)buffU8 !=0;i++) {
        *(buffU16)=*(buffU8); 
        buffU8++;
        *(buffU16)=*(buffU16)<<8;
        *(buffU16)=*(buffU16)|*(buffU8);
        buffU16++;
        buffU8++;
    }           
} 



STATUS DisplayNum(U32 num, U16 xSrc, U16 ySrc, U16 font)
{
    U8      Num[MAXLEN];
    TEXT    NumTxt[MAXLEN];
    U16     i;

    sprintf((char *)Num, "%.3d", num);

    /* Convert to TEXT format */                     
    StrASCIIToTEXT(NumTxt, Num);

    if (Typing(font, STYLE, BLACK, xSrc, ySrc, (P_U8)NumTxt)
        != PPSM_OK) return PPSM_ERROR;


    return PPSM_OK;
}


STATUS NumButton(P_U32 iconid,U32 num, U8 font, U16 xSrc, U16 ySrc, U16 width, U16 height, U8 flag, U8 tt){

    U8      Num[MAXLEN];
    TEXT    NumTxt[MAXLEN];
    U16     i;

    for (i=0;i<MAXLEN;i++) {
        NumTxt[i]=0;
        Num[i]=0;
    }
    if (tt==1) {
        sprintf((char *)Num, "%.1d", num);
    } else if (tt==2) {
        sprintf((char *)Num, "%.2d", num);  
    } else if ( tt==3) {
        sprintf((char *)Num, "%.3d", num);
    } else if ( tt==4) {
        sprintf((char *)Num, "%.4d", num);
    } else if ( tt==5) {
        sprintf((char *)Num, "%.5d", num);
    } else if ( tt==6) {
        sprintf((char *)Num, "%.6d", num);
    }
    /* Convert to TEXT format */
    StrASCIIToTEXT(NumTxt, Num);

    //if (Typing(font, STYLE, BLACK, xSrc, ySrc, (P_TEXT)NumTxt)
    //    != PPSM_OK) return PPSM_ERROR;  
    AredText(iconid, font, (P_TEXT)NumTxt, xSrc, ySrc, width, height, flag);    
    return PPSM_OK;

} 
/* Function 8:
 * Display the x, y coordinate
 */




STATUS ErrCheck(STATUS rv)
{    
    /* Swap Task to Error App if rv is not zero*/
    /*if(rv != PPSM_OK)
        if (AdvSendMessage(gErrorId, NULL, SWAP_TASK_BACK_LATER) 
            != PPSM_OK) return PPSM_ERROR;*/
    return PPSM_OK;
}



void Strcpy(P_TEXT dest, P_TEXT src)
{
    while (*dest++ = *src++);
}     

void StrcpyU8(P_U8 dest,P_U8 src ){
    while (*dest++ = *src++);
}

S16 Strcmp(P_TEXT string1, P_TEXT string2)
{
    for (; *string1 == *string2; string1++, string2++)
        if (*string1 == '\0')
            return 0;
    return(*string1 - *string2);
} 

⌨️ 快捷键说明

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