Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

switch.cc

00001 /***
00002  * This file is part of OpenHome, an open source home automation system.
00003  * Copyright (C) 2003 Jan Klötzke
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #include <inttypes.h>
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #include "net/application.h"
00024 #include "net/snt.h"
00025 #include "main/keys.h"
00026 #include "main/lcd.h"
00027 #include "main/rom.h"
00028 #include "main/menu.h"
00029 #include "main/switch.h"
00030 
00031 // methods
00032 #define SW_SWITCH_FB    0
00033 
00034 // events
00035 #define SW_ON_SWITCH    0
00036 
00037 // parameter tables
00038 static param_desc_t switch_prop[] = {{2,0}};
00039 static param_desc_t switch_events[] = {{0,2}};
00040 
00041 // forward definition
00042 static void SwitchAppObj_Callback(void *self, uint8_t method, uint8_t *buf, uint8_t *result, uint8_t repeated);
00043 
00044 Switch::Switch(void)
00045 {
00046         struct SwitchAppObj *app;
00047 
00048         app = new SwitchAppObj;
00049         app->property_sizes = switch_prop;
00050         app->event_sizes = switch_events;
00051         app->Callback = SwitchAppObj_Callback;
00052         app->state.value = 0xff;
00053         app->parent = this;
00054         app->id = app_register_obj((struct AppObject*)app, 1);  
00055         this->app = app;
00056 }
00057 
00058 bool Switch::Activate(void)
00059 {
00060         menu_set_hook(4, i_tray_switch_off, this);
00061         menu_set_hook(5, i_tray_switch_on, this);
00062         keys_set_repeat_mask(0);
00063         keys_set_leds(LED_FUNC_5|LED_FUNC_6|LED_MENU_UP|LED_MENU_DOWN);
00064         return VisibleObject::Activate();
00065 }
00066 
00067 void Switch::Deactivate(void)
00068 {
00069         VisibleObject::Deactivate();
00070         menu_remove_hook(4);
00071         menu_remove_hook(5);
00072 }
00073 
00074 void Switch::Display(void)
00075 {
00076         if (active) {
00077                 if (app->state.state) {
00078                         lcd_put_image(x, y, i_switch_on);
00079                 } else {
00080                         lcd_put_image(x, y, i_switch_off);
00081                 }
00082         } else {
00083                 if (app->state.state) {
00084                         lcd_put_image(x, y, i_switch_on_na);
00085                 } else {
00086                         lcd_put_image(x, y, i_switch_off_na);
00087                 }
00088         }
00089 }
00090 
00091 void Switch::KeyCallback(uint8_t key)
00092 {
00093         if (key == 4)
00094                 app->state.state = 0;
00095         else
00096                 app->state.state = 1;
00097         app_trigger_event(app->id, SW_ON_SWITCH);
00098         Display();
00099 }
00100 
00101 static void SwitchAppObj_Callback(void *self, uint8_t method, uint8_t *buf, uint8_t *result, uint8_t repeated)
00102 {
00103         switch (method) {
00104                 case SW_SWITCH_FB:
00105                         ((SwitchAppObj*)self)->state = *((snt_switch*)buf);
00106                         // FIXME: must not display if parent is hidden
00107                         ((SwitchAppObj*)self)->parent->Display();
00108                         break;
00109                 case SW_ON_SWITCH|0x80:
00110                         *((snt_switch*)result) = ((SwitchAppObj*)self)->state;
00111                         break;
00112         }
00113 }

Generated on Thu Oct 16 13:13:41 2003 for OpenHomeMainPanel by doxygen 1.3.3