Skip to content

Commit

Permalink
working on #10
Browse files Browse the repository at this point in the history
  • Loading branch information
amagura committed Mar 1, 2015
1 parent 48a9001 commit ce3d438
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 33 deletions.
10 changes: 10 additions & 0 deletions src/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,20 @@ int get_ac_info(bool *acline, char *acfile)

void read_pwr_files(struct pwr_sup *info, struct error *err, char *ac, char *batt, int btnum)
{

ZB_DBG("info->cap before: %d\n", info->cap);
zb_ping;
zb_eset((err), get_ac_info(&(info->acline), ac));
zb_eset((err), get_batt_info(&(info->cap), batt, btnum));
if (info->acline == 0 && info->cap == 0) {
/* power supply is most likely broken... or this is a test.... Did we pass? :P */
zb_eset((err), PWR_EBRK);
}
zb_ping;
ZB_DBG("info->cap after: %d\n", info->cap);
zb_eset((err), get_ac_info(&(info->acline), ac));
zb_pong;
ZB_DBG("*err->vp: %d\n", *err->vp);
}

# if ZB_USE_KCAT
Expand Down
11 changes: 10 additions & 1 deletion src/main-text.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@ void disp(struct txt_disp_opts opts, struct power pwr)
}
return;
}
ZB_DBG("pwr.charge.tr: %d\n", pwr.charge.tr);

if (pwr.charge.raw == 0) {
pwr.charge.raw = pwr.acline * 100;
if (pwr.acline) {
for (int hdx = 0; hdx < 10; ++hdx) {
printf("%s", hdx < 9
? opts.empty_heart
: opts.full_heart);
}
}
return;
}

if (opts.remaining || !opts.expended) {
for (int idx = 10; idx <= pwr.charge.raw; idx += 10)
printf("%s", opts.full_heart);
Expand Down
29 changes: 19 additions & 10 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ limitations under the License.
} while(0)
# define ZB_ONDBG(...) (__VA_ARGS__)
# define ZB_XONDBG(ZB_X) ZB_X
# define zb_ping ZB_DBG("\n^^^^ %s ^^^^\n", "MARCO!");
# define zb_pong ZB_DBG("\n$$$$ %s $$$$\n", "POLO!");
# else
# define ZB_DBG(format, ...)
# define ZB_SDBG(format, exp)
# define ZB_ONDBG(...)
# define ZB_XONDBG(ZB_X)
# define zb_ping
# define zb_pong
# endif

# undef bzero
Expand Down Expand Up @@ -141,19 +145,23 @@ limitations under the License.
# define zb_eset(ZB_EPTR, ZB_ENO) \
do { \
ZB_DBG("(ZB_ENO): %d\n", (ZB_ENO)); \
zb_ping; \
if ((ZB_ENO) != PWR_OK) { \
(ZB_EPTR)->vec[(ZB_EPTR)->pos] = (ZB_ENO); \
(ZB_EPTR)->last = (ZB_EPTR)->pos; \
(ZB_EPTR)->vec[++(ZB_EPTR)->pos] = PWR_OK; \
zb_ping; \
*(ZB_EPTR)->vp = (ZB_ENO); \
(ZB_EPTR)->last = (ZB_EPTR)->vp++; \
zb_ping; \
} \
ZB_DBG("(ZB_EPTR)->last: %d\n", (ZB_EPTR)->last); \
ZB_DBG("(ZB_EPTR)->pos: %d\n", (ZB_EPTR)->pos); \
ZB_DBG("(ZB_EPTR)->vec[(ZB_EPTR)->last]: %d\n", \
(ZB_EPTR)->vec[(ZB_EPTR)->last]); \
ZB_DBG("(ZB_EPTR)->vec[(ZB_EPTR)->pos]: %d\n", \
(ZB_EPTR)->vec[(ZB_EPTR)->pos]); \
ZB_DBG("*(ZB_EPTR)->last: %d\n", *((ZB_EPTR)->last)); \
ZB_DBG("*(ZB_EPTR)->vp: %d\n", *((ZB_EPTR)->vp)); \
zb_pong; \
} while (0)

# define zb_esync(ZB_EPTR) \
do { \
ZB_EPTR->last = ZB_EPTR->pos++; \
} while(0)

/*
# define zb_efree(ZB_EPTR) \
do { \
Expand All @@ -179,6 +187,7 @@ enum pwrsuply {
PWR_ENOSUPLY = -5,
PWR_ENOREAD = -6,
PWR_ENOWANT = -7,
PWR_ELIMIT = 16
PWR_ELIMIT = 16,
PWR_EBRK = -8
};
#endif /* ZB_MAIN_H_GUARD */
1 change: 1 addition & 0 deletions src/main_gui.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def getPixbuf(charge):

def sync_icon(tcon):
pwr = py_getpwr()
print pwr.err
tcon.set_from_pixbuf(getPixbuf(pwr.tr if pwr.err is 0 else pwr.err))
ttip = 'A/C: %s\n' % 'online' if pwr.acline is 1 else 'offline'
if pwr.err is 0:
Expand Down
35 changes: 18 additions & 17 deletions src/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@ void getpwr(struct power *pwr)
{
if (pwr->charge.nof < 0)
pwr->charge.nof = 1;
pwr->err.pos = 0;
pwr->err.vec[pwr->err.pos] = PWR_OK;

ZB_DBG("err: %d\n", (pwr->err.vec[pwr->err.pos]));
memset(&pwr->err.vec, PWR_OK, sizeof(int)*PWR_ELIMIT);
pwr->err.vp = pwr->err.vec;
pwr->err.last = pwr->err.vec;

ZB_DBG("err: %d\n", *pwr->err.vp);

#if ZB_LINUX
struct pwr_sup info;
info.cap = -1;

/* check if there was an error */
pwr_info(&info, &(pwr->err), pwr->charge.nof);
ZB_DBG("pwr->err.vec[pwr->err.last]: %d\n", pwr->err.vec[pwr->err.last]);
ZB_DBG("pwr->err.vec[pwr->err.pos]: %d\n", pwr->err.vec[pwr->err.pos]);
if (pwr->err.vec[pwr->err.last] != PWR_OK) {
ZB_DBG("err: %d\n", pwr->err.vec[pwr->err.last]);
ZB_DBG("strerr: %s\n", strerror(pwr->err.vec[pwr->err.last]));
info.cap = pwr->err.vec[pwr->err.last];
ZB_DBG("pwr->err.vec[pwr->err.last]: %d\n", *pwr->err.last);
ZB_DBG("pwr->err.vec[pwr->err.pos]: %d\n", *pwr->err.vp);
if (*pwr->err.last != PWR_OK) {
ZB_DBG("err: %d\n", *pwr->err.last);
ZB_DBG("strerr: %s\n", strerror(*pwr->err.last));
info.cap = *pwr->err.last;
/*
pwr->err.vec[pwr->err.last--] = PWR_OK;
for (; pwr->err.pos > 0; --pwr->err.pos) {
Expand Down Expand Up @@ -100,24 +102,23 @@ void getpwr(struct power *pwr)
#endif
}

void sumerr(struct error *err)
{
for (int idx = err->pos; idx > 0; --idx)
err->sum += err->vec[idx];
}

struct py_power py_getpwr()
{
struct power pwr;
struct py_power pyp;
memset(&pwr.charge, 0, sizeof(pwr.charge));
pwr.charge.nof = -1;
pwr.charge.divsr = 20;
getpwr(&pwr);
ZB_DBG("lulz, I haven't segfault'd yet, derp.");
pyp.acline = pwr.acline;
ZB_DBG("pwr.err.vec[pwr.err.last]: %d\n", pwr.err.vec[pwr.err.last]);
ZB_DBG("*pwr.err.vp: %d\n", *pwr.err.vp);
ZB_DBG("pwr.charge.raw: %d\n", pwr.charge.raw);
pyp.err = pwr.err.vec[pwr.err.last];
zb_ping;
ZB_DBG("*pwr.err.last: %d\n", *pwr.err.last);
pyp.err = *pwr.err.vp;
pyp.tr = pwr.charge.tr;
pyp.raw = pwr.charge.raw;
zb_pong;
return pyp;
}
6 changes: 2 additions & 4 deletions src/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ struct pwr_lvl {

struct error {
int vec[PWR_ELIMIT];
int pos;
int *vp;
/* FIXME, `last' should be a pointer so that we can keep track of more errors better */
int last;
int sum;
int *last;
};

struct power {
Expand All @@ -64,7 +63,6 @@ struct py_power {
};

void getpwr PARAMS((struct power *pwr));
void sumerr PARAMS((struct error *err));

struct py_power py_getpwr PARAMS(());
#endif /* ZB_POWER_H_GUARD */
2 changes: 1 addition & 1 deletion test/ACAD/online
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1
0

0 comments on commit ce3d438

Please sign in to comment.