Contiki-Inga 3.x
duty-cycle-scroller.c
1 /*
2  * Copyright (c) 2006, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * Author : Adam Dunkels
32  */
33 
34 #include "contiki.h"
35 #include "duty-cycle-scroller.h"
36 #include "lcd.h"
37 #include "sys/energest.h"
38 
39 PROCESS(duty_cycle_scroller_process, "Duty cycle scroller");
40 
41 static clock_time_t interval;
42 
43 /*---------------------------------------------------------------------------*/
44 PROCESS_THREAD(duty_cycle_scroller_process, ev, data)
45 {
46  static struct etimer interval_timer;
47  int height;
48  static uint32_t last_cpu, last_lpm, last_transmit, last_listen;
49  uint32_t cpu, lpm, transmit, listen;
50  uint32_t all_cpu, all_lpm, all_transmit, all_listen;
51  uint32_t radio, time;
52  PROCESS_BEGIN();
53 
54  while(1) {
55  etimer_set(&interval_timer, interval);
56  PROCESS_WAIT_UNTIL(etimer_expired(&interval_timer));
57  lcd_scroll_x();
58 
59  all_cpu = energest_type_time(ENERGEST_TYPE_CPU);
60  all_lpm = energest_type_time(ENERGEST_TYPE_LPM);
61  all_transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT);
62  all_listen = energest_type_time(ENERGEST_TYPE_LISTEN);
63 
64  cpu = all_cpu - last_cpu;
65  lpm = all_lpm - last_lpm;
66  transmit = all_transmit - last_transmit;
67  listen = all_listen - last_listen;
68 
69  last_cpu = all_cpu;
70  last_lpm = all_lpm;
71  last_transmit = all_transmit;
72  last_listen = all_listen;
73 
74  radio = transmit + listen;
75  time = cpu + lpm;
76 
77  height = 1 + (5 + ((1000 * radio) / time)) / 10;
78  if(height >= LCD_MAX_SCROLL_AREA) {
79  height = LCD_MAX_SCROLL_AREA;
80  }
81  lcd_draw_vertical_line(height);
82  }
83 
84  PROCESS_END();
85 }
86 /*---------------------------------------------------------------------------*/
87 void
88 duty_cycle_scroller_start(clock_time_t i)
89 {
90  interval = i;
91  process_start(&duty_cycle_scroller_process, NULL);
92 }
93 /*---------------------------------------------------------------------------*/
94 void
95 duty_cycle_scroller_stop(void)
96 {
97  process_exit(&duty_cycle_scroller_process);
98 }
99 /*---------------------------------------------------------------------------*/