示例#1
0
static bool handleWrite(int size, const byte *msg, CONTEXT *context)
    {
    byte *expr = (byte *) &msg[1];
    byte slaveAddress = evalWord8Expr(&expr, context);
    bool alloc;
    byte *list = evalList8Expr(&expr, context, &alloc);
    byte listSize = list[1];
    const byte *data = &list[2];
    byte byteCount = size;

    if (byteCount > listSize)
        byteCount = listSize;

    if (byteCount > 0)
        {
        Wire.beginTransmission(slaveAddress);
        Wire.write(data, byteCount);
        Wire.endTransmission();
        delayMicroseconds(70);
        }

    if (alloc)
        free(list);

    return false;
    }
示例#2
0
void storeList8Ref(byte *expr, CONTEXT *context, byte refIndex)
    {
    bool alloc;
    byte *lVal = evalList8Expr(&expr, context, &alloc);

    if (haskinoRefs[refIndex].ref != NULL)
        {
        free(haskinoRefs[refIndex].ref);
        haskinoRefs[refIndex].ref = NULL;
        }

    if (alloc)
        haskinoRefs[refIndex].ref = lVal;
    else
        {
        // Need to copy expression
        byte *newLVal = (byte *) malloc(lVal[1]+2);
        if (newLVal)
            {
            memcpy(newLVal, lVal, lVal[1]+2);
            haskinoRefs[refIndex].ref = newLVal;
            }
        }    
    }