I got two of the displays working, thanks for the great object.
In order to organize my patch, I want to dynamically switch the data sent to the display depending on the context. My object only has one string output per display line.
I made a function in my sub patch in the "local data" tab, copied from "f_c", and I added the local data and init calls as well.
char* f_c(float i, char* prefix) {
char c[7+strlen(prefix)];
char *p=c+strlen(prefix);
strcpy(&c[0],prefix);
float f = i * (1.0f/(1<<21));
if(i > 0) p[0] = '+';
else if(i < 0) {p[0] = '-'; f = -f; }
else p[0] = ' ';
if(f >= 1000){
p[1]=127;p[2]=127;p[3]=0;
} else {
{
int cent=(int)(f/100);
if(cent == 0) p[1]=' '; else p[1]='0' + cent;
f -= cent * 100;
}
{
int diz=(int)(f/10);
if(diz == 0) p[2] = ' '; else p[2]='0' + diz;
f -= diz * 10;
}
{
int un = (int)(f);
p[3] = '0' + un;
f -= un * 1;
p[4] = '.';
}
{
int diz = (int)(f*10);
p[5] = '0'+diz;
f -= diz * 10;
}
p[6]=0;
}
return c;
}
If I call it from my k-rate code, the prefix string is displayed, the float is not. I don't understand why.
I tried both strbar and bar mode in the same manner. I get similar results (no bar basically)
I set the c[0] byte according to the mode. they are displayed as "U"
char* stringbar(int i, char* prefix) {
char c[2 + strlen(prefix)];
strcpy(&c[2], prefix);
c[0] = 0; //string bar mode
int32_t v = __SSAT(i,28)>>21;
if(v >= 0)
c[1] = (uint8_t)(v + 1); // must not be zero !
else
c[1] = (uint8_t)(256 + v);
return c;
}
char* barmode(int i){
char c[3];
c[0] = 2; //bar mode
c[2] = '\0';
int32_t v = i >>20;
if(v >= 0)
if(v > 127)
c[1] = 128;
else
c[1] = (uint8_t)(v + 1); //[1 128]
else
if(v < -127)
c[1] = 129;
else
c[1] = (uint8_t)(256 + v); //[255 128]
return c;
}
Obviously I'm missing something here, but I do not get it...