60 TRAP_IGNORE(iOtgWatcher.VBusObserver()->UnsubscribeL(*this)); |
59 TRAP_IGNORE(iOtgWatcher.VBusObserver()->UnsubscribeL(*this)); |
61 } |
60 } |
62 |
61 |
63 // Unsubscribe from otg watcher states change notifications |
62 // Unsubscribe from otg watcher states change notifications |
64 TRAP_IGNORE(iOtgWatcher.UnsubscribeL(*this)); |
63 TRAP_IGNORE(iOtgWatcher.UnsubscribeL(*this)); |
|
64 |
|
65 delete iUsbConnectingIndicator; |
65 } |
66 } |
66 |
67 |
67 // --------------------------------------------------------------------------- |
68 // --------------------------------------------------------------------------- |
68 // C++ constructor |
69 // C++ constructor |
69 // --------------------------------------------------------------------------- |
70 // --------------------------------------------------------------------------- |
70 // |
71 // |
71 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager& aNotifManager, |
72 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager& aNotifManager, |
72 CUsbOtgWatcher& aOtgWatcher) : |
73 CUsbOtgWatcher& aOtgWatcher) : |
73 CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL), iOtgWatcher( |
74 iOtgWatcher(aOtgWatcher) |
74 aOtgWatcher) |
75 { |
75 { |
76 LOG_FUNC |
76 LOG_FUNC |
77 |
77 |
|
78 //To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer |
|
79 //when AVKON implements animation form of usb indicator. |
|
80 iIndicatorState = EAknIndicatorStateOn; |
|
81 } |
78 } |
82 |
79 |
83 // --------------------------------------------------------------------------- |
80 // --------------------------------------------------------------------------- |
84 // Second-phase constructor |
81 // Second-phase constructor |
85 // --------------------------------------------------------------------------- |
82 // --------------------------------------------------------------------------- |
86 // |
83 // |
87 void CUsbIndicatorNotifier::ConstructL() |
84 void CUsbIndicatorNotifier::ConstructL() |
88 { |
85 { |
89 LOG_FUNC |
86 LOG_FUNC |
90 |
87 |
|
88 iUsbConnectingIndicator = CHbIndicatorSymbian::NewL(); |
|
89 |
91 // Subscribe for VBus change notifications |
90 // Subscribe for VBus change notifications |
92 iOtgWatcher.VBusObserver()->SubscribeL(*this); |
91 iOtgWatcher.VBusObserver()->SubscribeL(*this); |
93 |
92 |
94 // Subscribe for otg watcher states change notifications |
93 // Subscribe for otg watcher states change notifications |
95 iOtgWatcher.SubscribeL(*this); |
94 iOtgWatcher.SubscribeL(*this); |
96 |
95 |
|
96 iConnectingIndicatorOn = EFalse; |
|
97 |
97 // check here for condition to set usb indicator |
98 // check here for condition to set usb indicator |
98 SetIndicatorL(); |
99 SetIndicator(); |
99 } |
100 |
100 |
101 } |
101 // --------------------------------------------------------------------------- |
102 |
102 // Show/hide static icon of the indicator. |
|
103 // If the indicator is blinking, stop blinking it and show/hide the static |
|
104 // form of the indicator. |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 void CUsbIndicatorNotifier::ShowStaticL(TBool aVisible) |
|
108 { |
|
109 LOG_FUNC |
|
110 |
|
111 LOG1("aVisible = %d" , aVisible); |
|
112 |
|
113 SetIndicatorStateL(aVisible |
|
114 ? EAknIndicatorStateOn |
|
115 : EAknIndicatorStateOff); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CUsbIndicatorNotifier::BlinkL() |
|
123 { |
|
124 LOG_FUNC |
|
125 |
|
126 SetIndicatorStateL( EAknIndicatorStateAnimate ); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // From base class CUsbNotifier |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CUsbIndicatorNotifier::ShowL() |
|
134 { |
|
135 LOG_FUNC |
|
136 |
|
137 ShowStaticL(ETrue); |
|
138 } |
|
139 |
103 |
140 // --------------------------------------------------------------------------- |
104 // --------------------------------------------------------------------------- |
141 // From CUsbNotifier |
105 // From CUsbNotifier |
142 // --------------------------------------------------------------------------- |
106 // --------------------------------------------------------------------------- |
143 // |
107 // |
144 void CUsbIndicatorNotifier::Close() |
108 void CUsbIndicatorNotifier::Close() |
145 { |
109 { |
146 LOG_FUNC |
110 LOG_FUNC |
147 |
111 |
148 TRAP_IGNORE( ShowStaticL(EFalse) ); |
112 ToggleConnectingIndicator( EFalse ); |
149 } |
113 } |
150 |
114 |
151 // --------------------------------------------------------------------------- |
115 // --------------------------------------------------------------------------- |
152 // Set USB indicator On or Off |
116 // Set USB indicator On or Off |
153 // --------------------------------------------------------------------------- |
117 // --------------------------------------------------------------------------- |
154 // |
118 // |
155 void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState) |
119 void CUsbIndicatorNotifier::ToggleConnectingIndicator(TBool aEnable) |
156 { |
120 { |
157 |
121 LOG1( "toggle connecting indicator = %d" , aEnable); |
158 LOG1( "USB indicator State = %d" , aState); |
122 |
159 |
123 TBool success = ETrue; |
160 CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid( |
124 |
161 EAknIndicatorUSBConnection)); |
125 if (aEnable && !iConnectingIndicatorOn) |
162 indicator->SetIndicatorStateL(aState); |
126 { |
163 CleanupStack::PopAndDestroy(indicator); //indicator |
127 success = iUsbConnectingIndicator->Activate(KUsbConnectingIndicator); |
164 } |
128 LOG1( "calling CHbIndicatorSymbian::Activate(), returned %d", success); |
165 |
129 if (success) |
|
130 { |
|
131 iConnectingIndicatorOn = ETrue; |
|
132 } |
|
133 |
|
134 } |
|
135 |
|
136 if (!aEnable && iConnectingIndicatorOn) |
|
137 { |
|
138 success = iUsbConnectingIndicator->Deactivate(KUsbConnectingIndicator); |
|
139 if (success) |
|
140 { |
|
141 iConnectingIndicatorOn = EFalse; |
|
142 } |
|
143 LOG1( "calling CHbIndicatorSymbian::Deactivate(), returned %d", success); |
|
144 } |
|
145 |
|
146 // if success became false loading the indicator failed, log the error |
|
147 if (!success) |
|
148 { |
|
149 TInt error = iUsbConnectingIndicator->Error(); |
|
150 LOG1( "indicator error is %d", error); |
|
151 } |
|
152 } |
|
153 |
166 // --------------------------------------------------------------------------- |
154 // --------------------------------------------------------------------------- |
167 // |
155 // |
168 // --------------------------------------------------------------------------- |
156 // --------------------------------------------------------------------------- |
169 // |
157 // |
170 void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState) |
158 void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState) |
171 { |
159 { |
172 SetIndicatorL(); |
160 LOG_FUNC |
|
161 SetIndicator(); |
173 } |
162 } |
174 |
163 |
175 // --------------------------------------------------------------------------- |
164 // --------------------------------------------------------------------------- |
176 // |
165 // |
177 // --------------------------------------------------------------------------- |
166 // --------------------------------------------------------------------------- |
178 // |
167 // |
179 void CUsbIndicatorNotifier::VBusDownL() |
168 void CUsbIndicatorNotifier::VBusDownL() |
180 { |
169 { |
181 SetIndicatorL(); |
170 LOG_FUNC |
|
171 SetIndicator(); |
182 } |
172 } |
183 |
173 |
184 // --------------------------------------------------------------------------- |
174 // --------------------------------------------------------------------------- |
185 // |
175 // |
186 // --------------------------------------------------------------------------- |
176 // --------------------------------------------------------------------------- |
187 // |
177 // |
188 void CUsbIndicatorNotifier::VBusUpL() |
178 void CUsbIndicatorNotifier::VBusUpL() |
189 { |
179 { |
190 SetIndicatorL(); |
180 LOG_FUNC |
|
181 SetIndicator(); |
191 } |
182 } |
192 |
183 |
193 // --------------------------------------------------------------------------- |
184 // --------------------------------------------------------------------------- |
194 // |
185 // |
195 // --------------------------------------------------------------------------- |
186 // --------------------------------------------------------------------------- |
196 // |
187 // |
197 void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError) |
188 void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError) |
198 { |
189 { |
|
190 LOG_FUNC |
199 // do nothing |
191 // do nothing |
200 } |
192 } |
201 |
193 |
202 // --------------------------------------------------------------------------- |
194 // --------------------------------------------------------------------------- |
203 // |
195 // |
204 // --------------------------------------------------------------------------- |
196 // --------------------------------------------------------------------------- |
205 // |
197 // |
206 void CUsbIndicatorNotifier::SetIndicatorL() |
198 void CUsbIndicatorNotifier::SetIndicator() |
207 { |
199 { |
|
200 LOG_FUNC |
208 if (!(iOtgWatcher.IsDeviceA()) || iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAPeripheral) |
201 if (!(iOtgWatcher.IsDeviceA()) || iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAPeripheral) |
209 { |
202 { |
210 // if B or peripheral, than other party (usbwatcher) takes care of usb indicator |
203 // if B or peripheral, than other party (usbwatcher) takes care of usb indicator |
211 // in combined usbwatcher (if role swap allowed) one class has to manage usb indicator |
204 // in combined usbwatcher (if role swap allowed) one class has to manage usb indicator |
212 return; |
205 return; |
213 } |
206 } |
214 |
207 |
215 // if VBus Up and we are host -> show indicator |
208 // if VBus up and we are not host -> show connecting indicator |
216 if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) |
209 if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) |
217 && (iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAHost)) |
|
218 { |
|
219 ShowStaticL(ETrue); |
|
220 } |
|
221 // if VBus up and we are not host -> Blink indicator |
|
222 else if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) |
|
223 && (iOtgWatcher.CurrentHostState()->Id() != EUsbStateHostAHost)) |
210 && (iOtgWatcher.CurrentHostState()->Id() != EUsbStateHostAHost)) |
224 { |
211 { |
225 BlinkL(); |
212 ToggleConnectingIndicator( ETrue ); |
226 } |
213 } |
227 else |
214 else |
228 // Otherwise do not show indicator |
215 // Otherwise do not show indicator |
229 { |
216 { |
230 ShowStaticL(EFalse); |
217 ToggleConnectingIndicator( EFalse ); |
231 } |
218 } |
232 } |
219 } |
233 |
220 |
234 // End of file |
221 // End of file |