minimal fridge-controller functionality implemented (though it protects the compressor better than the BASIC program does)

git-svn-id: https://svn.salfter.gotdns.org/svn/a2bfc/trunk@90 1b90f75b-8b96-4784-87c0-14078182fce6
This commit is contained in:
(no author)
2007-09-24 08:17:47 +00:00
parent d8a3fd2194
commit 7a20ce6e2b
2 changed files with 167 additions and 20 deletions

177
main.c
View File

@@ -1,9 +1,12 @@
#include <stdio.h>
#include <conio.h>
#include <errno.h>
#include <string.h>
#include <peekpoke.h>
#include "ow.h"
#include "ow-temp.h"
#include "ow-time.h"
#include <errno.h>
#include "main.h"
int main (void)
{
@@ -12,20 +15,16 @@ int main (void)
unsigned char* tempsensor=NULL;
unsigned char* clock=NULL;
time_t t;
// unsigned char c1, c2;
struct tm intime;
unsigned char setpoint=70;
unsigned char gotopoint=70;
unsigned char currtemp;
time_t shutoff=0;
unsigned char cmd;
time_t gototime=0;
devcount=ow_enumeratedevices(devs, 10);
/*//
for (c1=0; c1<devcount; c1++)
{
printf("%i: ", c1);
for (c2=0; c2<8; c2++)
printf("%02X ", devs[(c1<<3)+c2]);
printf("\n");
}
//*/
for (i=0; i<devcount; i++)
{
if (ow_temp_idcheck(&devs[i<<3]))
@@ -39,22 +38,160 @@ int main (void)
return -1;
}
ow_time_set(clock, 1190611728-28800);
clrscr();
printf("Set clock? ");
if (readYN())
{
bzero(&intime, sizeof(intime));
printf("Year? ");
intime.tm_year=readnum()-1900;
printf("Month? ");
intime.tm_mon=readnum()-1;
printf("Day? ");
intime.tm_mday=readnum();
printf("Hour? ");
intime.tm_hour=readnum();
printf("Minute? ");
intime.tm_min=readnum();
ow_time_set(clock, mktime(&intime));
}
do
{
do
{
for (i=0; i<250; i++)
ow_mswait();
// for (i=0; i<250; i++)
// ow_mswait();
t=ow_time_read(clock);
printf("%i deg F %s",
ow_temp_read(tempsensor, OW_TEMP_FAHRENHEIT),
asctime(localtime(&t)));
currtemp=ow_temp_read(tempsensor, OW_TEMP_FAHRENHEIT);
gotoxy(0,0);
printf("curr=%i set=%i goto=%i \n",
currtemp,
setpoint,
gotopoint);
printf("%s", asctime(localtime(&t)));
printf(" \n");
gotoy(wherey()-1);
if (currtemp>=setpoint+2)
{
if (t-shutoff>300)
{
relayctrl(1);
gotoxy(25,0);
printf(" ");
gotoxy(0,2);
}
else
{
gotoxy(25,0);
printf("wait");
gotoxy(0,2);
}
}
if (currtemp<=setpoint-2)
{
relayctrl(0);
shutoff=t;
}
if (t>=gototime && gotopoint!=setpoint)
{
if (gotopoint>setpoint)
setpoint++;
else
setpoint--;
gototime=t+3600;
}
}
while (!kbhit());
cmd=cgetc();
if (cmd>96)
cmd=cmd-32;
if (cmd=='S')
{
printf("Set point? ");
gotopoint=setpoint=readnum();
}
if (cmd=='G')
{
printf("Go-to point? ");
gotopoint=readnum();
gototime=t+3600;
}
}
while (cgetc()!=3);
while (cmd!=3);
return 0;
}
int readYN()
{
unsigned char c;
cputc('_');
do
{
c=cgetc();
if (c>96)
c=c-32;
}
while (c!='Y' && c!='N');
backup();
cputc(c);
cputc(13);
cputc(10);
return (c=='Y')?1:0;
}
int readnum()
{
unsigned char c[8];
unsigned char p=0;
int r=0;
unsigned char i;
bzero(c, sizeof(c));
do
{
cputc('_');
c[p]=cgetc();
backup();
if (c[p]==8 || c[p]==127)
{
if (p>0)
{
p--;
backup();
}
}
else
if ((c[p]>='0' && c[p]<='9') || c[p]=='-')
{
if (p<6)
cputc(c[p++]);
}
}
while (c[p]!=13);
cputc(13);
cputc(10);
for (i=0; i<p; i++)
if (c[i]!='-')
r=(r*10)+(c[i]-48);
if (c[0]=='-')
r=-r;
return r;
}
void backup()
{
gotox(wherex()-1);
cputc(' ');
gotox(wherex()-1);
return;
}
void relayctrl(unsigned char on)
{
signed int addr=-16294+(on>0);
unsigned char x=PEEK(addr);
return;
}

10
main.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef _MAIN_H
#define _MAIN_H
int main (void);
int readYN();
int readnum();
void backup();
void relayctrl(unsigned char on);
#endif // _MAIN_H