void CalibrateScreen() {
const uint8_t NRbutts=5;
Button butt[NRbutts];
Button* BS[NRbutts];
for (uint8_t i=0; i<NRbutts; i++) BS[i]=&butt[i];
Fader fad[2];
Fader* FD[2];
for (uint8_t i=0; i<2; i++) FD[i]=&fad[i];
uint16_t CBx,CBy;
uint8_t pressed=NRbutts;
CBx=((TFT_X_RANGE-40)/2); // buttons 40x40
CBy=((TFT_Y_RANGE-40)/2);
butt[0] = {CBx,CBy,40,40,2,"OK",B3COL};
butt[1] = {CBx-42,CBy,40,40,2,"<-",B3COL};
butt[2] = {CBx+42,CBy,40,40,2,"->",B3COL};
butt[3] = {CBx-20,CBy-42,80,40,1,"Top",B3COL};
butt[4] = {CBx-20,CBy+42,80,40,1,"Bottom",B3COL};
fad[0] = {10,10,200,40,3,255,B1COL};
fad[1] = {30,80,100,40,1,200,B1COL};
DrawFader(&fad[1],20,B1COL);
delay(2000);
tft.setTextColor(TextColor);
/*while (true) {
DrawScreen (BS,NRbutts,"Calibrate","");
pressed=CheckButtonPressed(BS,NRbutts,true);
if (pressed==0) return;
else if (pressed==1) {
String str;
str=String("Current Left Margin is: ");
str=str+String(TS_LEFT);
char discrpt[str.length() + 1];
str.toCharArray(discrpt,str.length() + 1);
TS_LEFT=DecimalScreen("Set Left Margin",discrpt, B1COL);
}
else if (pressed==2) {
String str;
str=String("Current Right Margin is: ");
str=str+String(TS_RT);
char discrpt[str.length() + 1];
str.toCharArray(discrpt,str.length() + 1);
TS_RT=DecimalScreen("Set Right Margin",discrpt, B1COL);
}
else if (pressed==3) {
String str;
str=String("Current Top Margin is: ");
str=str+String(TS_TOP);
char discrpt[str.length() + 1];
str.toCharArray(discrpt,str.length() + 1);
TS_TOP=DecimalScreen("Set Top Margin",discrpt, B1COL);
}
else if (pressed==4) {
String str;
str=String("Current Bottom Margin is: ");
str=str+String(TS_BOT);
char discrpt[str.length() + 1];
str.toCharArray(discrpt,str.length() + 1);
TS_BOT=DecimalScreen("Set Bottom Margin",discrpt, B1COL);
}
}*/
}
void DrawScreen(Button * BS[],uint8_t NRbutts, char * cname,char * discrpt){
tft.fillScreen(BgColor);
tft.setTextSize(2);
tft.setCursor((TFT_X_RANGE/2) - strlen(cname)*6,10);
tft.print(cname);
tft.setTextSize(1);
tft.setCursor((TFT_X_RANGE/2) - strlen(discrpt)*3,35);
tft.print(discrpt);
for (uint8_t i=0; i<NRbutts; i++) DrawButton(&(*BS[i]));
}
void DrawButton (Button* B) {
tft.fillRect(B->x1,B->y1,B->sx,B->sy,B->color);
tft.drawRect(B->x1,B->y1,B->sx,B->sy,BLACK);
tft.drawRect(B->x1+2,B->y1+2,B->sx-4,B->sy-4,BLACK);
tft.setTextSize(B->tsize);
tft.setCursor(B->x1+(B->sx/2)-(strlen(B->cname)*3*B->tsize),B->y1+(B->sy/2)-(4*B->tsize));
tft.print(B->cname);
}
void DrawChannel(uint16_t channel, uint8_t fadnr, bool select) {
uint16_t color=CHANNEL;
if (select) color=CHSELCT;
uint16_t offset=40*fadnr;
tft.fillRect(79+offset,1,40,238,color);
tft.drawRect(80+offset,42,38,196,BLACK);
tft.drawLine(80+offset,218,116+offset,218,BLACK);
tft.drawLine(98+offset,42,98+offset,218,BLACK);
tft.drawLine(101+offset,42,101+offset,218,BLACK);
tft.drawRect(80+offset,2,38,38,BLACK); // draw special button
tft.drawRect(82+offset,4,34,34,BLACK);
tft.setTextSize(2);
tft.setCursor(88+offset,8);
tft.print("GO");
tft.setTextSize(1);
tft.setCursor(100+offset-HasDigits(dmx_master.getChannelValue(channel))*3,27);
tft.print(dmx_master.getChannelValue(channel), DEC);
tft.setCursor(101+offset-HasDigits(channel)*3,224);
tft.print(channel,DEC);
uint16_t faderlevel=((uint16_t) dmx_master.getChannelValue(channel)*166)/255;
tft.drawRect(84+offset,211-faderlevel,30,4,BLACK);
tft.drawRect(85+offset,212-faderlevel,28,2,RED);
}
void DrawFader(Fader * Fad, uint16_t level, uint16_t color) {
if (!color) color=Fad->color;
tft.fillRect(Fad->x1,Fad->y1,Fad->sx,Fad->sy,color);
tft.drawRect(Fad->x1,Fad->y1,Fad->sx,Fad->sy,BLACK);
uint16_t faderlevel;
if (Fad->orientation%2) { // horizontal
tft.drawLine(Fad->x1+0,Fad->y1+(Fad->sy/2)-2,Fad->x1+Fad->sx,Fad->y1+(Fad->sy/2)-2,BLACK);
tft.drawLine(Fad->x1, Fad->y1 + (Fad->sy/2)+1, Fad->x1+Fad->sx, Fad->y1+(Fad->sy/2)+1,BLACK);
faderlevel=(level*(Fad->sx-12))/Fad->range;
if (Fad->orientation/2) { // left to right
tft.drawRect(Fad->x1+5+faderlevel,Fad->y1+5,4,Fad->sy-10,BLACK);
tft.drawRect(Fad->x1+6+faderlevel,Fad->y1+6,2,Fad->sy-12,RED);
}
else { // right to left
tft.drawRect(Fad->x1 + Fad->sx -faderlevel - 12,Fad->y1 + 5, 4, Fad->sy - 10,BLACK);
tft.drawRect(Fad->x1+Fad->sx-faderlevel-11,Fad->y1+6,2,Fad->sy-12,RED);
}
}
else { // vertical
tft.drawLine(Fad->x1+(Fad->sx/2)-2,Fad->y1,Fad->x1+(Fad->sx/2)-2,Fad->y1+Fad->sy,BLACK);
tft.drawLine(Fad->x1+(Fad->sx/2)+1,Fad->y1,Fad->x1+(Fad->sx/2)+1,Fad->y1+Fad->sy,BLACK);
faderlevel=(level*(Fad->sy-12))/Fad->range;
if (Fad->orientation/2) { // bottom to top
tft.drawRect(Fad->x1+5,Fad->y1+Fad->sy-faderlevel-12,Fad->sx-10,4,BLACK);
tft.drawRect(Fad->x1+6,Fad->y1+Fad->sy-faderlevel-11,Fad->sx-12,2,RED);
}
else { // Top to bottom
tft.drawRect(Fad->x1+5,Fad->y1+5+faderlevel,Fad->sx-10,4,BLACK);
tft.drawRect(Fad->x1+6,Fad->y1+6+faderlevel,Fad->sx-12,2,RED);
}
}
}
void ChannelAdjustFader() { // still needs to be made universal
int16_t tftx,tfty;
tftx = CalcTftx(tp.x);
uint8_t selectedCH=(tftx-79)/40; // that should give us the fadernr (0-6)
tfty = CalcTfty(tp.y);
uint8_t newvalue=RangeValueFader(212-tfty,166,255);
if ((selectedCH+firstSC) != selchannel) { // if it is not the current highlighted one
if (firstSC<=selchannel && (firstSC+5)>=selchannel) { // but the highlighted was on screen
DrawChannel(selchannel,selchannel-firstSC,false); // we need to draw it not highlighted
}
dmx_master.setChannelValue(firstSC+selectedCH,newvalue); // assign newvalue to the dmxbuffer
DrawChannel(firstSC+selectedCH,selectedCH, true); // draw the selected one highlighted
selchannel=selectedCH+firstSC; // set it as the new selected channel
}
else ChannelMoveFader(newvalue,selectedCH); // we only draw it the first time if we haven't redrawn the channel.
while (!ConfirmRelease()) {
tfty = CalcTfty(tp.y);
newvalue=RangeValueFader(212-tfty,166,255);
ChannelMoveFader(newvalue,selectedCH);
}
}
uint16_t AdjustFader(Fader* Fad, uint16_t currentvalue, uint16_t color=0x0) {
if (!color) color=Fad->color;
uint16_t newvalue;
newvalue=CalculateFaderValue(Fad);
MoveFader(Fad,currentvalue,newvalue,color);
currentvalue=newvalue;
while (!ConfirmRelease()) {
newvalue=CalculateFaderValue(Fad);
MoveFader(Fad,currentvalue,newvalue,color);
currentvalue=newvalue;
}
return currentvalue;
}