Moved the CPU speed "clearing" function from Pulse to cpu_type.h header.

It's now also used by AboutHaiku.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13569 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-07-09 21:01:23 +00:00
parent 04d45bdb27
commit 26ca407bfc
4 changed files with 39 additions and 37 deletions
+27 -2
View File
@@ -1,10 +1,10 @@
/* /*
* Copyright 2004, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2005, Axel Dörfler, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
/* Taken from the Pulse application, and extended. /* Taken from the Pulse application, and extended.
* It's used by Pulse and sysinfo. * It's used by Pulse, AboutHaiku, and sysinfo.
*/ */
#ifdef __cplusplus #ifdef __cplusplus
@@ -14,6 +14,7 @@ extern "C" {
const char *get_cpu_vendor_string(enum cpu_types type); const char *get_cpu_vendor_string(enum cpu_types type);
const char *get_cpu_model_string(enum cpu_types type); const char *get_cpu_model_string(enum cpu_types type);
void get_cpu_type(char *vendorBuffer, size_t vendorSize, char *modelBuffer, size_t modelSize); void get_cpu_type(char *vendorBuffer, size_t vendorSize, char *modelBuffer, size_t modelSize);
int32 get_rounded_cpu_speed(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
@@ -202,3 +203,27 @@ get_cpu_type(char *vendorBuffer, size_t vendorSize, char *modelBuffer, size_t mo
strlcpy(modelBuffer, model, modelSize); strlcpy(modelBuffer, model, modelSize);
#endif #endif
} }
int32
get_rounded_cpu_speed(void)
{
system_info sys_info;
get_system_info(&sys_info);
int target = sys_info.cpu_clock_speed / 1000000;
int frac = target % 100;
int delta = -frac;
int at = 0;
int freqs[] = { 100, 50, 25, 75, 33, 67, 20, 40, 60, 80, 10, 30, 70, 90 };
for (uint x = 0; x < sizeof(freqs) / sizeof(freqs[0]); x++) {
int ndelta = freqs[x] - frac;
if (abs(ndelta) < abs(delta)) {
at = freqs[x];
delta = ndelta;
}
}
return target + delta;
}
+4 -3
View File
@@ -207,10 +207,11 @@ AboutView::AboutView(const BRect &r)
r.OffsetBy(0, labelHeight); r.OffsetBy(0, labelHeight);
r.bottom = r.top + textHeight; r.bottom = r.top + textHeight;
if (systemInfo.cpu_clock_speed < 1000000000) int32 clockSpeed = get_rounded_cpu_speed();
sprintf(string,"%d MHz", int(systemInfo.cpu_clock_speed / 1000000.0f)); if (clockSpeed < 1000000000)
sprintf(string,"%ld MHz", clockSpeed);
else else
sprintf(string,"%.2f GHz", systemInfo.cpu_clock_speed / 1000000000.0f); sprintf(string,"%.2f GHz", clockSpeed / 1000.0f);
stringView = new BStringView(r, "mhztext", string); stringView = new BStringView(r, "mhztext", string);
fInfoView->AddChild(stringView); fInfoView->AddChild(stringView);
+7 -30
View File
@@ -124,29 +124,6 @@ NormalPulseView::CalculateFontSize()
} }
int
NormalPulseView::CalculateCPUSpeed()
{
system_info sys_info;
get_system_info(&sys_info);
int target = sys_info.cpu_clock_speed / 1000000;
int frac = target % 100;
int delta = -frac;
int at = 0;
int freqs[] = { 100, 50, 25, 75, 33, 67, 20, 40, 60, 80, 10, 30, 70, 90 };
for (uint x = 0; x < sizeof(freqs) / sizeof(freqs[0]); x++) {
int ndelta = freqs[x] - frac;
if (abs(ndelta) < abs(delta)) {
at = freqs[x];
delta = ndelta;
}
}
return target + delta;
}
void void
NormalPulseView::DetermineVendorAndProcessor() NormalPulseView::DetermineVendorAndProcessor()
{ {
@@ -215,12 +192,12 @@ NormalPulseView::Draw(BRect rect)
#endif #endif
// Draw processor type and speed // Draw processor type and speed
char buf[500]; char buffer[64];
int cpu_speed = CalculateCPUSpeed(); int32 cpuSpeed = get_rounded_cpu_speed();
if (cpu_speed > 1000 && (cpu_speed % 10) == 0) if (cpuSpeed > 1000 && (cpuSpeed % 10) == 0)
sprintf(buf, "%.2f GHz", cpu_speed / 1000.0f); snprintf(buffer, sizeof(buffer), "%.2f GHz", cpuSpeed / 1000.0f);
else else
sprintf(buf, "%d MHz", cpu_speed); snprintf(buffer, sizeof(buffer), "%d MHz", cpuSpeed);
SetDrawingMode(B_OP_OVER); SetDrawingMode(B_OP_OVER);
SetHighColor(240, 240, 240); SetHighColor(240, 240, 240);
SetFontSize(fProcessorFontSize); SetFontSize(fProcessorFontSize);
@@ -229,9 +206,9 @@ NormalPulseView::Draw(BRect rect)
MovePenTo(10 + (32 - width / 2), 48); MovePenTo(10 + (32 - width / 2), 48);
DrawString(fProcessor); DrawString(fProcessor);
width = StringWidth(buf); width = StringWidth(buffer);
MovePenTo(10 + (32 - width / 2), 60); MovePenTo(10 + (32 - width / 2), 60);
DrawString(buf); DrawString(buffer);
PopState(); PopState();
} }
-1
View File
@@ -28,7 +28,6 @@ class NormalPulseView : public PulseView {
void UpdateColors(BMessage *message); void UpdateColors(BMessage *message);
private: private:
int CalculateCPUSpeed();
void DetermineVendorAndProcessor(); void DetermineVendorAndProcessor();
void CalculateFontSize(); void CalculateFontSize();