Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for different reading modes #34

Closed
wants to merge 3 commits into from

Conversation

NicoHood
Copy link
Owner

@NicoHood NicoHood commented Mar 12, 2021

Replaces #25 and #31

The idea or this PR is to arrange the sending data in the Gamecube_Report_t itself and accept all reading modes (0-7) by default. The data structure represents reading mode 3, the other modes must be implemented on your own. It is possible, that most of the time the sending will work with 0x00 data if you do not care about the changed triggers.

@mizuyoukanao
Copy link
Contributor

This is a way to do it without adding any additional definitions.
I'm sorry, but other than mode0 and mode3, I haven't tested this method yet because I don't have the software to use it.
(in Gamecube.c)

    else if (receivedBytes == 3 && command[0] == 0x40 && command[1] <= 0x07)
    {
        if (command[1] == 0x03)
        {
        gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask);
        ret = 3;
        }
        else if (command[1] == 0x01)
        {
            report->cxAxis = (report->cxAxis >> 4) << 4 | report->cyAxis >> 4;
            report->cyAxis = report->left;
            report->left = report->right;
            report->right = 0x00;
            gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask);
            ret = 3;
        }
        else if (command[1] == 0x02)
        {
            report->cxAxis = (report->cxAxis >> 4) << 4 | report->cyAxis >> 4;
            report->cyAxis = (report->left >> 4) << 4 | report->right >> 4;
            report->left = 0x00;
            report->right = 0x00;
            gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask);
            ret = 3;
        }
        else if (command[1] == 0x04)
        {
            report->left = 0x00;
            report->right = 0x00;
            gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask);
            ret = 3;
        }
        else
        {
            report->left = (report->left >> 4) << 4 | report->right >> 4;
            report->right = 0x00;
            gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask);
            ret = 3;
        }

@NicoHood
Copy link
Owner Author

NicoHood commented Jul 7, 2021

@mizuyoukanao thanks for sharing. I am not sure if this is the way to go, as it would rearrange the data in the current report. Meaning you cannot simply send it twice. I would prefer to have the additional union types to define different modes. We could then write converter functions like your code above that converts modes. This can be used if you are reading the controller in a different mode than the console requests it.

On the other side we do not know which mode the console might request, so your idea might be still a valid solution. Maybe we should use an additional array to cache the data, so all modifications will be only taken on this temporary array, not the real data? Not sure if it has a performance impact as well.

Uuuf really unsure about that on.e

@mizuyoukanao
Copy link
Contributor

Sorry, I'm not very familiar with the C language... This may not be the code you think it is.
4f1eb28
596da5f

src/Gamecube.c Show resolved Hide resolved
@NicoHood
Copy link
Owner Author

NicoHood commented Jul 8, 2021

Great work! I've added some comments to your PR.

@NicoHood
Copy link
Owner Author

NicoHood commented Jul 8, 2021

@mizuyoukanao Do you think it would make sense to add the reading mode request to the read function as well? It could be an optional parameter which defaults to 0x03?

Nintendo/src/Gamecube.c

Lines 63 to 66 in 596da5f

bool gc_read(const uint8_t pin, Gamecube_Report_t* report, const bool rumble)
{
// Command to send to the gamecube, LSB is rumble
uint8_t command[] = { 0x40, 0x03, rumble };

Not sure if it consumes more memory/flash then...

@NicoHood
Copy link
Owner Author

NicoHood commented Jul 9, 2021

Closing in favor of: #42

@NicoHood NicoHood closed this Jul 9, 2021
@NicoHood NicoHood deleted the different_reading_modes branch July 9, 2021 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants