added input timeouts
git-svn-id: https://svn.salfter.gotdns.org/svn/a2bfc/trunk@91 1b90f75b-8b96-4784-87c0-14078182fce6
This commit is contained in:
95
main.c
95
main.c
@@ -8,12 +8,14 @@
|
|||||||
#include "ow-time.h"
|
#include "ow-time.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
COMP_STATUS compressor_status;
|
||||||
|
unsigned char* tempsensor=NULL;
|
||||||
|
unsigned char* clockdev=NULL;
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
short i, devcount;
|
short i, devcount;
|
||||||
unsigned char devs[80];
|
unsigned char devs[80];
|
||||||
unsigned char* tempsensor=NULL;
|
|
||||||
unsigned char* clock=NULL;
|
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm intime;
|
struct tm intime;
|
||||||
unsigned char setpoint=70;
|
unsigned char setpoint=70;
|
||||||
@@ -30,9 +32,9 @@ int main (void)
|
|||||||
if (ow_temp_idcheck(&devs[i<<3]))
|
if (ow_temp_idcheck(&devs[i<<3]))
|
||||||
tempsensor=&devs[i<<3];
|
tempsensor=&devs[i<<3];
|
||||||
if (ow_time_idcheck(&devs[i<<3]))
|
if (ow_time_idcheck(&devs[i<<3]))
|
||||||
clock=&devs[i<<3];
|
clockdev=&devs[i<<3];
|
||||||
}
|
}
|
||||||
if (tempsensor==NULL || clock==NULL)
|
if (tempsensor==NULL || clockdev==NULL)
|
||||||
{
|
{
|
||||||
printf("Error: temperature sensor and/or clock not found.\n");
|
printf("Error: temperature sensor and/or clock not found.\n");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -44,41 +46,51 @@ int main (void)
|
|||||||
{
|
{
|
||||||
bzero(&intime, sizeof(intime));
|
bzero(&intime, sizeof(intime));
|
||||||
printf("Year? ");
|
printf("Year? ");
|
||||||
intime.tm_year=readnum()-1900;
|
intime.tm_year=readnum(0,0)-1900;
|
||||||
printf("Month? ");
|
printf("Month? ");
|
||||||
intime.tm_mon=readnum()-1;
|
intime.tm_mon=readnum(0,0)-1;
|
||||||
printf("Day? ");
|
printf("Day? ");
|
||||||
intime.tm_mday=readnum();
|
intime.tm_mday=readnum(0,0);
|
||||||
printf("Hour? ");
|
printf("Hour? ");
|
||||||
intime.tm_hour=readnum();
|
intime.tm_hour=readnum(0,0);
|
||||||
printf("Minute? ");
|
printf("Minute? ");
|
||||||
intime.tm_min=readnum();
|
intime.tm_min=readnum(0,0);
|
||||||
ow_time_set(clock, mktime(&intime));
|
ow_time_set(clockdev, mktime(&intime));
|
||||||
|
clrscr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
relayctrl(0);
|
||||||
|
gotoxy(25,0);
|
||||||
|
printf("off ");
|
||||||
|
gotoxy(0,2);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// for (i=0; i<250; i++)
|
t=ow_time_read(clockdev);
|
||||||
// ow_mswait();
|
|
||||||
t=ow_time_read(clock);
|
|
||||||
currtemp=ow_temp_read(tempsensor, OW_TEMP_FAHRENHEIT);
|
currtemp=ow_temp_read(tempsensor, OW_TEMP_FAHRENHEIT);
|
||||||
gotoxy(0,0);
|
gotoxy(0,0);
|
||||||
printf("curr=%i set=%i goto=%i \n",
|
printf("curr=%i set=%i goto=%i \n",
|
||||||
currtemp,
|
currtemp,
|
||||||
setpoint,
|
setpoint,
|
||||||
gotopoint);
|
gotopoint);
|
||||||
printf("%s", asctime(localtime(&t)));
|
memcpy(&intime, localtime(&t), sizeof(intime));
|
||||||
|
printf("%i/%i/%02i %02i:%02i:%02i \n",
|
||||||
|
intime.tm_mon+1,
|
||||||
|
intime.tm_mday,
|
||||||
|
intime.tm_year%100,
|
||||||
|
intime.tm_hour,
|
||||||
|
intime.tm_min,
|
||||||
|
intime.tm_sec);
|
||||||
printf(" \n");
|
printf(" \n");
|
||||||
gotoy(wherey()-1);
|
gotoy(wherey()-1);
|
||||||
if (currtemp>=setpoint+2)
|
if (currtemp>=setpoint+2 && compressor_status==COMP_OFF)
|
||||||
{
|
{
|
||||||
if (t-shutoff>300)
|
if (t-shutoff>300)
|
||||||
{
|
{
|
||||||
relayctrl(1);
|
relayctrl(1);
|
||||||
gotoxy(25,0);
|
gotoxy(25,0);
|
||||||
printf(" ");
|
printf("on ");
|
||||||
gotoxy(0,2);
|
gotoxy(0,2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -88,10 +100,13 @@ int main (void)
|
|||||||
gotoxy(0,2);
|
gotoxy(0,2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currtemp<=setpoint-2)
|
if (currtemp<=setpoint-2 && compressor_status==COMP_ON)
|
||||||
{
|
{
|
||||||
relayctrl(0);
|
relayctrl(0);
|
||||||
shutoff=t;
|
shutoff=t;
|
||||||
|
gotoxy(25,0);
|
||||||
|
printf("off ");
|
||||||
|
gotoxy(0,2);
|
||||||
}
|
}
|
||||||
if (t>=gototime && gotopoint!=setpoint)
|
if (t>=gototime && gotopoint!=setpoint)
|
||||||
{
|
{
|
||||||
@@ -109,16 +124,17 @@ int main (void)
|
|||||||
if (cmd=='S')
|
if (cmd=='S')
|
||||||
{
|
{
|
||||||
printf("Set point? ");
|
printf("Set point? ");
|
||||||
gotopoint=setpoint=readnum();
|
gotopoint=setpoint=readnum(setpoint,1);
|
||||||
}
|
}
|
||||||
if (cmd=='G')
|
if (cmd=='G')
|
||||||
{
|
{
|
||||||
printf("Go-to point? ");
|
printf("Go-to point? ");
|
||||||
gotopoint=readnum();
|
gotopoint=readnum(gotopoint,1);
|
||||||
gototime=t+3600;
|
gototime=t+3600;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (cmd!=3);
|
while (cmd!=3);
|
||||||
|
relayctrl(0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -126,15 +142,30 @@ int main (void)
|
|||||||
int readYN()
|
int readYN()
|
||||||
{
|
{
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
time_t start;
|
||||||
|
|
||||||
cputc('_');
|
cputc('_'); // display cursor
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
start=ow_time_read(clockdev);
|
||||||
|
do // wait for input, but time out after 15 seconds
|
||||||
|
{
|
||||||
|
}
|
||||||
|
while (!kbhit() && ow_time_read(clockdev)-start<15);
|
||||||
|
if (!kbhit()) // time out...return "no"
|
||||||
|
{
|
||||||
|
backup();
|
||||||
|
c='N';
|
||||||
|
cputc(c);
|
||||||
|
cputc(13);
|
||||||
|
cputc(10);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
c=cgetc();
|
c=cgetc();
|
||||||
if (c>96)
|
if (c>96) // convert lowercase to uppercase
|
||||||
c=c-32;
|
c=c-32;
|
||||||
}
|
}
|
||||||
while (c!='Y' && c!='N');
|
while (c!='Y' && c!='N'); // yes or no only
|
||||||
backup();
|
backup();
|
||||||
cputc(c);
|
cputc(c);
|
||||||
cputc(13);
|
cputc(13);
|
||||||
@@ -142,17 +173,34 @@ int readYN()
|
|||||||
return (c=='Y')?1:0;
|
return (c=='Y')?1:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int readnum()
|
int readnum(int defval, unsigned char timeout)
|
||||||
{
|
{
|
||||||
unsigned char c[8];
|
unsigned char c[8];
|
||||||
unsigned char p=0;
|
unsigned char p=0;
|
||||||
int r=0;
|
int r=0;
|
||||||
unsigned char i;
|
unsigned char i;
|
||||||
|
time_t start;
|
||||||
|
|
||||||
bzero(c, sizeof(c));
|
bzero(c, sizeof(c));
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
cputc('_');
|
cputc('_');
|
||||||
|
start=ow_time_read(clockdev);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
}
|
||||||
|
while (!kbhit() && timeout && ow_time_read(clockdev)-start<15);
|
||||||
|
if (!kbhit() && timeout)
|
||||||
|
{
|
||||||
|
while (p>0)
|
||||||
|
{
|
||||||
|
backup();
|
||||||
|
p--;
|
||||||
|
}
|
||||||
|
backup();
|
||||||
|
printf("%i\n", defval);
|
||||||
|
return defval;
|
||||||
|
}
|
||||||
c[p]=cgetc();
|
c[p]=cgetc();
|
||||||
backup();
|
backup();
|
||||||
if (c[p]==8 || c[p]==127)
|
if (c[p]==8 || c[p]==127)
|
||||||
@@ -193,5 +241,6 @@ void relayctrl(unsigned char on)
|
|||||||
{
|
{
|
||||||
signed int addr=-16294+(on>0);
|
signed int addr=-16294+(on>0);
|
||||||
unsigned char x=PEEK(addr);
|
unsigned char x=PEEK(addr);
|
||||||
|
compressor_status=(on)?COMP_ON:COMP_OFF;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
4
main.h
4
main.h
@@ -1,9 +1,11 @@
|
|||||||
#ifndef _MAIN_H
|
#ifndef _MAIN_H
|
||||||
#define _MAIN_H
|
#define _MAIN_H
|
||||||
|
|
||||||
|
typedef enum {COMP_OFF, COMP_ON} COMP_STATUS;
|
||||||
|
|
||||||
int main (void);
|
int main (void);
|
||||||
int readYN();
|
int readYN();
|
||||||
int readnum();
|
int readnum(int defval, unsigned char timeout);
|
||||||
void backup();
|
void backup();
|
||||||
void relayctrl(unsigned char on);
|
void relayctrl(unsigned char on);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user