feature-complete replacement for BASIC control software...w00t!
git-svn-id: https://svn.salfter.gotdns.org/svn/a2bfc/trunk@92 1b90f75b-8b96-4784-87c0-14078182fce6
This commit is contained in:
83
main.c
83
main.c
@@ -3,6 +3,9 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <peekpoke.h>
|
||||
#include <modload.h>
|
||||
#include <tgi.h>
|
||||
#include <stdlib.h>
|
||||
#include "ow.h"
|
||||
#include "ow-temp.h"
|
||||
#include "ow-time.h"
|
||||
@@ -11,6 +14,7 @@
|
||||
COMP_STATUS compressor_status;
|
||||
unsigned char* tempsensor=NULL;
|
||||
unsigned char* clockdev=NULL;
|
||||
unsigned char tempsamples[280];
|
||||
|
||||
int main (void)
|
||||
{
|
||||
@@ -24,6 +28,17 @@ int main (void)
|
||||
time_t shutoff=0;
|
||||
unsigned char cmd;
|
||||
time_t gototime=0;
|
||||
time_t lastupdate=0;
|
||||
|
||||
for (i=0; i<280; i++)
|
||||
tempsamples[i]=70;
|
||||
|
||||
tgi_load(TGI_MODE_280_192_6);
|
||||
if (tgi_geterror()!=TGI_ERR_OK)
|
||||
{
|
||||
printf("tgi_load() failed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
devcount=ow_enumeratedevices(devs, 10);
|
||||
|
||||
@@ -59,17 +74,24 @@ int main (void)
|
||||
clrscr();
|
||||
}
|
||||
|
||||
tgi_init(); // turn on Hi-Res mode
|
||||
POKE(-16301,0); // make it split-screen
|
||||
drawgraph(70);
|
||||
if (tgi_geterror()!=TGI_ERR_OK)
|
||||
{
|
||||
printf("tgi_init() failed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
relayctrl(0);
|
||||
gotoxy(25,0);
|
||||
gotoxy(25,20);
|
||||
printf("off ");
|
||||
gotoxy(0,2);
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
t=ow_time_read(clockdev);
|
||||
currtemp=ow_temp_read(tempsensor, OW_TEMP_FAHRENHEIT);
|
||||
gotoxy(0,0);
|
||||
gotoxy(0,20);
|
||||
printf("curr=%i set=%i goto=%i \n",
|
||||
currtemp,
|
||||
setpoint,
|
||||
@@ -83,30 +105,35 @@ int main (void)
|
||||
intime.tm_min,
|
||||
intime.tm_sec);
|
||||
printf(" \n");
|
||||
if (t>lastupdate+60)
|
||||
{
|
||||
lastupdate=t;
|
||||
drawgraph(currtemp);
|
||||
}
|
||||
gotoy(wherey()-1);
|
||||
if (currtemp>=setpoint+2 && compressor_status==COMP_OFF)
|
||||
{
|
||||
if (t-shutoff>300)
|
||||
{
|
||||
relayctrl(1);
|
||||
gotoxy(25,0);
|
||||
gotoxy(25,20);
|
||||
printf("on ");
|
||||
gotoxy(0,2);
|
||||
gotoxy(0,22);
|
||||
}
|
||||
else
|
||||
{
|
||||
gotoxy(25,0);
|
||||
gotoxy(25,20);
|
||||
printf("wait");
|
||||
gotoxy(0,2);
|
||||
gotoxy(0,22);
|
||||
}
|
||||
}
|
||||
if (currtemp<=setpoint-2 && compressor_status==COMP_ON)
|
||||
{
|
||||
relayctrl(0);
|
||||
shutoff=t;
|
||||
gotoxy(25,0);
|
||||
gotoxy(25,20);
|
||||
printf("off ");
|
||||
gotoxy(0,2);
|
||||
gotoxy(0,22);
|
||||
}
|
||||
if (t>=gototime && gotopoint!=setpoint)
|
||||
{
|
||||
@@ -244,3 +271,41 @@ void relayctrl(unsigned char on)
|
||||
compressor_status=(on)?COMP_ON:COMP_OFF;
|
||||
return;
|
||||
}
|
||||
|
||||
void drawgraph(unsigned char newsample)
|
||||
{
|
||||
unsigned int x, y;
|
||||
char mkr[3]="00";
|
||||
|
||||
tgi_setcolor(0);
|
||||
tgi_setpixel(0,yscale(tempsamples[0]));
|
||||
tgi_gotoxy(0,yscale(tempsamples[0]));
|
||||
for (x=1; x<280; x++)
|
||||
{
|
||||
tgi_lineto(x,yscale(tempsamples[x]));
|
||||
tempsamples[x-1]=tempsamples[x];
|
||||
}
|
||||
tempsamples[279]=newsample;
|
||||
for (y=30; y<=90; y+=10)
|
||||
{
|
||||
tgi_setcolor(1);
|
||||
tgi_line(14,yscale(y),279,yscale(y));
|
||||
tgi_setcolor(3);
|
||||
mkr[0]=48+(y/10);
|
||||
tgi_outtextxy(0,yscale(y)-4,mkr);
|
||||
}
|
||||
tgi_setpixel(0,yscale(tempsamples[0]));
|
||||
tgi_gotoxy(0,yscale(tempsamples[0]));
|
||||
for (x=1; x<280; x++)
|
||||
tgi_lineto(x,yscale(tempsamples[x]));
|
||||
}
|
||||
|
||||
int yscale(int y)
|
||||
{
|
||||
if (y>90) // clamp to within range
|
||||
y=90;
|
||||
if (y<30)
|
||||
y=30;
|
||||
return 5+(90-y)*5/2;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user