First release

This commit is contained in:
mr grouch 2018-04-19 21:31:31 +02:00
parent 24e5d2a74d
commit 0d250d4595
2 changed files with 59 additions and 71 deletions

0
logo.bmp Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -5,41 +5,36 @@
// CONSTANTES
//----------------------------------------------------------------------------------
#define VERSION "20180415"
#define VERSION "20180419"
#define MAX6675_CS0 13
#define MAX6675_CS1 12
#define MAX6675_CS2 3
#define MAX6675_CS3 2
#define MAX6675_SO 1
#define MAX6675_CS2 3
#define MAX6675_CS3 2
#define MAX6675_SO 1
#define MAX6675_SCK 19
#define POTAR_PIN A7
#define POTAR_PIN A7
#define LEN_PLOT 100
#define LEN_PLOT 100
const byte X0Graph = 92;
const byte X0Graph = 92;
const int T_REFRESH = 500;
const int T_SWITCH = 100;
const int T_SWITCH = 100;
//----------------------------------------------------------------------------------
// CLASSE PLOT
//----------------------------------------------------------------------------------
class Plot{
int y[LEN_PLOT];
int y[LEN_PLOT]; // Tableau des valeurs stockées
public :
int y_min;
int y_max;
int y_min; // Min et max
int y_max; // (après avoir lancé AutoScale)
Plot(){
}
void SetScale (int mini, int maxi){
y_min = mini;
y_max = maxi;
}
void AutoScale(){
int mini = 1024;
int maxi = 0;
@ -62,20 +57,19 @@ class Plot{
y_max = min(1024, y_max); // on borne à la valeur max du MAX6675
}
void Push(int val){
for (int i = 0 ; i<LEN_PLOT ; i++){
void Push(int val){ // Stocke la nouvelle valeur en les décalant toutes
for (int i = 0 ; i<LEN_PLOT ; i++){ // On décale tout
y[i] = y[i+1];
}
y[LEN_PLOT-1] = val;
y[LEN_PLOT-1] = val; // Et on ajoute la nouvelle valeur
}
void Trace(byte x0, byte x1, byte y0, byte y1){
GLCD.SetPixels(x0, y1, x1, y0, PIXEL_OFF);
for (int i = 0 ; i<LEN_PLOT ; i++){
//int u = map(i, 0, LEN_PLOT, x0, x1);
int u = i+X0Graph;
int v = map(y[i], y_min, y_max, y0 , y1) ;
GLCD.SetDot(u ,v ,PIXEL_ON);
int u = map(i, 0, LEN_PLOT, x0, x1);
int v = map(y[i], y_min, y_max, y0 , y1) ;
GLCD.SetDot(u ,v ,PIXEL_ON); // On trace les pts du graphe
}
}
};
@ -84,48 +78,37 @@ class Plot{
// VARIABLES
//----------------------------------------------------------------------------------
gText t[4];
gText curseur[4];
gText y[3];
gText t[4]; // Affichage des 4 températures
gText curseur; // Curseur graphe courant
gText y[3]; // Etiquettes graphe
Plot p[4];
Plot p[4]; // 4 graphes de température
unsigned long pm_switch;
unsigned long pm_refresh;
byte plot_index = 0;
unsigned long pm_switch; // Previous millis switch entre graphes
unsigned long pm_refresh; // Previous millis refresh lecture TCs
byte plot_index = 0; // Graphe courant
//----------------------------------------------------------------------------------
// CODE
//----------------------------------------------------------------------------------
double readTC(byte CSpin) {
double readTC(byte CSpin) { // Lecture MAX6675
uint16_t v;
digitalWrite(CSpin, LOW);
delay(1);
v = shiftIn(MAX6675_SO, MAX6675_SCK, MSBFIRST);
v <<= 8;
v |= shiftIn(MAX6675_SO, MAX6675_SCK, MSBFIRST);
digitalWrite(CSpin, HIGH);
if (v & 0x4) {return NAN;} // Bit 2 indicates if the TC is disconnected
if (v & 0x4) {return NAN;} // Bit 2 = TC déconnecté
v >>= 3; // The lower three bits (0,1,2) are discarded status bits
return v*0.25; // The remaining bits are the number of 0.25°C counts
v >>= 3; // 3 bits status --> on jette
return v*0.25; // Le reste est le nb de 0.25°C
}
void setup() {
pinMode(MAX6675_CS0, OUTPUT);
pinMode(MAX6675_CS1, OUTPUT);
pinMode(MAX6675_CS2, OUTPUT);
pinMode(MAX6675_CS3, OUTPUT);
pinMode(MAX6675_SO, INPUT);
pinMode(MAX6675_SCK, OUTPUT);
GLCD.Init();
void display_logo(){ // Affichage logo, titre et version
GLCD.DrawBitmap(logo, 15,7);
gText titre;
titre.DefineArea(100,10,15,1,cp437font8x8);
titre.Printf("quadTC");
@ -135,16 +118,30 @@ void setup() {
titre.Printf("Tooling Co.");
titre.DefineArea(158,57,30,1,Wendy3x5);
titre.Printf(VERSION);
}
void setup() {
pinMode(MAX6675_CS0, OUTPUT);
pinMode(MAX6675_CS1, OUTPUT);
pinMode(MAX6675_CS2, OUTPUT);
pinMode(MAX6675_CS3, OUTPUT);
pinMode(MAX6675_SO, INPUT);
pinMode(MAX6675_SCK, OUTPUT);
GLCD.Init();
display_logo();
readTC(MAX6675_CS0);
readTC(MAX6675_CS1);
readTC(MAX6675_CS2);
readTC(MAX6675_CS3);
delay(2000);
GLCD.ClearScreen();
curseur[0].DefineArea(55,3,1,1,cp437font8x8);
curseur[0].Printf("<");
GLCD.DrawVLine(X0Graph-1,0,64);
GLCD.DrawVLine(X0Graph-1,0,64); // Lignes axe Y du graphe
GLCD.DrawHLine(X0Graph-2,0,3);
GLCD.DrawHLine(X0Graph-2,32,3);
GLCD.DrawHLine(X0Graph-2,63,3);
}
void loop() {
@ -154,11 +151,11 @@ void loop() {
t[0].DefineArea(2, 3,6,1,cp437font8x8);
t[1].DefineArea(2,20,6,1,cp437font8x8);
t[2].DefineArea(2,37,6,1,cp437font8x8);
t[3].DefineArea(2,53,6,1,cp437font8x8);
t[3].DefineArea(2,54,6,1,cp437font8x8);
int tc = readTC(MAX6675_CS0); // Lecture TC
t[0].Printf("A %4d",tc); // Affichage valeur
p[0].Push(tc); // Stockage valeur pour graphe
int tc = readTC(MAX6675_CS0); // Lecture TC
t[0].Printf("A %4d",tc); // Affichage valeur
p[0].Push(tc); // Stockage valeur pour graphe
tc = readTC(MAX6675_CS1);
t[1].Printf("B %4d",tc);
@ -172,11 +169,11 @@ void loop() {
t[3].Printf("D %4d",tc);
p[3].Push(tc);
y[0].DefineArea(73, 1,4,1,Wendy3x5); // PM plantage avr-gcc si pas fait à chaque loop !?§
y[0].DefineArea(73, 1,4,1,Wendy3x5); // PM plantage avr-gcc si pas fait à chaque loop !?§
y[1].DefineArea(73,58,4,1,Wendy3x5);
y[2].DefineArea(73,30,4,1,Wendy3x5);
y[0].Printf("%4d",p[plot_index].y_max);
y[0].Printf("%4d",p[plot_index].y_max); // Etiquettes de l'axe Y
y[1].Printf("%4d",p[plot_index].y_min);
y[2].Printf("%4d",(p[plot_index].y_min+p[plot_index].y_max)/2);
@ -185,20 +182,11 @@ void loop() {
pm_refresh = cm;
}
if ((cm - pm_switch) > T_SWITCH){
//plot_index++;
//if (plot_index>3){plot_index=0;}
plot_index = map(analogRead(POTAR_PIN)+50, 0, 1023, 0, 3);
//y[2].Printf("%4d",analogRead(POTAR_PIN));
curseur[0].DefineArea(55,3,1,1,cp437font8x8);
curseur[1].DefineArea(55,20,1,1,cp437font8x8);
curseur[2].DefineArea(55,37,1,1,cp437font8x8);
curseur[3].DefineArea(55,53,1,1,cp437font8x8);
for (byte i=0; i<4;i++){
if (i != plot_index){curseur[i].ClearArea();}}
curseur[plot_index].Printf("<");
if ((cm - pm_switch) > T_SWITCH){ // Lect. potar sélection graphe et affich. curseur
plot_index = map(analogRead(POTAR_PIN)+200, 0, 1023, 0, 3);
curseur.Printf(" "); // On efface le curseur courant
curseur.DefineArea(55,(3+17*plot_index),1,1,cp437font8x8);
curseur.Printf("<"); // Et on affiche le nouveau
pm_switch = cm;
}
}