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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
#include <board.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <adc/adc12.h>
#include <irq/irq.h>
#include <rtc/rtc.h>
#include "dfm_config.h"
#include "dfm_cmd.h"
#include "dfm_lcd_tsd.h"
#include "dfm_dispboxmgr.h"
#include "dfm_it.h"
//------------------------------------------------------------------------------
// Global variables
//------------------------------------------------------------------------------
#if defined(at91sam3u4)
#define BOARD_ADC_FREQ 5000000
#define ADC_VREF 3300 // 3.3 * 1000
#endif
#if defined(USE_IT_CHAIN_MGR)
void RTC_IrqHandlerSlideShow(void);
TDFM_ItServList gRtcItHandlerSlideShow = {BOARD_RTC_ID, RTC_IrqHandlerSlideShow, NULL};
#endif
/// count seconds
unsigned int gSecondCount = 0;
/// Record when slide show starts
static unsigned int gSlideShowStartSec = 0xFFFFFFFF;
/// slide show wait interval
unsigned int gSlideShowInterval = 5;
/// default home page to return when slide show ends
unsigned int gDefaultHomePage = 1;
/// adc sample value when slide show starts
unsigned int gPoMeterRefADValue = 0xFFFFFFFF;
/// adjustment interval base, will be set same as gSlideShowInterval when slide show start
unsigned int gIntervalBase;
/// the threshold value for interval adjustment by potentimeter
unsigned int gInvThreshold = 30;//default is 30 seconds
unsigned int xSlPenLast=0;
unsigned int ySlPenLast=0;
//------------------------------------------------------------------------------
/// Interrupt RTC handler for slide show.
//------------------------------------------------------------------------------
void RTC_IrqHandlerSlideShow()
{
unsigned int status, advalue;
unsigned char tmpT;
status = AT91C_BASE_RTC->RTC_SR;
if ((status & AT91C_RTC_SECEV) == AT91C_RTC_SECEV) {
// Disable RTC interrupt
RTC_DisableIt(AT91C_RTC_SECEV);
}
++gSecondCount;
if(gSlideShowStartSec == 0xffffffff)
gSlideShowStartSec = gSecondCount;
if(gSecondCount - gSlideShowStartSec >= gSlideShowInterval) {
++gActiveSlideIndex;
gSlideShowStartSec = gSecondCount;
}
#if defined(at91sam3u4)
if(gSecondCount & 1 == 0) {
ADC12_StartConversion(AT91C_BASE_ADC12B);
} else {
// if(gSecondCount % 2 == 0) {
advalue = ADC12_GetConvertedData(AT91C_BASE_ADC12B, ADC12_CHANNEL_3);
advalue = advalue * ADC_VREF / 0xFFF;
if(gPoMeterRefADValue == 0xFFFFFFFF) {
gPoMeterRefADValue = advalue;
gSlideShowInterval = advalue * gInvThreshold / ADC_VREF;
// gIntervalBase = gSlideShowInterval;
}
if(advalue != gPoMeterRefADValue) {
gSlideShowInterval = advalue * gInvThreshold / ADC_VREF;
}
// if(advalue > gPoMeterRefADValue) {
// gSlideShowInterval = (advalue - gPoMeterRefADValue) * (gInvThreshold - gIntervalBase) \
// /(ADC_VREF - gPoMeterRefADValue) + gIntervalBase;
// }
//
// if(advalue < gPoMeterRefADValue) {
// gSlideShowInterval = gIntervalBase - (gPoMeterRefADValue - advalue) * gIntervalBase \
// / gPoMeterRefADValue;
// }
if(gSlideShowInterval == 0) {
gSlideShowInterval = 1;
}
}
#endif
AT91C_BASE_RTC->RTC_SCCR = AT91C_RTC_SECEV;
RTC_EnableIt(AT91C_RTC_SECEV);
tmpT = TSD_GetTouched();
if(tmpT)
{
//printf("Touch \n\r");
TSD_ClearTouched();
// End slide show command
ParseAndRunMultiCmds("slideshow end");
ParseAndRunMultiCmds("slidepage goto 02");
}
}
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Portal for 'slideshow' command
// \param argc, number of argument
// \param argv, argument string array
// \return 0 succeed, other value failure
//------------------------------------------------------------------------------
int DFM_SlideShow(int argc, char ** argv)
{
unsigned int value;
char string[20];
if(argc == 3 && strcmp(argv[1], "-interval") == 0) {
//command "slideshow -interval up
if(strcmp(argv[2], "up")==0) {
++gSlideShowInterval;
}
//command "slideshow -interval down
if(strcmp(argv[2], "down")==0) {
--gSlideShowInterval;
}
//command "slideshow -interval display
// display current gSlideShowInterval value in display box
if(strcmp(argv[2], "display")==0) {
sprintf(string, "%u ", gSlideShowInterval);
DrawStrInDispBoxScrollNoClear((void *)BOARD_LCD_BASE, 1, string);
}
}
//command "slideshow start"
if(argc == 2 && strcmp(argv[1], "start")==0) {
TSD_ClearTouched();
//reset variable
gSlideShowStartSec = 0xFFFFFFFF;
gPoMeterRefADValue = 0xFFFFFFFF;
#if defined(at91sam3u4)
ADC12_EnableChannel(AT91C_BASE_ADC12B, ADC12_CHANNEL_3);
// Start measurement
ADC12_StartConversion(AT91C_BASE_ADC12B);
#endif
#if defined(USE_IT_CHAIN_MGR)
DFM_RegisterItHandler(&gRtcItHandlerSlideShow);
#endif
//enable RTC interrupt
IRQ_ConfigureIT(BOARD_RTC_ID, 0, RTC_IrqHandlerSlideShow);
RTC_EnableIt(AT91C_RTC_SECEV);
IRQ_EnableIT(BOARD_RTC_ID);
}
//command "slideshow start -homepage xx"
if(argc == 4 && strcmp(argv[1], "start")==0 &&
strcmp(argv[2], "-homepage")==0) {
TSD_ClearTouched();
//reset variable
gSlideShowStartSec = 0xFFFFFFFF;
#if defined(USE_IT_CHAIN_MGR)
DFM_RegisterItHandler(&gRtcItHandlerSlideShow);
#endif
//enable RTC interrupt
IRQ_ConfigureIT(BOARD_RTC_ID, 0, RTC_IrqHandlerSlideShow);
RTC_EnableIt(AT91C_RTC_SECEV);
IRQ_EnableIT(BOARD_RTC_ID);
value = atoi(argv[3]);
//in command input, slide start from 1, but in program it starts from 0
//note if index number of slide bigger than max, program will correct as
//the last of slide
gDefaultHomePage = value - 1;
}
//command "slideshow end"
if(argc == 2 && strcmp(argv[1], "end")==0) {
TSD_ClearTouched();
RTC_DisableIt(AT91C_RTC_SECEV);
IRQ_DisableIT(BOARD_RTC_ID);
#if defined(at91sam3u4)
DFM_UnRegisterItHandler(&gRtcItHandlerSlideShow);
#endif
//reset variable
gSlideShowStartSec = 0xFFFFFFFF;
gActiveSlideIndex = gDefaultHomePage;
}
//command "slideshow start -homepage xx"
if(argc == 4 && strcmp(argv[1], "end")==0 &&
strcmp(argv[2], "-homepage")==0) {
TSD_ClearTouched();
RTC_DisableIt(AT91C_RTC_SECEV);
IRQ_DisableIT(BOARD_RTC_ID);
#if defined(at91sam3u4)
DFM_UnRegisterItHandler(&gRtcItHandlerSlideShow);
#endif
//reset variable
gSlideShowStartSec = 0xFFFFFFFF;
value = atoi(argv[3]);
//in command input, slide start from 1, but in program it starts from 0
//note if index number of slide bigger than max, program will correct as
//the last of slide
gActiveSlideIndex = value - 1;
gDefaultHomePage = gActiveSlideIndex;
}
return 0;
}
//define a new command 'slideshow' for slide show
DFM_CMD(slideshow, DFM_SlideShow, "slide show ppt pages", "default");
|