From 3328c0018f364d7873b2aabaeb4284f19d586cb0 Mon Sep 17 00:00:00 2001 From: Michael Wilber Date: Wed, 25 Dec 2013 09:47:10 -0500 Subject: [PATCH] No longer read unnecessary data in -readFanData -readFanData was always reading the temperature and the speeds of all of the fans regardless of what data was displayed in the menu bar. Now, -readFanData only reads the data necessary to update the text in the menubar, so, if only the temp is displayed, only the temp is read. The updating of the fan speeds in the menu is now only done when the user clicks on the menu. Also: cleaned up some test code and deleted an unnecessary comment. --- Classes/FanControl.h | 6 +- Classes/FanControl.m | 255 +++++++++++++++++++++++++------------------ Classes/smcWrapper.m | 4 +- smc-command/smc.c | 2 +- 4 files changed, 151 insertions(+), 116 deletions(-) diff --git a/Classes/FanControl.h b/Classes/FanControl.h index 50b0df4..7069724 100755 --- a/Classes/FanControl.h +++ b/Classes/FanControl.h @@ -38,11 +38,8 @@ #define kMenuBarHeight 22 -// Max number of fans supported. -#define kMaxFanRpms 100 - -@interface FanControl : NSObject +@interface FanControl : NSObject { IBOutlet id currentSpeed; @@ -134,6 +131,7 @@ - (void) syncBinder:(Boolean)bind; - (IBAction) changeMenu:(id)sender; - (IBAction)menuSelect:(id)sender; +- (void)menuNeedsUpdate:(NSMenu*)menu; @end diff --git a/Classes/FanControl.m b/Classes/FanControl.m index 2969ad1..2ba7b7b 100755 --- a/Classes/FanControl.m +++ b/Classes/FanControl.m @@ -236,6 +236,11 @@ NSUserDefaults *defaults; for(i=0;i<[s_menus count];i++) { [theMenu insertItem:[s_menus objectAtIndex:i] atIndex:i]; }; + + // Sign up for menuNeedsUpdate call + // so that the fan speeds in the menu can be updated + // only when needed. + [theMenu setDelegate:self]; } @@ -303,123 +308,140 @@ NSUserDefaults *defaults; -(void) readFanData:(NSTimer*)timer{ int i = 0; - NSString *temp; - NSString *fan; - //on init handling if (s_sed==nil) { return; } - // Store fan speeds in simple array so that they only need to be read once. - int fanRpms[kMaxFanRpms] = { 0 }; - if (g_numFans > kMaxFanRpms) - return; - - - // Determine which fan speed to show in the menubar. - int selected = 0; - NSArray *fans = [[[FavoritesController arrangedObjects] objectAtIndex:[FavoritesController selectionIndex]] objectForKey:@"FanData"]; - for (i=0;i<[fans count];i++) - { - if ([[[fans objectAtIndex:i] objectForKey:@"menu"] boolValue]==YES) { - selected = i; + // Determine what data is actually needed to keep the energy impact + // as low as possible. + bool bNeedTemp = false; + bool bNeedRpm = false; + const int menuBarSetting = [[defaults objectForKey:@"MenuBar"] intValue]; + switch (menuBarSetting) { + default: + case 1: + bNeedTemp = true; + bNeedRpm = true; break; - } - } - if (selected < 0 || selected >= g_numFans) - { - // Bad selected fan index. - return; + + case 2: + bNeedTemp = true; + bNeedRpm = true; + break; + + case 3: + bNeedTemp = true; + bNeedRpm = false; + break; + + case 4: + bNeedTemp = false; + bNeedRpm = true; + break; + } + + NSString *temp = nil; + NSString *fan = nil; + float c_temp = 0.0f; + int selectedRpm = 0; + + if (bNeedRpm == true) { + // Read the current fan speed for the desired fan and format text for display in the menubar. + NSArray *fans = [[[FavoritesController arrangedObjects] objectAtIndex:[FavoritesController selectionIndex]] objectForKey:@"FanData"]; + for (i=0; i> 2)/64; if (c_temp>0) break; diff --git a/smc-command/smc.c b/smc-command/smc.c index b8483ee..c7e10d0 100755 --- a/smc-command/smc.c +++ b/smc-command/smc.c @@ -440,7 +440,7 @@ int main(int argc, char *argv[]) kern_return_t result; int op = OP_NONE; - UInt32Char_t key = { 0 }; //MAW + UInt32Char_t key = { 0 }; SMCVal_t val; while ((c = getopt(argc, argv, "fhk:lrw:v")) != -1)