ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/DashInterface.cpp
(Generate patch)

Comparing DashInterface/DashInterface.cpp (file contents):
Revision 30 by douglas, 2008-02-28T17:01:10-08:00 vs.
Revision 33 by douglas, 2008-02-29T19:05:18-08:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 + #include <iomanip>
8   #include <iostream>
9 + #include <sstream>
10  
11   #include <foreach.hpp>
12   #include <hash.hpp>
# Line 13 | Line 15
15   #include <Audacious.hpp>
16   #include <GPS.hpp>
17  
18 + #include <sys/types.h>
19 + #include <sys/sysctl.h>
20 + #include <sys/utsname.h>
21 +
22   #include <sqlite3.h>
23  
24   #include "Display.hpp"
25  
26   bool debug(false);
27  
28 + void Uname(Display &display, time_t now = 0)
29 + {
30 +        utsname os;
31 +
32 +        ::uname(&os);
33 +
34 +        static Pcre::RegEx version(_B("^(\\d+\\.\\d+)-([A-Z])[A-Z]*(-p\\d+)?.*$"));
35 +        Pcre::RegEx::Match match(version(os.release));
36 +
37 +        display.Set(0, 1, os.sysname + _B(" ") + match[1] + match[2] + match[3]);
38 +
39 +        int mib[] = { CTL_KERN, KERN_BOOTTIME };
40 +        timeval boottime;
41 +        size_t size(sizeof (boottime));
42 +
43 +        if (now && ::sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0)
44 +        {
45 +                time_t uptime(now - boottime.tv_sec);
46 +
47 +                if (uptime > 60)
48 +                        uptime += 30;
49 +
50 +                std::ostringstream output;
51 +
52 +                output << _B("up ") << (uptime / 86400) << '+';
53 +
54 +                uptime %= 86400;
55 +
56 +                output.width(2);
57 +                output.fill('0');
58 +
59 +                output << (uptime / 3600) << ':';
60 +
61 +                uptime %= 3600;
62 +
63 +                output << (uptime / 60) << ':' << (uptime % 60);
64 +                output << std::string(20 - output.str().size(), ' ');
65 +
66 +                display.Set(0, 2, output.str());
67 +        }
68 +        else
69 +                display.Set(0, 2, _B("up -+--:--:--       "));
70 +
71 +        double averages[3];
72 +
73 +        if (::getloadavg(averages, 3) == -1 || !now)
74 +                display.Set(0, 3, _B("-.--, -.--, -.--    "));
75 +        else
76 +        {
77 +                std::ostringstream output;
78 +
79 +                output << std::fixed << std::setprecision(2) << averages[0] << _B(", ") << averages[1] << _B(", ") << averages[2];
80 +                output << std::string(20 - output.str().size(), ' ');
81 +
82 +                display.Set(0, 3, output.str());
83 +        }
84 + }
85 +
86   int main(int argc, char *argv[])
87   {
88          std::string device;
# Line 58 | Line 122 | usage: std::cout << _B("Usage: ") << arg
122                  //Audacious audacious;
123                  Display display(device);
124  
61                display.Ping("Hello!");
62
63                std::cout << display.Version() << std::endl;
64
65                display.Store();
125                  display.Clear();
126                  display.SetBacklight(100);
127 <                display.KeyReporting(Display::Up | Display::Enter | Display::Cancel | Display::Left | Display::Right | Display::Down, Display::Up | Display::Enter | Display::Cancel | Display::Left | Display::Right | Display::Down);
69 <                display.Set(0, 0, _B("Hello, World!"));
127 >                display.Set(2, 0, _B("--:--:-- -- ---"));
128                  display.Set(0, Display::Green, 0);
129                  display.Set(0, Display::Red, 100);
130  
131 +                {
132 +                        uint8_t mask(Display::Up | Display::Enter | Display::Cancel | Display::Left | Display::Right | Display::Down);
133 +
134 +                        display.KeyReporting(mask, mask);
135 +                }
136 +
137 +                ::Uname(display);
138 +
139 +                display.Store();
140 +
141 +                ::Uname(display, std::time(NULL));
142 +
143                  /*GPS::GPS gps;
144  
145                  gps.Query(_B("o"));
146  
147                  std::cout << gps.GetLatitude() << std::endl;*/
148 +
149 +                /*time_t now(std::time(NULL));
150 +                char when[16];
151 +
152 +                std::strftime(when, sizeof (when), "%l:%M:%S %p %Z", std::localtime(&now));*/
153          }
154          catch (const std::exception &exception)
155          {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines