Skip to content

Commit

Permalink
Merge pull request #1 from Lorys89/dev/counter
Browse files Browse the repository at this point in the history
FIX : Make jack detection more stable
  • Loading branch information
mbarbierato authored May 30, 2024
2 parents ff4d19e + 0f8023d commit ef2b14b
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions ComboJack_Source/Combo Jack/hda-verb.m
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,27 @@ static uint32_t headset(void)

void JackBehavior(void)
{
while(run && ((GetJackStatus() & 0x80000000) == 0x80000000)) // Poll headphone jack state
int counter = 4;

while (run) // Poll headphone jack state
{
sleep(1); // Polling frequency (seconds): use usleep for microseconds if finer-grained control is needed
usleep(250000); // Polling frequency (seconds): use usleep for microseconds if finer-grained control is needed

if (awake)
{
awake = false;
break;
}

if ((GetJackStatus() & 0x80000000) != 0x80000000)
{
if (--counter < 0)
break;
}
else
counter = 4;
}

if (run) // If process is killed, maintain current state
{
if (!isSleeping) {
Expand Down Expand Up @@ -660,30 +672,39 @@ int main(void)
@"Cancel", @"btnCancel",
nil];

int counter = 4;

while(run) // Poll headphone jack state
{
if (!isSleeping){
jackstat = GetJackStatus();
if (jackstat == -1) // 0xFFFFFFFF means jack not ready yet
{
fprintf(stderr, "Jack not ready. Checking again in 1 second...\n");
counter = 4;
}
else if ((jackstat & 0x80000000) == 0x80000000)
{
fprintf(stderr, "Jack sense detected! Displaying menu...\n");
if (CFPopUpMenu() == 0)
{
JackBehavior();
}
else
if (--counter < 0)
{
break;
fprintf(stderr, "Jack sense detected! Displaying menu...\n");
counter = 4;
if (CFPopUpMenu() == 0)
{
JackBehavior();
}
else
{
break;
}
}
}
else
counter = 4;
}

//if (awake) awake = false;
sleep(1); // Sleep delay (seconds): use usleep for microseconds if fine-grained control is needed
usleep(250000); // Sleep delay (seconds): use usleep for microseconds if fine-grained control is needed
}

sem_unlink("ComboJack_Watcher");
Expand Down

0 comments on commit ef2b14b

Please sign in to comment.