basic action handling inplemented
This commit is contained in:
parent
aa2b367773
commit
72182dc780
54
src/main.c
54
src/main.c
|
@ -78,6 +78,10 @@ ISR(TIMER2_OVF_vect) { /* timer 2 overflow interrupt vector */
|
|||
timer2_ovf++; /* increase tachometer counter */
|
||||
} else {
|
||||
tachometer = 0; /* indicate no speed can be measured */
|
||||
if (pwr_ok) { /* warn the fan is dead while the power in on */
|
||||
power_flag = true;
|
||||
}
|
||||
timer2_ovf = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,44 +175,56 @@ int main(void)
|
|||
ioinit(); /* initialize IOs */
|
||||
|
||||
uint8_t command_i = 0; /* command index */
|
||||
struct nec ir_data; /* last IR data */
|
||||
ir_data.valid = false;
|
||||
ir_data.repeat = false;
|
||||
ir_data.address = 0;
|
||||
ir_data.command = 0;
|
||||
uint8_t ir_repeat = 0; /* number of times the IR data has been repeated */
|
||||
|
||||
puts("LED dimmer up & running");
|
||||
while (true) {
|
||||
/* handle user input */
|
||||
while (input_flag) {
|
||||
input_flag = false;
|
||||
/* echo back */
|
||||
char c = 0;
|
||||
while (command_i<input_i) {
|
||||
c = input[command_i++];
|
||||
putchar(c);
|
||||
}
|
||||
action(c);
|
||||
uart_action(c);
|
||||
input_flag = false;
|
||||
}
|
||||
/* handle power state */
|
||||
while (power_flag) {
|
||||
power_flag = false;
|
||||
if (pwr_ok) {
|
||||
puts("power ok");
|
||||
/* verify if FAN is present */
|
||||
_delay_ms(1000);
|
||||
_delay_ms(500);
|
||||
if (0==tachometer) {
|
||||
puts("FAN not on, switching power off");
|
||||
PORTB |= (1<<nPS_ON);
|
||||
}
|
||||
} else {
|
||||
puts("power ko");
|
||||
puts("power off");
|
||||
}
|
||||
power_flag = false;
|
||||
}
|
||||
/* handle IR input */
|
||||
while (ir_flag) {
|
||||
time2nec(burst,pulse-1); /* convert raw time burst in NEC format */
|
||||
struct nec ir_data = nec2data(burst,pulse-1); /* decode NEC burst */
|
||||
if (ir_data.valid) {
|
||||
if (ir_data.repeat) {
|
||||
printf("IR signal repeated\n");
|
||||
struct nec ir_tmp = nec2data(burst,pulse-1); /* decode NEC burst */
|
||||
if (ir_tmp.valid) {
|
||||
if (ir_tmp.repeat) {
|
||||
if (ir_repeat<0xff) {
|
||||
ir_repeat++;
|
||||
}
|
||||
} else {
|
||||
printf("IR addr: %u, command: %u\n",ir_data.address,ir_data.command);
|
||||
ir_data = ir_tmp;
|
||||
ir_repeat = 0;
|
||||
}
|
||||
if (ir_repeat==0 || ir_repeat>3) {
|
||||
ir_action(ir_data.address,ir_data.command);
|
||||
}
|
||||
}
|
||||
pulse = 0; /* reset burst */
|
||||
|
@ -218,8 +234,7 @@ int main(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void action(char c)
|
||||
static void uart_action(char c)
|
||||
{
|
||||
switch (c) {
|
||||
case 'l':
|
||||
|
@ -369,3 +384,18 @@ static void action(char c)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ir_action(uint8_t address, uint8_t command)
|
||||
{
|
||||
if (0==address && 72==command) {
|
||||
printf("switching power supply ");
|
||||
if (PINB&(1<<nPS_ON)) {
|
||||
puts("on");
|
||||
} else {
|
||||
puts("off");
|
||||
}
|
||||
PINB |= (1<<nPS_ON);
|
||||
} else {
|
||||
printf("IR addr: %u, command: %u\n", address, command);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,5 @@
|
|||
#define CH2_5 PD7
|
||||
|
||||
static void ioinit(void);
|
||||
static void action(char c);
|
||||
static void uart_action(char c);
|
||||
static void ir_action(uint8_t address, uint8_t command);
|
||||
|
|
Loading…
Reference in New Issue