adamdunkels | 9fcf9d6 | 2003-09-04 19:46:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2002, Adam Dunkels. |
| 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 |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * 3. All advertising materials mentioning features or use of this |
| 15 | * software must display the following acknowledgement: |
| 16 | * This product includes software developed by Adam Dunkels. |
| 17 | * 4. The name of the author may not be used to endorse or promote |
| 18 | * products derived from this software without specific prior |
| 19 | * written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | * This file is part of the Contiki desktop environment |
| 34 | * |
| 35 | * $Id: sensorview.c,v 1.1 2003/09/04 19:46:33 adamdunkels Exp $ |
| 36 | * |
| 37 | */ |
| 38 | |
| 39 | #include "ctk.h" |
| 40 | #include "dispatcher.h" |
| 41 | #include "loader.h" |
| 42 | #include "sensors.h" |
| 43 | |
| 44 | #include <stdio.h> |
| 45 | |
| 46 | static struct ctk_window window; |
| 47 | |
| 48 | #if 1 |
| 49 | static struct ctk_label templabel = |
| 50 | {CTK_LABEL(1, 1, 12, 1,"Temperature:")}; |
| 51 | static char tempval[7]; |
| 52 | static struct ctk_label tempvallabel = |
| 53 | {CTK_LABEL(4, 3, 6, 1, tempval)}; |
| 54 | #endif |
| 55 | |
| 56 | static void sensorview_idle(void); |
| 57 | static DISPATCHER_SIGHANDLER(sensorview_sighandler, s, data); |
| 58 | static struct dispatcher_proc p = |
| 59 | {DISPATCHER_PROC("Sensor view", sensorview_idle, |
| 60 | sensorview_sighandler, NULL)}; |
| 61 | static ek_id_t id = EK_ID_NONE; |
| 62 | |
| 63 | /*-----------------------------------------------------------------------------------*/ |
| 64 | LOADER_INIT_FUNC(sensorview_init, arg) |
| 65 | { |
| 66 | arg_free(arg); |
| 67 | |
| 68 | if(id == EK_ID_NONE) { |
| 69 | id = dispatcher_start(&p); |
| 70 | |
| 71 | ctk_window_new(&window, 14, 4, "Sensors"); |
| 72 | #if 1 |
| 73 | CTK_WIDGET_ADD(&window, &templabel); |
| 74 | CTK_WIDGET_ADD(&window, &tempvallabel); |
| 75 | #endif |
| 76 | dispatcher_listen(ctk_signal_window_close); |
| 77 | } |
| 78 | ctk_window_open(&window); |
| 79 | } |
| 80 | /*-----------------------------------------------------------------------------------*/ |
| 81 | static void |
| 82 | sensorview_quit(void) |
| 83 | { |
| 84 | ctk_window_close(&window); |
| 85 | dispatcher_exit(&p); |
| 86 | id = EK_ID_NONE; |
| 87 | LOADER_UNLOAD(); |
| 88 | } |
| 89 | /*-----------------------------------------------------------------------------------*/ |
| 90 | static |
| 91 | DISPATCHER_SIGHANDLER(sensorview_sighandler, s, data) |
| 92 | { |
| 93 | DISPATCHER_SIGHANDLER_ARGS(s, data); |
| 94 | |
| 95 | if(s == dispatcher_signal_quit || |
| 96 | s == ctk_signal_window_close) { |
| 97 | sensorview_quit(); |
| 98 | } |
| 99 | } |
| 100 | /*-----------------------------------------------------------------------------------*/ |
| 101 | static void |
| 102 | sensorview_idle(void) |
| 103 | { |
| 104 | sprintf(tempval, "%d", sensors_temp); |
| 105 | } |
| 106 | /*-----------------------------------------------------------------------------------*/ |