00001 #include "flGlobal.h"
00002 #if FL_NOTIFY != 0
00003 #include <stdio.h>
00004 #include <psprtc.h>
00005 #include <pspkernel.h>
00006 #include <psppower.h>
00007 #include <pspimpose_driver.h>
00008
00009 #if FL_INCLUDE_ALL_C == 0
00010 #include "flNotify.h"
00011 #include "flMemory.h"
00012 #include "flTimer.h"
00013 #include "flDebug.h"
00014 #include "flGraphics.h"
00015 #include "flGraphics2d.h"
00016 #include "flFont.h"
00017 #endif
00018
00019 #if FL_KERNELMODE
00020 int ntfyVolLast = -1;
00021 int ntfyVolMuteLast = -1;
00022 float ntfyVolTime = 0.0f;
00023 Timer* ntfyVolTimer = NULL;
00024 #endif
00025
00026 int ntfyBattChrgLast = -1;
00027 int ntfyBattPercentLast = -1;
00028 int ntfyBattLowLast = -1;
00029 float ntfyBattTime = 0.0f;
00030 Timer* ntfyBattTimer = NULL;
00031
00032 pspTime ntfyTimeLast;
00033 float ntfyTimeTime = 0.0f;
00034 Timer* ntfyTimeTimer = NULL;
00035
00036 #if FL_NOTIFY_TRAYSIZE
00037 NotifyTrayItem ntfyTray[FL_NOTIFY_TRAYSIZE];
00038 Timer* ntfyTrayTimer = NULL;
00039 #endif
00040
00041 u32 ntfyTickCount = 0;
00042 bool ntfyInitialized = false;
00043 bool ntfyVisible = true;
00044
00045
00046 void ntfyInit() {
00047 sceRtcGetCurrentClockLocalTime(&ntfyTimeLast);
00048
00049 #if FL_NOTIFY_TRAYSIZE
00050 u32 i;
00051 for(i = 0; i < FL_NOTIFY_TRAYSIZE; i++)
00052 ntfyTray[i].ntiTime = 0.0f;
00053 ntfyTrayTimer = timerCreate();
00054 #endif
00055
00056 #if FL_KERNELMODE
00057 ntfyVolTimer = timerCreate();
00058 #endif
00059
00060 ntfyBattTimer = timerCreate();
00061
00062 ntfyTimeTimer = timerCreate();
00063
00064 ntfyInitialized = true;
00065 }
00066
00067 void ntfyTick() {
00068 if(!ntfyInitialized)
00069 return;
00070
00071 ntfyTickCount++;
00072 if(ntfyTickCount > FL_NOTIFY_FREQUENCY) {
00073 float tempTick;
00074
00075 #if FL_KERNELMODE
00076 tempTick = timerGetDeltaTime(ntfyVolTimer);
00077 if(ntfyVolTime > 0.0f) {
00078 ntfyVolTime -= tempTick;
00079 if(ntfyVolTime < 0.0f)
00080 ntfyVolTime = 0.0f;
00081 }
00082 #if FL_NOTIFY_VOLUME
00083 ntfyCheckVolume();
00084 #endif
00085 #endif
00086
00087 tempTick = timerGetDeltaTime(ntfyBattTimer);
00088 if(ntfyBattTime > 0.0f) {
00089 ntfyBattTime -= tempTick;
00090 if(ntfyBattTime < 0.0f)
00091 ntfyBattTime = 0.0f;
00092 }
00093 #if FL_NOTIFY_BATTERY
00094 ntfyCheckBattery();
00095 #endif
00096
00097 tempTick = timerGetDeltaTime(ntfyTimeTimer);
00098 if(ntfyTimeTime > 0.0f) {
00099 ntfyTimeTime -= tempTick;
00100 if(ntfyTimeTime < 0.0f)
00101 ntfyTimeTime = 0.0f;
00102 }
00103 #if FL_NOTIFY_TIME
00104 ntfyCheckTime();
00105 #endif
00106
00107 #if FL_NOTIFY_TRAYSIZE
00108 ntfyTrayTick();
00109 #endif
00110
00111 ntfyTickCount = 0;
00112 }
00113 #if FL_NOTIFY_VOLUME
00114 if(ntfyVolTime > 0.0f)
00115 ntfyShowVolume();
00116 #endif
00117 #if FL_NOTIFY_BATTERY
00118 if(ntfyBattTime > 0.0f)
00119 ntfyShowBattery();
00120 #endif
00121 #if FL_NOTIFY_TIME
00122 if(ntfyTimeTime > 0.0f)
00123 ntfyShowTime();
00124 #endif
00125
00126 #if FL_NOTIFY_TRAYSIZE
00127 ntfyTrayShow();
00128 #endif
00129 }
00130
00131 void ntfyShowAll(float inTime) {
00132 #if FL_NOTIFY_VOLUME
00133 ntfyShowVolume();
00134 ntfyVolTime = inTime;
00135 #endif
00136 #if FL_NOTIFY_BATTERY
00137 ntfyShowBattery();
00138 ntfyBattTime = inTime;
00139 #endif
00140 #if FL_NOTIFY_TIME
00141 ntfyShowTime();
00142 ntfyTimeTime = inTime;
00143 #endif
00144 #if FL_NOTIFY_TIME
00145 ntfyShowDate();
00146 #endif
00147 }
00148
00149 #if FL_KERNELMODE
00150 void ntfyCheckVolume() {
00151 if(!ntfyInitialized)
00152 return;
00153
00154 int tempVol = sceImposeGetParam(PSP_IMPOSE_MAIN_VOLUME);
00155 int tempVolMute = sceImposeGetParam(PSP_IMPOSE_MUTE);
00156
00157 if((tempVol >= 0) && (ntfyVolLast != tempVol)) {
00158 ntfyVolLast = tempVol;
00159 if((ntfyVolLast >= 0) && (ntfyVolTime < FL_NOTIFY_DURATION))
00160 ntfyVolTime = FL_NOTIFY_DURATION;
00161 }
00162 if((tempVolMute >= 0) && (ntfyVolMuteLast != tempVolMute)) {
00163 if((ntfyVolMuteLast >= 0) && (ntfyVolTime < FL_NOTIFY_DURATION))
00164 ntfyVolTime = FL_NOTIFY_DURATION;
00165 ntfyVolMuteLast = tempVolMute;
00166 }
00167 }
00168 #endif
00169
00170 void ntfyCheckBattery() {
00171 if(!ntfyInitialized)
00172 return;
00173
00174 int tempBattLow = scePowerIsLowBattery();
00175 int tempCharge = scePowerIsPowerOnline();
00176 int tempPercent = scePowerGetBatteryLifePercent();
00177
00178 if(tempBattLow > 0) {
00179 if(ntfyBattTime < FL_NOTIFY_DURATION)
00180 ntfyBattTime = FL_NOTIFY_DURATION;
00181 #if FL_DEBUG_STATUS
00182 if(ntfyBattLowLast != 0)
00183 debugStatusLog("Battery low.");
00184 #endif
00185 ntfyBattLowLast = tempBattLow;
00186 }
00187
00188 if((tempCharge >= 0) && (tempCharge != ntfyBattChrgLast)) {
00189 if((ntfyBattChrgLast >= 0) && (ntfyBattTime < FL_NOTIFY_DURATION))
00190 ntfyBattTime = FL_NOTIFY_DURATION;
00191 ntfyBattChrgLast = tempCharge;
00192 #if FL_DEBUG_STATUS
00193 if(tempCharge > 0)
00194 debugStatusLog("AC plugged in.");
00195 else
00196 debugStatusLog("AC removed.");
00197 #endif
00198 }
00199
00200 if((ntfyBattPercentLast >= 0) && (ntfyBattTime < FL_NOTIFY_DURATION)) {
00201 if((tempPercent < 75) && (ntfyBattPercentLast > 75))
00202 ntfyBattTime = FL_NOTIFY_DURATION;
00203 else if((tempPercent > 75) && (ntfyBattPercentLast < 75))
00204 ntfyBattTime = FL_NOTIFY_DURATION;
00205 else if((tempPercent < 50) && (ntfyBattPercentLast > 50))
00206 ntfyBattTime = FL_NOTIFY_DURATION;
00207 else if((tempPercent > 50) && (ntfyBattPercentLast < 50))
00208 ntfyBattTime = FL_NOTIFY_DURATION;
00209 else if((tempPercent < 25) && (ntfyBattPercentLast > 25))
00210 ntfyBattTime = FL_NOTIFY_DURATION;
00211 else if((tempPercent > 25) && (ntfyBattPercentLast < 25))
00212 ntfyBattTime = FL_NOTIFY_DURATION;
00213 }
00214 ntfyBattPercentLast = tempPercent;
00215 }
00216
00217 void ntfyCheckTime() {
00218 if(!ntfyInitialized)
00219 return;
00220
00221 pspTime tempTime;
00222 sceRtcGetCurrentClockLocalTime(&tempTime);
00223
00224 if((tempTime.hour != ntfyTimeLast.hour) && (ntfyTimeTime < FL_NOTIFY_DURATION))
00225 ntfyTimeTime = FL_NOTIFY_DURATION;
00226 else if((ntfyTimeLast.minutes != tempTime.minutes) && (ntfyTimeTime < FL_NOTIFY_DURATION)) {
00227 if((tempTime.minutes == 15) || (tempTime.minutes == 30) || (tempTime.minutes == 45))
00228 ntfyTimeTime = FL_NOTIFY_DURATION;
00229 }
00230
00231 ntfyTimeLast = tempTime;
00232 }
00233
00234 #if FL_KERNELMODE
00235 void ntfyShowVolume() {
00236 if(!ntfyVisible)
00237 return;
00238
00239 int tempVol = sceImposeGetParam(PSP_IMPOSE_MAIN_VOLUME);
00240 int tempVolMute = sceImposeGetParam(PSP_IMPOSE_MUTE);
00241 if(tempVol < 0) {
00242 #if FL_DEBUG_WARNING != 0
00243 debugWarning("Error retrieving volume percentage.");
00244 #endif
00245 return;
00246 }
00247 graphics2dDrawRectFilled(24, (SCREEN_HEIGHT - 12), (SCREEN_WIDTH - 28), 8, 0x7F7F7F7F);
00248 if(tempVol > 0) {
00249 tempVol *= (SCREEN_WIDTH - 28);
00250 tempVol /= 30;
00251 graphics2dDrawRectFilled(24, (SCREEN_HEIGHT - 12), tempVol, 8, 0xFFFFFFFF);
00252 }
00253
00254 if(tempVolMute > 0) {
00255 graphics2dDrawLine(8, (SCREEN_HEIGHT - 12), 16, (SCREEN_HEIGHT - 4), 0xFF0000FF);
00256 graphics2dDrawLine(16, (SCREEN_HEIGHT - 12), 8, (SCREEN_HEIGHT - 4), 0xFF0000FF);
00257 }
00258 }
00259 #endif
00260
00261 void ntfyShowBattery() {
00262 if(!ntfyVisible)
00263 return;
00264
00265 int tempBatt = scePowerGetBatteryLifePercent();
00266 int tempLowBatt = scePowerIsLowBattery();
00267 int tempAC = scePowerIsPowerOnline();
00268 if(tempBatt < 0) {
00269 #if FL_DEBUG_WARNING != 0
00270 debugWarning("Error retrieving battery percentage.");
00271 #endif
00272 return;
00273 }
00274 if(tempAC < 0)
00275 tempAC = 0;
00276
00277 u32 tempWidth = 32;
00278 u32 tempHeight = 12;
00279 u32 tempX = (SCREEN_WIDTH - (tempWidth + 4));
00280 u32 tempY = 4;
00281
00282 graphics2dDrawRectFilled(tempX, tempY, tempWidth, tempHeight, 0x7F7F7F7F);
00283 graphics2dDrawRectFilled((tempX + 1), tempY, ((tempBatt * (tempWidth - 2)) / 100), tempHeight, (tempAC ? 0xFF00DFFF : (tempLowBatt > 0 ? 0x7F0000FF : 0x7F00FF00)));
00284 graphics2dDrawRect(tempX, tempY, tempWidth, tempHeight, 0xFFFFFFFF);
00285 graphics2dDrawLine((tempX + tempWidth), (tempY + 3), (tempX + tempWidth), ((tempY + tempHeight) - 3), 0xFFFFFFFF);
00286
00287 #if FL_FONT
00288 char tempString[16];
00289 if(tempAC)
00290 sprintf(tempString, "AC");
00291 else
00292 sprintf(tempString, "%i", tempBatt);
00293
00294 u32 tempFontWidth = fontStringWidth(fontDefault, tempString);
00295 u32 tempFontHeight = fontHeight(fontDefault);
00296 fontDraw2dString((tempX + ((tempWidth - tempFontWidth) >> 1)), (tempY + ((tempHeight - tempFontHeight) >> 1)), fontDefault, tempString);
00297 #endif
00298 }
00299
00300 void ntfyShowTime() {
00301 if(!ntfyVisible)
00302 return;
00303
00304 pspTime tempTime;
00305 sceRtcGetCurrentClockLocalTime(&tempTime);
00306
00307 u32 tempWidth = 56;
00308 u32 tempHeight = 12;
00309 u32 tempX = (SCREEN_WIDTH - (tempWidth + 40));
00310 u32 tempY = 4;
00311
00312 graphics2dDrawRectFilled((tempX + (tempHeight >> 1)), tempY, (tempWidth - (tempHeight >> 1)), tempHeight, 0xFF7F7F7F);
00313 graphics2dDrawEllipseFilled(tempX, tempY, tempHeight, tempHeight, 0xFF7F7F7F);
00314 graphics2dDrawEllipse(tempX, tempY, tempHeight, tempHeight, 0xFFFFFFFF);
00315 graphics2dDrawLine((tempX + (tempHeight >> 1)), (tempY + (tempHeight >> 1)), (tempX + (tempHeight >> 1)), tempY, 0xFFFFFFFF);
00316 graphics2dDrawLine((tempX + (tempHeight >> 1)), (tempY + (tempHeight >> 1)), (tempX + tempHeight), (tempY + (tempHeight >> 1)), 0xFFFFFFFF);
00317
00318 #if FL_FONT
00319 char tempString[16];
00320 sprintf(tempString, "%02u:%02u", (unsigned int)tempTime.hour, (unsigned int)tempTime.minutes);
00321
00322 u32 tempFontHeight = fontHeight(fontDefault);
00323 fontDraw2dString((tempX + tempHeight + 4), (tempY + ((tempHeight - tempFontHeight) >> 1)), fontDefault, tempString);
00324 #endif
00325 }
00326
00327 void ntfyShowDate() {
00328
00329 }
00330
00331 #if FL_NOTIFY_TRAYSIZE
00332 void ntfyTrayAdd(char* inMessage, u32 inColor) {
00333 if(!ntfyInitialized || !inMessage || !inMessage[0])
00334 return;
00335
00336 int i;
00337 #if FL_NOTIFY_TRAYSIZE > 1
00338 for(i = (FL_NOTIFY_TRAYSIZE - 2); i >= 0 ; i--)
00339 ntfyTray[i + 1] = ntfyTray[i];
00340 #endif
00341 for(i = 0; i < 255; i++)
00342 ntfyTray[0].ntiMessage[i] = inMessage[i];
00343 ntfyTray[0].ntiMessage[255] = 0;
00344 ntfyTray[0].ntiColor = inColor;
00345 ntfyTray[0].ntiTime = (FL_NOTIFY_DURATION * 2.0f);
00346 }
00347
00348 void ntfyTrayTick() {
00349 if(!ntfyInitialized)
00350 return;
00351
00352 float tempTick = timerGetDeltaTime(ntfyTrayTimer);
00353
00354 u32 i;
00355 for(i = 0; i < FL_NOTIFY_TRAYSIZE; i++) {
00356 if(ntfyTray[i].ntiTime > 0.0f)
00357 ntfyTray[i].ntiTime -= tempTick;
00358 if(ntfyTray[i].ntiTime < 0.0f)
00359 ntfyTray[i].ntiTime = 0.0f;
00360 }
00361 }
00362
00363 void ntfyTrayShow() {
00364 if(!ntfyVisible)
00365 return;
00366
00367 int tempY = SCREEN_HEIGHT;
00368
00369 u32 i;
00370 for(i = 0; i < FL_NOTIFY_TRAYSIZE; i++) {
00371 tempY -= fontHeight(fontDefault);
00372
00373 if(ntfyTray[i].ntiTime <= 0.0f)
00374 continue;
00375
00376 graphics2dDrawRectFilled(0, tempY, SCREEN_WIDTH, fontHeight(fontDefault), ((ntfyTray[i].ntiColor & 0x00FFFFFF) | 0xBF000000));
00377 fontDraw2dString(0, tempY, fontDefault, ntfyTray[i].ntiMessage);
00378 }
00379 }
00380 #endif
00381
00382 #endif