Skip to content

Commit

Permalink
Volume Level to MUTE when at 0 #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpndable committed Apr 4, 2023
1 parent 7a7302c commit 36b2fcb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ int isCharging(void) {
static char governor[128];

void enterSleep(void) {
SetRawVolume(-60);
//SetRawVolume(-60);
SetMute(1);
// SetRawBrightness(0);
putInt("/sys/class/gpio/export", 4);
putFile("/sys/class/gpio/gpio4/direction", "out");
Expand All @@ -841,6 +842,7 @@ void exitSleep(void) {
putInt("/sys/class/pwm/pwmchip0/pwm0/enable",0);
putInt("/sys/class/pwm/pwmchip0/pwm0/enable",1);
// SetBrightness(GetBrightness());
SetMute(0);
SetVolume(GetVolume());

// restore previous governor
Expand Down
2 changes: 2 additions & 0 deletions src/keymon/keymon.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ int main (int argc, char *argv[]) {
} else {
val = GetVolume();
if (val<VOLMAX) SetVolume(++val);
if (val>0) SetMute(0);
}
}
break;
Expand All @@ -194,6 +195,7 @@ int main (int argc, char *argv[]) {
} else {
val = GetVolume();
if (val>0) SetVolume(--val);
if (val==0) SetMute(1);
}
}
break;
Expand Down
17 changes: 17 additions & 0 deletions src/libmsettings/msettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include <mi_ao.h>

#include <stdint.h>
#include <sys/ioctl.h>

#include "msettings.h"

///////////////////////////////////////
Expand All @@ -30,6 +33,7 @@ static Settings DefaultSettings = {
static Settings* settings;

#define SHM_KEY "/SharedSettings"
#define MI_AO_SETMUTE 0x4008690d
static char SettingsPath[256];
static int shm_fd = -1;
static int is_host = 0;
Expand Down Expand Up @@ -67,6 +71,8 @@ void InitSettings(void) {
MI_AO_Enable(0);
MI_AO_EnableChn(0,0);
SetVolume(GetVolume());
if (GetVolume()==0) SetMute(1);
else SetMute(0);
SetBrightness(GetBrightness());
}
void QuitSettings(void) {
Expand Down Expand Up @@ -116,6 +122,17 @@ void SetRawVolume(int val) {
MI_AO_SetVolume(0,val);
}

void SetMute(int mute) {
int fd = open("/dev/mi_ao", O_RDWR);
if (fd >= 0) {
int buf2[] = {0, mute};
uint64_t buf1[] = {sizeof(buf2), (uintptr_t)buf2};

ioctl(fd, MI_AO_SETMUTE, buf1);
close(fd);
}
}

int GetJack(void) {
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/libmsettings/msettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ int GetVolume(void);

void SetRawBrightness(int value); // 0-100
void SetRawVolume(int value); // -60-0
void SetMute(int mute); // 0-1

void SetBrightness(int value); // 0-10
void SetVolume(int value); // 0-20
Expand Down

0 comments on commit 36b2fcb

Please sign in to comment.