MCPcopy Create free account
hub / github.com/OpenStickCommunity/GP2040-CE / obdMenuReadRotary

Function obdMenuReadRotary

lib/OneBitDisplay/OneBitDisplay.cpp:842–870  ·  view source on GitHub ↗

A valid CW or CCW move returns 1 or -1, invalid returns 0.

Source from the content-addressed store, hash-verified

840
841// A valid CW or CCW move returns 1 or -1, invalid returns 0.
842static int obdMenuReadRotary(SIMPLEMENU *sm)
843{
844 static int8_t rot_enc_table[] = {0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0};
845 uint8_t c;
846 int rc = 0;
847
848 sm->prevNextCode <<= 2;
849 if (gpio_get(sm->u8Dn) == sm->iPressed)
850 sm->prevNextCode |= 0x02;
851 if (gpio_get(sm->u8Up) == sm->iPressed)
852 sm->prevNextCode |= 0x01;
853 sm->prevNextCode &= 0x0f;
854
855 // If valid then store as 16 bit data.
856 if (rot_enc_table[sm->prevNextCode])
857 {
858 sm->store <<= 4;
859 sm->store |= sm->prevNextCode;
860 c = sm->store & 0xff;
861 //if (store==0xd42b) return 1;
862 //if (store==0xe817) return -1;
863 if ((c & 0xf) == 2)
864 rc = -1;
865 else if ((c & 0xf) == 1)
866 rc = 1;
867 }
868 // Serial.printf("store = 0x%04x, val = %d\n", sm->store, rc);
869 return rc;
870} /* obdMenuReadRotary() */
871
872//
873// Initialize the simple menu structure

Callers 1

obdMenuRunFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected