// 16 bit color code: red -> 5 bit, green -> 6 bit, blue -> 5 bit
#define TOP_BACKGROUND() lcd_set_background(0x03,0x04,0x05)
#define BOTTOM_BACKGROUND() lcd_set_background(0x00,0x00,0x00)
-#define FIRST_VALUE_FOREGROUND() lcd_set_foreground(0x1f,0x3f,0x0e);lcd_set_background(0x03,0x04,0x05)
-#define SECOND_VALUE_FOREGROUND() lcd_set_foreground(0x0e,0x2e,0x1f);lcd_set_background(0x03,0x04,0x05)
-#define THIRD_VALUE_FOREGROUND() lcd_set_foreground(31, 63/2 ,31/2);lcd_set_background(0x03,0x04,0x05)
+#define FIRST_VALUE_FOREGROUND() lcd_set_color(&foreground,0x1f,0x3f,0x0e)
+#define SECOND_VALUE_FOREGROUND() lcd_set_color(&foreground,0x0e,0x2e,0x1f)
+#define THIRD_VALUE_FOREGROUND() lcd_set_color(&foreground,31, 63/2 ,31/2)
#define FIRST_VALUE_BACKGROUND() lcd_set_background(0x1f,0x3f,0x0e)
#define SECOND_VALUE_BACKGROUND() lcd_set_background(0x0e,0x2e,0x1f)
-#define AXES_COLOR() lcd_set_foreground(0x1f,0x3f,0x1f);
+#define AXES_COLOR() lcd_set_color(&foreground,0x1f,0x3f,0x1f)
+#define MAINSENSOR 1
+#define SUPPSENSOR 0
+
#define BUFFERSIZE 16
#define STORAGESIZE 300
const uint8_t lut[16] = {0,1,1,2,3,3,4,4,5,5,6,7,7,8,9,9};
uint8_t buffer[BUFFERSIZE];
uint8_t recvpointer = 0;
int16_t values[2][STORAGESIZE];
-uint16_t valuepointer[2] = {0};
-int16_t lastvalues[2] = {0,0};
+uint16_t valuepointer[4] = {0};
+int16_t lastvalues[4] = {0,0};
volatile uint8_t second, lastsecond;
uint8_t ids[NUMSENSORS][8];
-uint16_t temps[NUMSENSORS] = {-255};
+int16_t temps[NUMSENSORS] = {-255};
int16_t set_value = 12*16;
uint8_t output_power_percent = 0;
+color_t colors[4];
+color_t topback;
volatile uint8_t keys_pressed = 0b00000000;
#define MINY 100
#define MAXY 220
void draw(void) {
- uint16_t c = MINX;
- uint16_t p = valuepointer[0];
- FIRST_VALUE_FOREGROUND();
- lcd_set_background(0x00,0x00,0x00);
lcd_set_page(0,239);
lcd_set_column(0,319);
+ lcd_set_background(0x00,0x00,0x00);
+ uint16_t c = MINX;
+ uint16_t p = valuepointer[0];
do{
- uint16_t y = values[0][p];
- y = y*3;
- y >>= 4;
- y = 190-y;
- lcd_set_pixel_col_xy(c+1,y,background);
- lcd_set_pixel_col_xy(c+1,y+1,background);
- lcd_set_pixel_col_xy(c,y,foreground);
- lcd_set_pixel_col_xy(c,y+1,foreground);
+ for(uint8_t i = 0; i<=1; i++) {
+ if(i) SECOND_VALUE_FOREGROUND();
+ else FIRST_VALUE_FOREGROUND();
+ uint16_t y = values[i][p];
+ y = y*3;
+ y >>= 4;
+ y = 190-y;
+ lcd_set_pixel_col_xy(c+1,y,background);
+ lcd_set_pixel_col_xy(c+1,y+1,background);
+ lcd_set_pixel_col_xy(c,y,foreground);
+ lcd_set_pixel_col_xy(c,y+1,foreground);
+ }
p++;
if(p>= STORAGESIZE) p = 0;
}while(++c<MAXX);
x = t >> 4;
lcd_set_font(FONT_DIGITS_32,SPACING);
- TOP_BACKGROUND();
-
- if(place == 0) {
- FIRST_VALUE_FOREGROUND();
- if(lastvalues[place]<=-160) {
- if(val >-160)
- lcd_set_area_xy(190,210,23,28);
- }
- else if (lastvalues[place]<0) {
- if(val>0)
- lcd_set_area_xy(220,240,23,28);
- }
-
- if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=160))
- lcd_set_area_xy(210,246,8,39);
-
- FIRST_VALUE_BACKGROUND();
- if(neg) {
- if(x>=10 && lastvalues[place]>-160)
- lcd_set_area_xy(190,210,23,28);
- else if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=0))
- lcd_set_area_xy(220,240,23,28);
- }
- if(x>=10) lcd_moveto_xy(8,220);
- else lcd_moveto_xy(8,249);
+ lcd_use_background(topback);
+
+ uint16_t left = 0;
+ uint16_t top = 0;
+ if (place == 0) {left = 190; top = 8; }
+ else if(place == 1) {left = 190; top = 48; }
+ else if(place == 2) {left = 33; top = 48; }
+ else if(place == 3) {left = 33; top = 8; }
+
+ lcd_use_foreground(colors[place]);
+ if(lastvalues[place]<=-160) {
+ if(val >-160)
+ lcd_set_area_xy(left,left+20,top+15,top+20);
}
- else {
- SECOND_VALUE_FOREGROUND();
- lcd_set_area_xy(190,210,63,68);
- lcd_set_area_xy(210,246,48,79);
-
- SECOND_VALUE_BACKGROUND();
- if(neg) {
- if(x>=10) lcd_set_area_xy(190,210,63,68);
- else lcd_set_area_xy(220,240,63,68);
- }
- if(x>=10) lcd_moveto_xy(48,220);
- else lcd_moveto_xy(48,249);
+ else if (lastvalues[place]<0) {
+ if(val>0)
+ lcd_set_area_xy(left+30,left+50,top+15,top+20);
}
-
- TOP_BACKGROUND();
+
+ if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=160))
+ lcd_set_area_xy(left+20,left+56,top,top+31);
+
+ lcd_use_background(colors[place]);
+ if(neg) {
+ if(x>=10 && lastvalues[place]>-160)
+ lcd_set_area_xy(left,left+20,top+15,top+20);
+ else if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=0))
+ lcd_set_area_xy(left+30,left+50,top+15,top+20);
+ }
+ if(x>=10) lcd_moveto_xy(top,left+30);
+ else lcd_moveto_xy(top,left+59);
+
+ lcd_use_background(topback);
lcd_put_int(x);
- if(!place)lcd_moveto_xy(8,289);
- else lcd_moveto_xy(48,289);
+ lcd_moveto_xy(top,left+99);
lcd_putc(lut[y]+'0');
lastvalues[place] = val;
AXES_COLOR();
BOTTOM_BACKGROUND();
lcd_set_area_xy(20,319,100,220);
- TOP_BACKGROUND();
+ lcd_use_background(topback);
lcd_set_font(FONT_PROP_16,NORMAL);
lcd_putstr_xy_P(PSTR("-10"),216,0);
lcd_putstr_xy_P(PSTR(" 30"),96,0);
lcd_putstr_xy_P(PSTR("minutes"),228,150);
lcd_putstr_xy_P(PSTR("T"),160,10);
- FIRST_VALUE_FOREGROUND();
+ lcd_use_foreground(colors[0]);
lcd_set_font(FONT_PROP_16,NORMAL);
lcd_putstr_xy_P(PSTR("is"),8,190);
lcd_set_font(FONT_DIGITS_32,SPACING);
lcd_moveto_xy(8,278);
lcd_putc('.');
- SECOND_VALUE_FOREGROUND();
- lcd_set_font(FONT_PROP_16,NORMAL);
- lcd_putstr_xy_P(PSTR("set"),48,190);
+
+ lcd_use_foreground(colors[1]);
lcd_set_font(FONT_DIGITS_32,SPACING);
lcd_moveto_xy(48,278);
lcd_putc('.');
+ lcd_use_foreground(colors[2]);
+ lcd_set_font(FONT_PROP_16,NORMAL);
+ lcd_putstr_xy_P(PSTR("power"),48,20);
+ lcd_set_font(FONT_PROP_16,DOUBLE_SIZE|SPACING);
+ lcd_putstr_xy_P(PSTR("%"),54,150);
+
+ lcd_use_foreground(colors[3]);
+ lcd_set_font(FONT_PROP_16,NORMAL);
+ lcd_putstr_xy_P(PSTR("set"),8,33);
+ lcd_set_font(FONT_DIGITS_32,SPACING);
+ lcd_moveto_xy(8,121);
+ lcd_putc('.');
+
}
value = MAX(value,SET_VAL_LOWER);
value = MIN(value,SET_VAL_UPPER);
set_value = value;
- showTemp(1,set_value);
+ showTemp(3,set_value);
}
// all constants in x/10
void showPower(void){
#define POWER_XPOS 62
#define POWER_YPOS 48
-
+ TOP_BACKGROUND();
THIRD_VALUE_FOREGROUND();
if(output_power_percent <10){
lcd_set_area_xy(POWER_XPOS,POWER_XPOS+29*2,POWER_YPOS,POWER_YPOS+32);
uart_puts(" deg C\n\r");
uart_puts("Temperature: ");
- uart_print_sign(temps[0]);
- uart_print_number(abs(temps[0])/16,2);
+ uart_print_sign(temps[MAINSENSOR]);
+ uart_print_number(abs(temps[MAINSENSOR])/16,2);
usb_serial_putchar('.');
- usb_serial_putchar('0'+lut[abs(temps[0])%16]); // print post comma
+ usb_serial_putchar('0'+lut[abs(temps[MAINSENSOR])%16]); // print post comma
uart_puts(" deg C\n\r");
-
+
+ uart_puts("2nd temp: ");
+ uart_print_sign(temps[SUPPSENSOR]);
+ uart_print_number(abs(temps[SUPPSENSOR])/16,2);
+ usb_serial_putchar('.');
+ usb_serial_putchar('0'+lut[abs(temps[SUPPSENSOR])%16]); // print post comma
+ uart_puts(" deg C\n\r");
+
uart_puts("PWM Output: ");
uart_print_number(output_power_percent,3);
uart_puts("%\n\r");
keys_init();
PWM_init();
+ lcd_set_color(colors+0,0x1f,0x3f,0x0e);
+ lcd_set_color(colors+1,0x1f,0x3f,0x0e);
+ lcd_set_color(colors+2,0x1f,0x1f,0x0f);
+ lcd_set_color(colors+3,0x0e,0x2e,0x1f);
+ lcd_set_color(&topback,0x03,0x04,0x05);
+
lcd_command_1(LCD_MIRROR, LCD_BGR | LCD_FLIP_XY);
lcd_command(LCD_ON);
- TOP_BACKGROUND();
+ lcd_use_background(topback);
lcd_set_area_xy(0, 0x13F, 0, 0xEF);
- lcd_set_foreground(0x1f,0x3f,0x1f);
- lcd_set_font(FONT_PROP_16,DOUBLE_HEIGHT|SPACING);
- lcd_putstr_xy_P(PSTR("Cooling Control"),10,30);
printAxes();
+
+ new_set_value(12*16);
- THIRD_VALUE_FOREGROUND();
- lcd_set_font(FONT_PROP_16,NORMAL);
- lcd_putstr_xy_P(PSTR("power"),48,20);
- lcd_set_font(FONT_PROP_16,DOUBLE_SIZE|SPACING);
- lcd_putstr_xy_P(PSTR("%"),54,150);
-
-
-
- pushvalue(1,set_value);
-
while (1) {
int n = usb_serial_getchar();
usb_serial_putchar(0x10);
read_meas();
start_meas();
- pushvalue(0,temps[0]);
+ pushvalue(0,temps[MAINSENSOR]);
+ pushvalue(1,temps[SUPPSENSOR]);
lastsecond = second;
- if(temps[0] > 30*16){ // turn off peltier if temperature is off limits (>30 deg C)
+ if(temps[MAINSENSOR] > 30*16){ // turn off peltier if temperature is off limits (>30 deg C)
set_PWM_output(0);
output_power_percent = 0;
} else {
- uint16_t pid_output = pid_calculation( temps[0] - set_value );
+ uint16_t pid_output = pid_calculation( temps[MAINSENSOR] - set_value );
set_PWM_output(pid_output); // let PID compute output
output_power_percent = MIN(100,pid_output/10); // output power in percent (ignore the last 23 from 1023)
}