123
Fork of LG by
DeviceTSS.c@197:7a05523bf588, 2016-10-19 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Oct 19 10:55:05 2016 +0000
- Revision:
- 197:7a05523bf588
- Parent:
- 174:0f86eedd511c
modul
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Diletant | 174:0f86eedd511c | 1 | #include "Device.h" |
Diletant | 174:0f86eedd511c | 2 | extern Device device; |
Diletant | 174:0f86eedd511c | 3 | |
Diletant | 174:0f86eedd511c | 4 | void InitTSSDefaultSettings(void){ |
Diletant | 174:0f86eedd511c | 5 | device.tss.temperature.settings.transfer.points = 16; |
Diletant | 174:0f86eedd511c | 6 | device.tss.temperature.settings.transfer.raw[0] = -0x8e0ba2e; //-2272.727272727273 |
Diletant | 174:0f86eedd511c | 7 | device.tss.temperature.settings.transfer.celsius[0] = -0x3c0000; //-60.0 |
Diletant | 174:0f86eedd511c | 8 | device.tss.temperature.settings.transfer.raw[1] = -0x6645d17; //-1636.3636363636365 |
Diletant | 174:0f86eedd511c | 9 | device.tss.temperature.settings.transfer.celsius[1] = -0x320000; //-50.0 |
Diletant | 174:0f86eedd511c | 10 | device.tss.temperature.settings.transfer.raw[2] = -0x3e80000; //-1000.0000000000002 |
Diletant | 174:0f86eedd511c | 11 | device.tss.temperature.settings.transfer.celsius[2] = -0x280000; //-40.0 |
Diletant | 174:0f86eedd511c | 12 | device.tss.temperature.settings.transfer.raw[3] = -0x16ba2e8; //-363.63636363636397 |
Diletant | 174:0f86eedd511c | 13 | device.tss.temperature.settings.transfer.celsius[3] = -0x1e0000; //-30.0 |
Diletant | 174:0f86eedd511c | 14 | device.tss.temperature.settings.transfer.raw[4] = 0x110ba2e; //272.7272727272725 |
Diletant | 174:0f86eedd511c | 15 | device.tss.temperature.settings.transfer.celsius[4] = -0x140000; //-20.0 |
Diletant | 174:0f86eedd511c | 16 | device.tss.temperature.settings.transfer.raw[5] = 0x38d1745; //909.090909090909 |
Diletant | 174:0f86eedd511c | 17 | device.tss.temperature.settings.transfer.celsius[5] = -0xa0000; //-10.0 |
Diletant | 174:0f86eedd511c | 18 | device.tss.temperature.settings.transfer.raw[6] = 0x609745d; //1545.454545454545 |
Diletant | 174:0f86eedd511c | 19 | device.tss.temperature.settings.transfer.celsius[6] = 0x0; //0.0 |
Diletant | 174:0f86eedd511c | 20 | device.tss.temperature.settings.transfer.raw[7] = 0x885d174; //2181.818181818182 |
Diletant | 174:0f86eedd511c | 21 | device.tss.temperature.settings.transfer.celsius[7] = 0xa0000; //10.0 |
Diletant | 174:0f86eedd511c | 22 | device.tss.temperature.settings.transfer.raw[8] = 0xb022e8b; //2818.181818181818 |
Diletant | 174:0f86eedd511c | 23 | device.tss.temperature.settings.transfer.celsius[8] = 0x140000; //20.0 |
Diletant | 174:0f86eedd511c | 24 | device.tss.temperature.settings.transfer.raw[9] = 0xd7e8ba2; //3454.545454545454 |
Diletant | 174:0f86eedd511c | 25 | device.tss.temperature.settings.transfer.celsius[9] = 0x1e0000; //30.0 |
Diletant | 174:0f86eedd511c | 26 | device.tss.temperature.settings.transfer.raw[10] = 0xffae8ba; //4090.909090909091 |
Diletant | 174:0f86eedd511c | 27 | device.tss.temperature.settings.transfer.celsius[10] = 0x280000; //40.0 |
Diletant | 174:0f86eedd511c | 28 | device.tss.temperature.settings.transfer.raw[11] = 0x127745d1; //4727.272727272727 |
Diletant | 174:0f86eedd511c | 29 | device.tss.temperature.settings.transfer.celsius[11] = 0x320000; //50.0 |
Diletant | 174:0f86eedd511c | 30 | device.tss.temperature.settings.transfer.raw[12] = 0x14f3a2e8; //5363.636363636363 |
Diletant | 174:0f86eedd511c | 31 | device.tss.temperature.settings.transfer.celsius[12] = 0x3c0000; //60.0 |
Diletant | 174:0f86eedd511c | 32 | device.tss.temperature.settings.transfer.raw[13] = 0x176fffff; //5999.999999999999 |
Diletant | 174:0f86eedd511c | 33 | device.tss.temperature.settings.transfer.celsius[13] = 0x460000; //70.0 |
Diletant | 174:0f86eedd511c | 34 | device.tss.temperature.settings.transfer.raw[14] = 0x19ec5d17; //6636.363636363637 |
Diletant | 174:0f86eedd511c | 35 | device.tss.temperature.settings.transfer.celsius[14] = 0x500000; //80.0 |
Diletant | 174:0f86eedd511c | 36 | device.tss.temperature.settings.transfer.raw[15] = 0x1c68ba2e; //7272.727272727273 |
Diletant | 174:0f86eedd511c | 37 | device.tss.temperature.settings.transfer.celsius[15] = 0x5a0000; //90.0 |
Diletant | 174:0f86eedd511c | 38 | |
Diletant | 174:0f86eedd511c | 39 | //TODO: actual values |
Diletant | 174:0f86eedd511c | 40 | device.tss.gradient.settings.transfer.points = 16; |
Diletant | 174:0f86eedd511c | 41 | device.tss.gradient.settings.transfer.raw[0] = -0x640000; //-100.0 |
Diletant | 174:0f86eedd511c | 42 | device.tss.gradient.settings.transfer.celsius[0] = -0xa0000; //-10.0 |
Diletant | 174:0f86eedd511c | 43 | device.tss.gradient.settings.transfer.raw[1] = -0x56aaaa; //-86.66666666666667 |
Diletant | 174:0f86eedd511c | 44 | device.tss.gradient.settings.transfer.celsius[1] = -0x8aaaa; //-8.666666666666666 |
Diletant | 174:0f86eedd511c | 45 | device.tss.gradient.settings.transfer.raw[2] = -0x495555; //-73.33333333333333 |
Diletant | 174:0f86eedd511c | 46 | device.tss.gradient.settings.transfer.celsius[2] = -0x75555; //-7.333333333333334 |
Diletant | 174:0f86eedd511c | 47 | device.tss.gradient.settings.transfer.raw[3] = -0x3c0000; //-60.0 |
Diletant | 174:0f86eedd511c | 48 | device.tss.gradient.settings.transfer.celsius[3] = -0x60000; //-6.0 |
Diletant | 174:0f86eedd511c | 49 | device.tss.gradient.settings.transfer.raw[4] = -0x2eaaaa; //-46.666666666666664 |
Diletant | 174:0f86eedd511c | 50 | device.tss.gradient.settings.transfer.celsius[4] = -0x4aaaa; //-4.666666666666667 |
Diletant | 174:0f86eedd511c | 51 | device.tss.gradient.settings.transfer.raw[5] = -0x215555; //-33.33333333333333 |
Diletant | 174:0f86eedd511c | 52 | device.tss.gradient.settings.transfer.celsius[5] = -0x35555; //-3.333333333333334 |
Diletant | 174:0f86eedd511c | 53 | device.tss.gradient.settings.transfer.raw[6] = -0x140000; //-20.0 |
Diletant | 174:0f86eedd511c | 54 | device.tss.gradient.settings.transfer.celsius[6] = -0x20000; //-2.0 |
Diletant | 174:0f86eedd511c | 55 | device.tss.gradient.settings.transfer.raw[7] = -0x6aaaa; //-6.666666666666657 |
Diletant | 174:0f86eedd511c | 56 | device.tss.gradient.settings.transfer.celsius[7] = -0xaaaa; //-0.6666666666666679 |
Diletant | 174:0f86eedd511c | 57 | device.tss.gradient.settings.transfer.raw[8] = 0x6aaaa; //6.666666666666671 |
Diletant | 174:0f86eedd511c | 58 | device.tss.gradient.settings.transfer.celsius[8] = 0xaaaa; //0.6666666666666661 |
Diletant | 174:0f86eedd511c | 59 | device.tss.gradient.settings.transfer.raw[9] = 0x140000; //20.0 |
Diletant | 174:0f86eedd511c | 60 | device.tss.gradient.settings.transfer.celsius[9] = 0x20000; //2.0 |
Diletant | 174:0f86eedd511c | 61 | device.tss.gradient.settings.transfer.raw[10] = 0x215555; //33.33333333333334 |
Diletant | 174:0f86eedd511c | 62 | device.tss.gradient.settings.transfer.celsius[10] = 0x35555; //3.333333333333332 |
Diletant | 174:0f86eedd511c | 63 | device.tss.gradient.settings.transfer.raw[11] = 0x2eaaaa; //46.666666666666686 |
Diletant | 174:0f86eedd511c | 64 | device.tss.gradient.settings.transfer.celsius[11] = 0x4aaaa; //4.666666666666666 |
Diletant | 174:0f86eedd511c | 65 | device.tss.gradient.settings.transfer.raw[12] = 0x3c0000; //60.0 |
Diletant | 174:0f86eedd511c | 66 | device.tss.gradient.settings.transfer.celsius[12] = 0x60000; //6.0 |
Diletant | 174:0f86eedd511c | 67 | device.tss.gradient.settings.transfer.raw[13] = 0x495555; //73.33333333333334 |
Diletant | 174:0f86eedd511c | 68 | device.tss.gradient.settings.transfer.celsius[13] = 0x75555; //7.333333333333332 |
Diletant | 174:0f86eedd511c | 69 | device.tss.gradient.settings.transfer.raw[14] = 0x56aaaa; //86.66666666666669 |
Diletant | 174:0f86eedd511c | 70 | device.tss.gradient.settings.transfer.celsius[14] = 0x8aaaa; //8.666666666666664 |
Diletant | 174:0f86eedd511c | 71 | device.tss.gradient.settings.transfer.raw[15] = 0x640000; //100.0 |
Diletant | 174:0f86eedd511c | 72 | device.tss.gradient.settings.transfer.celsius[15] = 0xa0000; //10.0 |
Diletant | 174:0f86eedd511c | 73 | } |
Diletant | 174:0f86eedd511c | 74 | |
Diletant | 174:0f86eedd511c | 75 | void InitTSSState(void) { |
Diletant | 174:0f86eedd511c | 76 | device.tss.temperature.state.sum = 0; |
Diletant | 174:0f86eedd511c | 77 | device.tss.gradient.state.sum = 0; |
Diletant | 174:0f86eedd511c | 78 | device.tss.temperature.state.raw = 0; |
Diletant | 174:0f86eedd511c | 79 | device.tss.temperature.state.celsius = tssTemperature(device.tss.temperature.state.raw); |
Diletant | 174:0f86eedd511c | 80 | device.tss.gradient.state.raw = 0; |
Diletant | 174:0f86eedd511c | 81 | device.tss.gradient.state.celsius = tssGradient(device.tss.gradient.state.raw); |
Diletant | 174:0f86eedd511c | 82 | } |
Diletant | 174:0f86eedd511c | 83 | |
Diletant | 174:0f86eedd511c | 84 | void DeviceStartTSS(void) { |
Diletant | 174:0f86eedd511c | 85 | } |
Diletant | 174:0f86eedd511c | 86 | |
Diletant | 174:0f86eedd511c | 87 | int32_t tssInterpolate(int32_t a,int32_t a1,int32_t a2,int32_t b1,int32_t b2) { |
Diletant | 174:0f86eedd511c | 88 | int32_t ma, mb; |
Diletant | 174:0f86eedd511c | 89 | while (1) { |
Diletant | 174:0f86eedd511c | 90 | if (a1 == a) return b1; |
Diletant | 174:0f86eedd511c | 91 | if (a2 == a) return b2; |
Diletant | 174:0f86eedd511c | 92 | |
Diletant | 174:0f86eedd511c | 93 | ma = (a1 + a2) >> 1; |
Diletant | 174:0f86eedd511c | 94 | mb = (b1 + b2) >> 1; |
Diletant | 174:0f86eedd511c | 95 | |
Diletant | 174:0f86eedd511c | 96 | if (a < ma) { |
Diletant | 174:0f86eedd511c | 97 | if (a2 == ma) return mb; |
Diletant | 174:0f86eedd511c | 98 | if (b1 == mb) return mb; |
Diletant | 174:0f86eedd511c | 99 | a2 = ma; b2 = mb; |
Diletant | 174:0f86eedd511c | 100 | } else if (a > ma) { |
Diletant | 174:0f86eedd511c | 101 | if (a1 == ma) return mb; |
Diletant | 174:0f86eedd511c | 102 | if (b2 == mb) return mb; |
Diletant | 174:0f86eedd511c | 103 | a1 = ma; b1 = mb; |
Diletant | 174:0f86eedd511c | 104 | } else return mb; |
Diletant | 174:0f86eedd511c | 105 | } |
Diletant | 174:0f86eedd511c | 106 | } |
Diletant | 174:0f86eedd511c | 107 | |
Diletant | 174:0f86eedd511c | 108 | int32_t tssTemperature(uint32_t raw) { |
Diletant | 174:0f86eedd511c | 109 | int32_t r1, r2; |
Diletant | 174:0f86eedd511c | 110 | for (uint8_t i = 1; i < device.tss.temperature.settings.transfer.points; i++) { |
Diletant | 174:0f86eedd511c | 111 | r1 = device.tss.temperature.settings.transfer.raw[i - 1]; |
Diletant | 174:0f86eedd511c | 112 | if (raw < r1) { |
Diletant | 174:0f86eedd511c | 113 | return device.tss.temperature.settings.transfer.celsius[i - 1]; |
Diletant | 174:0f86eedd511c | 114 | } |
Diletant | 174:0f86eedd511c | 115 | |
Diletant | 174:0f86eedd511c | 116 | r2 = device.tss.temperature.settings.transfer.raw[i]; |
Diletant | 174:0f86eedd511c | 117 | if (raw < r2) { |
Diletant | 174:0f86eedd511c | 118 | int32_t c1 = device.tss.temperature.settings.transfer.celsius[i - 1]; |
Diletant | 174:0f86eedd511c | 119 | int32_t c2 = device.tss.temperature.settings.transfer.celsius[i]; |
Diletant | 174:0f86eedd511c | 120 | return tssInterpolate(raw, r1, r2, c1, c2); |
Diletant | 174:0f86eedd511c | 121 | } |
Diletant | 174:0f86eedd511c | 122 | } |
Diletant | 174:0f86eedd511c | 123 | return device.tss.temperature.settings.transfer.celsius[device.tss.temperature.settings.transfer.points - 1]; |
Diletant | 174:0f86eedd511c | 124 | } |
Diletant | 174:0f86eedd511c | 125 | |
Diletant | 174:0f86eedd511c | 126 | int32_t tssGradient(uint32_t raw) { |
Diletant | 174:0f86eedd511c | 127 | int32_t r1, r2; |
Diletant | 174:0f86eedd511c | 128 | for (uint8_t i = 1; i < device.tss.gradient.settings.transfer.points; i++) { |
Diletant | 174:0f86eedd511c | 129 | r1 = device.tss.gradient.settings.transfer.raw[i - 1]; |
Diletant | 174:0f86eedd511c | 130 | if (raw < r1) { |
Diletant | 174:0f86eedd511c | 131 | return device.tss.gradient.settings.transfer.celsius[i - 1]; |
Diletant | 174:0f86eedd511c | 132 | } |
Diletant | 174:0f86eedd511c | 133 | |
Diletant | 174:0f86eedd511c | 134 | r2 = device.tss.gradient.settings.transfer.raw[i]; |
Diletant | 174:0f86eedd511c | 135 | if (raw < r2) { |
Diletant | 174:0f86eedd511c | 136 | int32_t c1 = device.tss.gradient.settings.transfer.celsius[i - 1]; |
Diletant | 174:0f86eedd511c | 137 | int32_t c2 = device.tss.gradient.settings.transfer.celsius[i]; |
Diletant | 174:0f86eedd511c | 138 | return tssInterpolate(raw, r1, r2, c1, c2); |
Diletant | 174:0f86eedd511c | 139 | } |
Diletant | 174:0f86eedd511c | 140 | } |
Diletant | 174:0f86eedd511c | 141 | return device.tss.gradient.settings.transfer.celsius[device.tss.gradient.settings.transfer.points - 1]; |
Diletant | 174:0f86eedd511c | 142 | } |
Diletant | 174:0f86eedd511c | 143 | |
Diletant | 174:0f86eedd511c | 144 | void tssProcess(void) { |
Diletant | 174:0f86eedd511c | 145 | device.tss.temperature.state.sum += device.controller.SSP.in[3]; |
Diletant | 174:0f86eedd511c | 146 | device.tss.gradient.state.sum += device.controller.SSP.in[0]; |
Diletant | 174:0f86eedd511c | 147 | |
Diletant | 174:0f86eedd511c | 148 | if (device.measurement.counter == 31) { |
Diletant | 174:0f86eedd511c | 149 | device.tss.temperature.state.raw = device.tss.temperature.state.sum >> 5; |
Diletant | 174:0f86eedd511c | 150 | device.tss.temperature.state.celsius = tssTemperature(device.tss.temperature.state.raw); |
Diletant | 174:0f86eedd511c | 151 | device.tss.temperature.state.sum = 0; |
Diletant | 174:0f86eedd511c | 152 | device.tss.gradient.state.raw = device.tss.gradient.state.sum >> 5; |
Diletant | 174:0f86eedd511c | 153 | device.tss.gradient.state.celsius = tssGradient(device.tss.gradient.state.raw); |
Diletant | 174:0f86eedd511c | 154 | device.tss.gradient.state.sum = 0; |
Diletant | 174:0f86eedd511c | 155 | } |
Diletant | 174:0f86eedd511c | 156 | } |