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/dimmer.h"
00030
00031
00032 #define SW_SWITCH_FB 0
00033
00034
00035 #define SW_ON_SWITCH 0
00036
00037
00038 static param_desc_t dimmer_prop[] = {{2,0}};
00039 static param_desc_t dimmer_events[] = {{0,2}};
00040
00041
00042 static void DimmerAppObj_Callback(void *self, uint8_t method, uint8_t *buf, uint8_t *result, uint8_t repeated);
00043
00044
00045 Dimmer::Dimmer(void)
00046 {
00047 struct DimmerAppObj *app;
00048
00049 app = new DimmerAppObj;
00050 app->property_sizes = dimmer_prop;
00051 app->event_sizes = dimmer_events;
00052 app->Callback = DimmerAppObj_Callback;
00053 app->state.value = 0xff;
00054 app->parent = this;
00055 app->id = app_register_obj((struct AppObject*)app, 1);
00056
00057 this->app = app;
00058 }
00059
00060 bool Dimmer::Activate(void)
00061 {
00062 menu_set_hook(2, i_tray_dim_down, this);
00063 menu_set_hook(3, i_tray_dim_up, this);
00064 menu_set_hook(4, i_tray_switch_off, this);
00065 menu_set_hook(5, i_tray_switch_on, this);
00066 keys_set_repeat_mask(REP_FUNC_3|REP_FUNC_4);
00067 keys_set_leds(LED_FUNC_3|LED_FUNC_4|LED_FUNC_5|LED_FUNC_6|LED_MENU_UP|LED_MENU_DOWN);
00068 return VisibleObject::Activate();
00069 }
00070
00071 void Dimmer::Deactivate(void)
00072 {
00073 VisibleObject::Deactivate();
00074 menu_remove_hook(2);
00075 menu_remove_hook(3);
00076 menu_remove_hook(4);
00077 menu_remove_hook(5);
00078 }
00079
00080 void Dimmer::Display(void)
00081 {
00082 if (active) {
00083 if (app->state.state) {
00084 lcd_put_image(x, y, i_dim_on);
00085 } else {
00086 lcd_put_image(x, y, i_dim_off);
00087 }
00088 } else {
00089 if (app->state.state) {
00090 lcd_put_image(x, y, i_dim_on_na);
00091 } else {
00092 lcd_put_image(x, y, i_dim_off_na);
00093 }
00094 }
00095 lcd_h_line(x+13, x+13+((47*app->state.value) >> 8), y+2);
00096 lcd_h_line(x+13, x+13+((45*app->state.value) >> 8), y+3);
00097 lcd_h_line(x+13, x+13+((41*app->state.value) >> 8), y+4);
00098 }
00099
00100 void Dimmer::KeyCallback(uint8_t key)
00101 {
00102 switch (key) {
00103 case 2: if (app->state.value > 5)
00104 app->state.value -= 5;
00105 else
00106 app->state.value = 0;
00107 app->state.state = 1;
00108 break;
00109 case 3: if (app->state.value < 250)
00110 app->state.value += 5;
00111 else
00112 app->state.value = 255;
00113 app->state.state = 1;
00114 break;
00115 case 4: app->state.state = 0; break;
00116 case 5: app->state.state = 1; break;
00117 }
00118 app_trigger_event(app->id, SW_ON_SWITCH);
00119 Display();
00120 }
00121
00122
00123 static void DimmerAppObj_Callback(void *self, uint8_t method, uint8_t *buf, uint8_t *result, uint8_t repeated)
00124 {
00125 switch (method) {
00126 case SW_SWITCH_FB:
00127 ((struct DimmerAppObj*)self)->state = *((snt_switch*)buf);
00128
00129 ((struct DimmerAppObj*)self)->parent->Display();
00130 break;
00131 case SW_ON_SWITCH|0x80:
00132 *((snt_switch*)result) = ((struct DimmerAppObj*)self)->state;
00133 break;
00134 }
00135 }