forked from muccc/formica_rev1_muc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leds.c
97 lines (85 loc) · 1.57 KB
/
leds.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "leds.h"
#include "time.h"
#include "device.h"
/* produce a single flash of a colour, as defined in leds.h */
mood_t mood = MOOD_NONE;
mood_t tempmood = MOOD_NONE;
#define FLASHTIME 3
void leds_flash(uint8_t colour)
{
uint8_t prev_led_state = 0;
prev_led_state = P4OUT & 0x06;
P4OUT &= ~(0x06);
P4OUT |= (colour & 0x06);
time_wait(FLASHTIME);
P4OUT &= ~(0x06);
P4OUT |= prev_led_state;
}
void leds_set(uint8_t colour)
{
P4OUT &= ~(0x06);
P4OUT |= (colour & 0x06);
}
void leds_update_mood()
{
static mood_t oldmood;
static uint32_t temptime=0;
if (tempmood != MOOD_NONE)
{
oldmood = mood;
mood = tempmood;
if (temptime == 0)
temptime = the_time + FLASHTIME;
else if (the_time > temptime)
{
mood = oldmood;
tempmood = MOOD_NONE;
temptime = 0;
}
}
switch (mood)
{
case MOOD_NONE:
leds_set(NONE);
break;
case MOOD_DRIVING_TO_CHARGER_NOFOOD:
leds_flash(GREEN);
leds_flash(NONE);
break;
case MOOD_DRIVING_TO_CHARGER_FLATBATT:
leds_flash(RED);
leds_flash(NONE);
break;
case MOOD_CHARGING:
leds_flash(ORANGE);
leds_flash(NONE);
break;
case MOOD_CHARGING_ANGER1:
leds_set(RED);
break;
case MOOD_CHARGING_ANGER2:
leds_flash(GREEN);
leds_flash(NONE);
break;
case MOOD_GOT_FOOD:
leds_set(GREEN);
break;
case MOOD_AT_LAMP:
leds_set(RED);
break;
case MOOD_HEARD_ABOUT_FOOD:
leds_flash(ORANGE);
break;
case MOOD_CHARGED:
leds_flash(GREEN);
leds_flash(NONE);
break;
case MOOD_BORED_CHARGING:
leds_flash(RED);
leds_flash(NONE);
break;
default:
mood = MOOD_NONE;
leds_set(NONE);
}
}