00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00032 #define SW_SWITCH_FB 0
00033
00034
00035 #define SW_ON_SWITCH 0
00036
00037
00038 static param_desc_t switch_prop[] = {{2,0}};
00039 static param_desc_t switch_events[] = {{0,2}};
00040
00041
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
00107 ((SwitchAppObj*)self)->parent->Display();
00108 break;
00109 case SW_ON_SWITCH|0x80:
00110 *((snt_switch*)result) = ((SwitchAppObj*)self)->state;
00111 break;
00112 }
00113 }