Subversion Repositories HomeAutomation

Rev

Rev 282 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 282 Rev 339
Line 2... Line 2...
2
 *
2
 *
3
 *   Functions for controlling blinds
3
 *   Functions for controlling blinds
4
 *
4
 *
5
 *********************************************************************
5
 *********************************************************************
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canTemp/Source/blinds.c $
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canTemp/Source/blinds.c $
7
 * Last changed:    $LastChangedDate: 2007-02-03 16:58:13 +0100 (Sat, 03 Feb 2007) $
7
 * Last changed:    $LastChangedDate: 2007-02-25 20:51:08 +0100 (Sun, 25 Feb 2007) $
8
 * By:              $LastChangedBy: johboh $
8
 * By:              $LastChangedBy: johboh $
9
 * Revision:        $Revision: 282 $
9
 * Revision:        $Revision: 339 $
10
 ********************************************************************/
10
 ********************************************************************/
11
#include <blinds.h>
11
#include <blinds.h>
12
 
12
 
13
#ifdef USE_BLINDS
13
#ifdef USE_BLINDS
14
 
14
 
15
static unsigned int timerVal = 50536;
15
static unsigned int timerVal = 50536;
-
 
16
static unsigned int turnOffIO = 0;
-
 
17
static signed char currentPrecent = 0;
16
 
18
 
17
/*
19
/*
18
*   Function: blindsInit
20
*   Function: blindsInit
19
*
21
*
20
*   Input:  none.
22
*   Input:  none.
Line 30... Line 32...
30
    T1CON = 0b11000001;
32
    T1CON = 0b11000001;
31
    TMR1H=((timerVal&0xFF00)>>8);
33
    TMR1H=((timerVal&0xFF00)>>8);
32
    TMR1L=(timerVal&0xFF);
34
    TMR1L=(timerVal&0xFF);
33
    PIR1bits.TMR1IF = 0;
35
    PIR1bits.TMR1IF = 0;
34
    PIE1bits.TMR1IE = 1;
36
    PIE1bits.TMR1IE = 1;
35
    IPR1bits.TMR1IP = 1; // high prior?
37
    IPR1bits.TMR1IP = 0; // Low prior
36
}
38
}
-
 
39
 
-
 
40
/*
-
 
41
*   Function: blindsGetAngle
-
 
42
*
-
 
43
*   Input:  none.
-
 
44
*   Output: angle.
-
 
45
*   Pre-conditions: none
-
 
46
*   Affects: none.
-
 
47
*   Depends: none.
-
 
48
*/
-
 
49
BYTE blindsGetPrecent()
-
 
50
{
-
 
51
    return currentPrecent;
-
 
52
}
-
 
53
 
37
 
54
 
38
/*
55
/*
39
*   Function: blindsTurn
56
*   Function: blindsTurn
40
*
57
*
41
*   Input:  Angle to turn to.
58
*   Input:  Angle to turn to.
42
*   Output: none.
59
*   Output: none.
43
*   Pre-conditions: none
60
*   Pre-conditions: none
44
*   Affects: none.
61
*   Affects: none.
45
*   Depends: none.
62
*   Depends: none.
46
*/
63
*/
47
void blindsTurn(signed char angle)
64
void blindsTurn(BYTE precent)
48
{
65
{
49
    // 65536-TIME/0,0000001
66
    // 65536-TIME/0,0000001
50
    // -90 0.5 ms = 60536 (5000)
67
    // -90 0.5 ms = 60536 (5000)
51
    // 0   1.5 ms = 50536 (15000)
68
    // 0   1.5 ms = 50536 (15000)
52
    // 90  2.5 ms = 40536 (25000)
69
    // 90  2.5 ms = 40536 (25000)
53
 
70
 
-
 
71
    BLINDS0P_IO=1;
54
    if (angle<-90) timerVal=60536;
72
    turnOffIO = IO_TIMEOUT;
-
 
73
    /*
-
 
74
        if (angle<ANGLE_MIN) {timerVal=ANGLE_MIN_TIMER; currentAngle=ANGLE_MIN; }
55
    else if (angle>90) timerVal=40536;
75
        else if (angle>ANGLE_MAX) {timerVal=ANGLE_MAX_TIMER; currentAngle=ANGLE_MAX; }
56
    else
76
        else
57
    {
77
        {
58
        timerVal=60536-(unsigned int)((90+(signed int)angle)*111.111);
78
            timerVal=60536-(unsigned int)((90+(signed int)angle)*111.111);
-
 
79
            currentAngle=angle;
59
    }
80
        }
-
 
81
    */
-
 
82
 
-
 
83
    /*
-
 
84
    angle=precent*
-
 
85
 
-
 
86
    -50=k*100+m
-
 
87
    60=k*0+m
-
 
88
    angle=-1.1x+60
-
 
89
    */
-
 
90
 
-
 
91
    currentPrecent=precent;
-
 
92
    if (precent>100) { currentPrecent=100; }
-
 
93
    if (precent<0) { currentPrecent=0; }
-
 
94
 
-
 
95
   
-
 
96
    timerVal=60536-(unsigned int)((90+(-1.05*(signed int)currentPrecent+60))*111.111);
60
}
97
}
61
 
98
 
62
 
99
 
63
/*
100
/*
64
*   Function: blindsISR
101
*   Function: blindsISR
Line 70... Line 107...
70
*   Depends: none.
107
*   Depends: none.
71
*/
108
*/
72
void blindsISR(void)
109
void blindsISR(void)
73
{
110
{
74
    if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1)
111
    if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1)
75
    {
112
    {
76
        TMR1H=((timerVal&0xFF00)>>8);
113
        TMR1H=((timerVal&0xFF00)>>8);
77
        TMR1L=(timerVal&0xFF);
114
        TMR1L=(timerVal&0xFF);
78
 
115
 
79
        BLINDS0_IO=~BLINDS0_IO;
116
        BLINDS0_IO=~BLINDS0_IO;
-
 
117
 
-
 
118
        if (turnOffIO--<1)
-
 
119
        {
-
 
120
            BLINDS0P_IO=0;
-
 
121
        }
80
 
122
 
81
        PIR1bits.TMR1IF = 0;
123
        PIR1bits.TMR1IF = 0;
82
    }
124
    }
83
}
125
}
84
 
126