Development:TipsNTricks
From Dingoonity Wiki
Setting volume (set volume in "volume" variable)
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <stdio.h>
[...]
long mixer;
int realVol = (this->volume << 8) + this->volume; /* 0 < volume < 255 */
mixer = open("/dev/mixer", O_RDWR);
if (mixer != -1) {
ioctl(mixer, SOUND_MIXER_WRITE_VOLUME , &realVol);
close(mixer);
}
Reading battery (stores value in "currentval")
#include <stdlib.h>
#include <stdio.h>
[...]
static FILE* devbatt_;
static char* strval;
static size_t n;
static size_t t;
[...]
devbatt_ = fopen("/proc/jz/battery", "r");
n = 4;
t = sizeof(char);
strval = (char*)malloc((size_t)10*sizeof(char));
[...]
unsigned short currentval = 0;
fseek (devbatt_, 0, SEEK_SET);
fread (strval, t, n, devbatt_);
currentval = atoi(strval);
if (currentval > 4000) {
currentval = 4000;
} else if (currentval < 3000) {
currentval = 3000;
}
lastBattLevel_= ((currentval-3000)/10);
[...]
fclose (devbatt_);