コード例 #1
0
ファイル: game.c プロジェクト: szczys/SloCommunicator
void gameSetMetaPixel(uint8_t x, uint8_t y, uint8_t status) {
    //status is ON (non-zero) or OFF (zero)
    //oled is 128x64, our meta board will be 0-64 (x) and 0-32 (y)

    //oled is written in 'pages' of 8-bits. This particular screen
    //cannot be read so the game buffer must be used to ensure writing
    //a new game pixel doesn't overwrite existing pixels.

    //make our changes to the buffer
    uint8_t metaPage = y/8; 
    uint8_t metaPageY = 1<<(y%8);
    if (status) { buffer[metaPage][x] |= metaPageY; }
    else { buffer[metaPage][x] &= ~metaPageY; }

    //write to the screen accounting for 2x pixel sizes meta-v-actual
    uint8_t subMetaPage = (y%8)/4;
    uint8_t actualPage = (metaPage*2) + subMetaPage;
    uint8_t actualX = x*2;
    
    uint8_t metaData = buffer[metaPage][x];
    if (subMetaPage) { metaData>>=4; }  //Shift data to get to upper nibble if necessary
    uint8_t actualData = 0x00;
    for (uint8_t i=0; i<4; i++) {
        if (metaData & (1<<i)) {
            //Each '1' in the meta data is amplified to two bits in the actual
            actualData |= (0b11<<(i*2));
        }
    }
    
    oledSetCursor(actualX,actualPage);
    oledWriteData(actualData);
    oledWriteData(actualData);
}
コード例 #2
0
ファイル: main.c プロジェクト: szczys/SloJak
int main(void)
{
    init_IO();
    init_interrupts();
    oledInit();
    _delay_ms(200);

    oledSetCursor(cursX, cursY);
    putChar(66,1);
    advanceCursor(6);

    compose();

    initMenu();

    while(1)
    {
        static uint16_t butCounter = 0;
        if (butCounter++ > 65000) {
            //FIXME: Proper button debounce and handling
            butCounter = 0;
            uint8_t readButtons = BUT_PIN;
            if (~readButtons & BUT_LEFT) {
                ++goLeft;
            }
            if (~readButtons & BUT_SEL) {
                ++goSel;
            }
        }

        if (knobChange) {
            if (knobChange > 0) {
                //menuUp();
                knobLeft();
            }
            else {
                //menuDn();
                knobRight();
            }
            knobChange = 0;
        }

        if (goSel) {
            //Lookup and execute action
            doSelect[optionIndex]();
            goSel = 0;
        }
        else if (goLeft) {
            doBack();
            goLeft = 0;
        }
    }
}
コード例 #3
0
ファイル: oled-exp-module.c プロジェクト: kea/i2c-exp-driver
/*
 * 	oledSetCursor() Python Analogue
 */
static PyObject* pyOledSetCursor(PyObject* self, PyObject* args)
{
	int 	status, row, col;

	// parse the arguments
	if (!PyArg_ParseTuple(args, "ii", &row, &col) ) {
		return NULL;
	}

	// make the oled-exp call
	status 	= oledSetCursor (row, col);

	if (status != EXIT_SUCCESS) {
		PyErr_SetString(PyExc_IOError, wrmsg_i2c);
		return NULL;
	}

	return Py_BuildValue("i", status);
}