// ---- Configuration ----
#define DWrite_MaxWrite 0 // when to stop textoutput: 0=complete text, 1=first whitespace, 2 or more for stop after n characters
#define DWrite_Wait 500 // 500ms for each character to display
#define DWrite_WaitNext 80 // 50ms before next character to display
#define DWrite_WaitNextD NULL // the mask from display.gph to show between characters, default is none/NULL;
#define DWrite_Def SEG_D // the mask from display.gph to use for unknown characters, SEG_D is the bottom segment
#define DWrite_Ws NULL // the mask from display.gph to use for whitespace, default is none/NULL;
//
#define DWRITE_NS // no special character like: dot slash underline (only a few supported atm)
#define DWRITE_LC // lowercase only (default) (converts upper to lower)
#define DWRITE_UC // uppercase only (converts lower to upper)
#define DWRITE_MC // uppercase and lowercase
#define DWRITE_DI // disable function DWriteInt(int32 Num) (number to char conversion output)
#define DWRITE_DF // disable function DWriteFix(fix32 Num) (fix32 numer to char conversion output)
*** Notes END ***/
#ifndef DISPLAY_GPH_
#include <display.gph>
#endif
#ifndef DWrite_GPH_
#define DWrite_GPH_
// display options
//
//
#ifndef DWrite_Ws
#define DWrite_Ws NULL // mask (from display.gph) to display for whitespace
#endif
//
#ifndef DWrite_MaxWrite
#define DWrite_MaxWrite 0 // show maximum of selected characters
// // 0 = complete
// // 1 = stop at first whitespace
// // 2 and above = stop after n characters
#endif
//
#ifndef DWrite_Wait
#define DWrite_Wait 450 // delay between each character during text display via segment led
#endif
//
#ifndef DWrite_WaitNext
#define DWrite_WaitNext 60 // delay between each character during text display via segment led
#endif
//
#ifndef DWrite_WaitNextD
#define DWrite_WaitNextD NULL // mask (from display.gph) to display during wait time between characters, default NULL
#endif
// char -> bitmask mapping for output of names via the segment display
//
// Special Chars
//
// Numbers & Letters
// default to lowercase
// lowercase & uppercase (default)
#ifdef DWRITE_MC
#undef DWRITE_UC // just to avoid errors
uint8 DWriteCr[]={
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
_0_,_1_,_2_,_3_,_4_,_5_,_6_,_7_,_8_,_9_,
//10 , 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
_a_,_b_,_c_,_d_,_E_,_F_,_g_,_h_,_i_,_J_,_k_,_l_,_m_,_n_,_o_,_p_,_q_,_r_,_s_,_t_,_u_,_v_,_w_,_x_,_y_,_z_,
//36 , 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
_A_,_B_,_C_,_D_,_E_,_F_,_G_,_H_,_I_,_J_,_K_,_L_,_M_,_N_,_O_,_P_,_Q_,_R_,_S_,_T_,_U_,_V_,_W_,_X_,_Y_,_Z_,
};
#endif
//
// lowercase only
//
// uppercase only
#ifdef DWRITE_UC
uint8 DWriteCr[]={
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
_0_,_1_,_2_,_3_,_4_,_5_,_6_,_7_,_8_,_9_,
//10 , 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
_A_,_B_,_C_,_D_,_E_,_F_,_G_,_H_,_I_,_J_,_K_,_L_,_M_,_N_,_O_,_P_,_Q_,_R_,_S_,_T_,_U_,_V_,_W_,_X_,_Y_,_Z_,
};
#endif
// own control/helper flags/variables
//
bool DWrite_On; // state of text output
int8 DWrite_Idx; // the current active character beeing displayed
char *DWriteT; // the string to display
#if !defined(DWRITE_DI) || !defined(DWRITE_DF)
#define DWriteNum(a) DWriteInt(a) // backward compatibility
char DWriteN[13];// int32/fix32 convert to char for diplay output
uint8 DWiPos; // current position writing/pointing to
#endif
main {
if (DWrite_On) combo_run(cDisplayText); // write the text
}
#if !defined(DWRITE_DI) || !defined(DWRITE_DF)
// used by all number to text conversion
void DWriteNr(int32 Num, uint8 oPos) {
//printf("parameter Num: %ld",Num);
uint8 iDigits=1;
while(Num/pow(10,iDigits)) iDigits++;
uint8 iThis;
for (DWiPos=0;DWiPos<iDigits;DWiPos++) {
iThis=Num/pow(10,(iDigits-(DWiPos+1)));
Num=Num-iThis*pow(10,iDigits-DWiPos-1);
DWriteN[DWiPos+oPos]=iThis+48;
}
DWiPos+=oPos;
DWriteN[DWiPos]='\0';
}
bool DWriteNegative(int32 Num) {
if (Num<0) {
DWriteN[0]='-'; return TRUE;
}
return FALSE;
}
#endif
// int32 number to text conversion for output
#ifndef DWRITE_DI
void DWriteInt(int32 Num) {
DWriteNr(abs(Num),DWriteNegative(Num));
DWriteTxt(&DWriteN);
//printf(&DWriteN);
}
#endif
// fix32 to text conversion for output
#ifndef DWRITE_DF
void DWriteFix(fix32 Num,uint8 prec) {
//### first part before .
DWriteNr((int32)abs(Num),DWriteNegative((int32)Num)); //printf(&DWriteN);
DWriteN[DWiPos]='.'; //printf(&DWriteN);
DWiPos++; //printf("DWiPos: %d",DWiPos);
//### second part after .
Num=abs(Num);
Num=Num-floor(Num); //printf("rest: %f",Num);
// round to given precision
Num=round(Num*pow(10f,(fix32)clamp(prec,1,4))); //printf(". : %f",Num);
DWriteNr((int32)Num,DWiPos);
DWriteTxt(&DWriteN);
//printf(&DWriteN);
}
#endif
// start displaying text via segment display
void DWriteTxt(char *text) {
DWriteT=text;
//printf(text);
DWrite_On=FALSE; // stop first
combo_stop(cDisplayText);
combo_stop(cDWriteEnd);
DWrite_Idx=0; // reset to display first character
DWrite_On=TRUE; // start displaying
}
// display the text via segment display
combo cDisplayText {
DWriteWrite(DWriteT);
wait(0);
wait(DWrite_Wait);
display_overlay(DWrite_WaitNextD,DWrite_WaitNext);
wait(DWrite_WaitNext);
}
// write out all characters up to selected limit/condition
void DWriteWrite(char *text) {
int8 C=text[DWrite_Idx]; // get current char
uint8 Mask;
// convert to mask array position //ascii 0:48, A:65, a:97
// //index 0 10/36 10
// default
Mask=DWrite_Def;
// lowercase or uppercase
#if defined(DWRITE_LC) || defined(DWRITE_UC)
if (C >= 97) Mask=DWriteCr[C-87]; // a..z
else if (C >= 65) Mask=DWriteCr[C-55]; // uppercase to lowercase
else if (C >= 48) Mask=DWriteCr[C-48]; // 0..9
#endif
//
// lower and uppercase
#ifdef DWRITE_MC
if (C >= 97 && C < 123) Mask=DWriteCr[C-87]; // a..z
else if (C >= 65 && C < 91) Mask=DWriteCr[C-29]; // A..Z
else if (C >= 48 && C < 58 ) Mask=DWriteCr[C-48]; // 0..9
#endif
// space
else if (C == 32) Mask=DWrite_Ws;
// special chars if not disabled
#ifndef DWRITE_DS
else if (C >= 45 && C < 48) Mask=DWriteCrS[C-45]; // // -./_
#endif
//uint8 DWriteCrS[]={
// 0:- , 1: . , 2: / , 62, 63:_
// SEG_G,BOTTOM_DOT,SEG_B|SEG_G|SEG_E,NULL,SEG_D,
display_overlay(Mask,DWrite_Wait);
//display_overlay(DWriteCr[C],DWrite_Wait);
//printf("C: %d,char: %c %d",C,name[DisplayIdx],name[DisplayIdx]);
DWrite_Idx++;
//if ( DWrite_MaxWrite==1 && text[DWrite_Idx] == ' ' ) printf("space");
if (
(text[DWrite_Idx] == '\0') // always stop at end of string
|| (DWrite_MaxWrite==1 && text[DWrite_Idx] == ' ' ) // stop at first space
|| (DWrite_MaxWrite>=2 && DWrite_MaxWrite==DWrite_Idx ) // stop after showing selected amount of characters
) {
DWrite_On=FALSE; // end
combo_run(cDWriteEnd); // end wait
}
}
// extra pause when end is reached
combo cDWriteEnd {
wait(DWrite_Wait);
display_overlay(NULL,DWrite_Wait*2);
wait(0);
wait(DWrite_Wait);
}
#endif