// simon-wrench.ino
//
// NOT FINISHED, NOT WORKING YET
//
// This is a translation of a Arduino sketch into wrench code.
//
// 12 November 2022, Version 1, by Koepel, MIT license.
// Copied from "simon-with-score.ino" by Uri Shaked, MIT license.
// https://wokwi.com/projects/328451800839488084
// Circuit diagram also by Uri Shaked.
// Converted into wrench code by Koepel.
// Using the wrench interpreter, MIT license.
// wrench repository: https://github.com/jingoro2112/wrench
// wrench website: http://northarc.com/wrench/www/
// I learned about wrench here:
// https://forum.arduino.cc/t/c-like-interpreter-that-actually-fits-and-runs-inside-most-arduino-chips-wrench/1050025
#include "wrench.h"
// The Arduino preprocessor gets confused, therefor function prototyping is required
void print( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void println( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void delay( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void pinMode( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void digitalWrite( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void digitalRead( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void analogRead( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void tone( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void noTone( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void randomSeed( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void random( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void shiftOut( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr);
void lcd_begin( WRValue* stackTop, const int argn, WRContext* c);
void lcd_setCursor( WRValue* stackTop, const int argn, WRContext* c);
void lcd_print( WRValue* stackTop, const int argn, WRContext* c);
void Wire_begin( WRValue* stackTop, const int argn, WRContext* c);
void Wire_beginTransmission( WRValue* stackTop, const int argn, WRContext* c);
void Wire_write( WRValue* stackTop, const int argn, WRContext* c);
void Wire_endTransmission( WRValue* stackTop, const int argn, WRContext* c);
void Wire_requestFrom( WRValue* stackTop, const int argn, WRContext* c);
void Wire_available( WRValue* stackTop, const int argn, WRContext* c);
void Wire_read( WRValue* stackTop, const int argn, WRContext* c);
const int simon_bytecodeSize=1085;
const unsigned char simon_bytecode[]=
{
0x08, 0x11, 0x01, 0x00, 0x02, 0x02, 0x00, 0x01, 0x0D, 0xDE, 0x3C, 0x63, 0xAD, 0x01, 0xE6, 0x00, // 16
0x01, 0x00, 0x03, 0x00, 0x01, 0x01, 0x0A, 0x0B, 0x49, 0x65, 0xAD, 0x02, 0x16, 0x00, 0x01, 0x00, // 32
0x01, 0x01, 0x02, 0x01, 0x78, 0xAA, 0x4C, 0x7B, 0xAD, 0x02, 0x4B, 0x00, 0x01, 0x00, 0x01, 0x00, // 48
0x03, 0x01, 0x74, 0xB5, 0x1E, 0x52, 0xAD, 0x02, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x04, 0x01, // 64
0x53, 0xA1, 0x33, 0xC6, 0xAD, 0x02, 0xA4, 0x00, 0x01, 0x00, 0x05, 0x00, 0x05, 0x01, 0x90, 0x87, // 80
0x97, 0x3D, 0xAD, 0x02, 0xD7, 0x00, 0x01, 0x00, 0x02, 0x00, 0x06, 0x01, 0xAC, 0xE1, 0x91, 0x29, // 96
0xAD, 0x03, 0x92, 0x00, 0x01, 0x00, 0x04, 0x00, 0x07, 0x01, 0xEA, 0x99, 0x76, 0x95, 0xAD, 0x03, // 112
0xBE, 0x00, 0xCD, 0x00, 0x00, 0xC4, 0xCD, 0x01, 0x01, 0x06, 0xCD, 0x02, 0x01, 0x4A, 0xCD, 0x03, // 128
0x03, 0x10, 0xB1, 0x04, 0x00, 0xAC, 0x09, 0x95, 0x00, 0x00, 0xAC, 0x0A, 0x95, 0x00, 0x01, 0xAC, // 144
0x0B, 0x95, 0x00, 0x02, 0xAC, 0x0C, 0x95, 0x00, 0x03, 0x0F, 0xB1, 0x05, 0x00, 0xAC, 0x02, 0x95, // 160
0x00, 0x00, 0xAC, 0x03, 0x95, 0x00, 0x01, 0xAC, 0x04, 0x95, 0x00, 0x02, 0xAC, 0x05, 0x95, 0x00, // 176
0x03, 0x0F, 0xCC, 0x06, 0x08, 0xCC, 0x07, 0x65, 0xCC, 0x08, 0x64, 0xCC, 0x09, 0x66, 0xCC, 0x0A, // 192
0x64, 0xB1, 0x0B, 0x00, 0x1D, 0x00, 0x95, 0x00, 0x00, 0x1D, 0x01, 0x95, 0x00, 0x01, 0x1D, 0x02, // 208
0x95, 0x00, 0x02, 0x1D, 0x03, 0x95, 0x00, 0x03, 0x0F, 0x21, 0x0A, 0x0C, 0x14, 0x02, 0x95, 0x00, // 224
0x00, 0x0F, 0xCC, 0x0D, 0x00, 0xCC, 0x0E, 0x00, 0xAC, 0x04, 0x6D, 0x0E, 0x1F, 0x09, 0x21, 0x0E, // 240
0x04, 0x14, 0xAC, 0x01, 0x06, 0x02, 0x8D, 0x64, 0x9E, 0xF7, 0x21, 0x0E, 0x05, 0x14, 0xAC, 0x02, // 256
0x06, 0x02, 0x8D, 0x64, 0x9E, 0xF7, 0x8D, 0x0E, 0x34, 0xDF, 0x09, 0x1D, 0x06, 0xAC, 0x01, 0x06, // 272
0x02, 0x8D, 0x64, 0x9E, 0xF7, 0x1D, 0x07, 0xAC, 0x01, 0x06, 0x02, 0x8D, 0x64, 0x9E, 0xF7, 0x1D, // 288
0x09, 0xAC, 0x01, 0x06, 0x02, 0x8D, 0x64, 0x9E, 0xF7, 0x1D, 0x08, 0xAC, 0x01, 0x06, 0x02, 0x8D, // 304
0x64, 0x9E, 0xF7, 0xAC, 0x67, 0x05, 0x01, 0xEC, 0x31, 0x55, 0x11, 0x06, 0x01, 0xE9, 0x91, 0x75, // 320
0x43, 0xB1, 0x0F, 0x00, 0xAD, 0x00, 0xC0, 0x95, 0x00, 0x00, 0xAD, 0x00, 0xF9, 0x95, 0x00, 0x01, // 336
0xAD, 0x00, 0xA4, 0x95, 0x00, 0x02, 0xAD, 0x00, 0xB0, 0x95, 0x00, 0x03, 0xAD, 0x00, 0x99, 0x95, // 352
0x00, 0x04, 0xAD, 0x00, 0x92, 0x95, 0x00, 0x05, 0xAD, 0x00, 0x82, 0x95, 0x00, 0x06, 0xAD, 0x00, // 368
0xF8, 0x95, 0x00, 0x07, 0xAD, 0x00, 0x80, 0x95, 0x00, 0x08, 0xAD, 0x00, 0x90, 0x95, 0x00, 0x09, // 384
0x0F, 0xCD, 0x10, 0x00, 0xBF, 0xAC, 0x01, 0x36, 0x5B, 0xEA, 0x07, 0x00, 0x01, 0x03, 0x32, 0x0F, // 400
0x21, 0x0D, 0x0C, 0x14, 0x02, 0xAC, 0x04, 0x05, 0x02, 0x14, 0x4F, 0x0C, 0x62, 0x1A, 0x02, 0x92, // 416
0x8D, 0x0D, 0x84, 0x0A, 0x0D, 0x08, 0x09, 0xAC, 0x01, 0x1D, 0x0A, 0xB5, 0x0D, 0x07, 0x00, 0x03, // 432
0x03, 0x32, 0x0F, 0x07, 0x00, 0x06, 0x02, 0x32, 0x08, 0xAA, 0x36, 0x08, 0x09, 0x07, 0x00, 0x05, // 448
0x03, 0x32, 0x0F, 0xAD, 0x01, 0x2C, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, 0x02, 0x6B, 0x0D, 0x11, // 464
0x09, 0x07, 0x00, 0x07, 0x03, 0x32, 0x0F, 0xAD, 0x01, 0x2C, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, // 480
0x34, 0xA4, 0x09, 0x02, 0xED, 0x12, 0x1D, 0x07, 0x02, 0x06, 0x02, 0x04, 0xC8, 0x38, 0x4E, 0x1D, // 496
0x08, 0x1D, 0x09, 0xAC, 0x01, 0x1C, 0x01, 0x06, 0x04, 0xAA, 0x47, 0xC7, 0xD9, 0x1D, 0x08, 0x1D, // 512
0x09, 0xAC, 0x01, 0x1C, 0x00, 0x06, 0x04, 0xAA, 0x47, 0xC7, 0xD9, 0x1D, 0x07, 0xAC, 0x01, 0x06, // 528
0x02, 0x04, 0xC8, 0x38, 0x4E, 0x10, 0xAC, 0x0A, 0xAC, 0x64, 0x2A, 0x1D, 0x0D, 0x2D, 0x94, 0x00, // 544
0xAC, 0x0A, 0x1D, 0x0D, 0x2D, 0x94, 0x01, 0x02, 0x66, 0x00, 0x13, 0x09, 0x1F, 0x00, 0x0F, 0x14, // 560
0x1E, 0x01, 0x02, 0x14, 0x07, 0x02, 0x00, 0x03, 0x32, 0x0F, 0x34, 0x0F, 0x09, 0xAD, 0x00, 0xFF, // 576
0x1F, 0x01, 0x0F, 0x14, 0x07, 0x02, 0x00, 0x03, 0x32, 0x0F, 0x10, 0x1F, 0x00, 0x04, 0x14, 0xAC, // 592
0x01, 0x06, 0x02, 0x04, 0xC8, 0x38, 0x4E, 0x1D, 0x06, 0x1F, 0x00, 0x0B, 0x14, 0x06, 0x02, 0x5C, // 608
0x71, 0x4E, 0x81, 0xAD, 0x01, 0x2C, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, 0x1F, 0x00, 0x04, 0x14, // 624
0x02, 0x06, 0x02, 0x04, 0xC8, 0x38, 0x4E, 0x1D, 0x06, 0x06, 0x01, 0xFA, 0x8A, 0xB8, 0x32, 0x10, // 640
0xCC, 0x0E, 0x00, 0x81, 0x0D, 0x0E, 0x1D, 0x09, 0x21, 0x0E, 0x0C, 0x14, 0x94, 0x00, 0x1C, 0x00, // 656
0x07, 0x01, 0x02, 0x03, 0x32, 0x0F, 0xAC, 0x32, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, 0x8D, 0x0E, // 672
0x34, 0xE2, 0x09, 0x10, 0xAC, 0x01, 0x36, 0x30, 0x09, 0xCC, 0x0E, 0x00, 0xAC, 0x04, 0x6D, 0x0E, // 688
0x1C, 0x09, 0x21, 0x0E, 0x05, 0x14, 0x94, 0x00, 0x1C, 0x00, 0x05, 0x01, 0x7C, 0x56, 0x10, 0x2F, // 704
0x02, 0xC2, 0x05, 0x09, 0x1D, 0x0E, 0x11, 0x8D, 0x0E, 0x34, 0xE2, 0x09, 0xAC, 0x01, 0x06, 0x01, // 720
0x4E, 0xD1, 0xF1, 0xD8, 0x34, 0xCF, 0x09, 0x04, 0x00, 0x17, 0x47, 0x61, 0x6D, 0x65, 0x20, 0x6F, // 736
0x76, 0x65, 0x72, 0x21, 0x20, 0x79, 0x6F, 0x75, 0x72, 0x20, 0x73, 0x63, 0x6F, 0x72, 0x65, 0x3A, // 752
0x20, 0x06, 0x01, 0x16, 0x37, 0x8A, 0x88, 0xAC, 0x01, 0x1D, 0x0D, 0x29, 0x06, 0x01, 0x18, 0xBF, // 768
0xF8, 0xA6, 0xCC, 0x0D, 0x00, 0xAD, 0x00, 0xC8, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, 0x1D, 0x06, // 784
0x1C, 0x00, 0x06, 0x02, 0x5C, 0x71, 0x4E, 0x81, 0xAD, 0x01, 0x2C, 0x06, 0x01, 0x4E, 0xD1, 0xF1, // 800
0xD8, 0x1D, 0x06, 0x1C, 0x01, 0x06, 0x02, 0x5C, 0x71, 0x4E, 0x81, 0xAD, 0x01, 0x2C, 0x06, 0x01, // 816
0x4E, 0xD1, 0xF1, 0xD8, 0x1D, 0x06, 0x1C, 0x02, 0x06, 0x02, 0x5C, 0x71, 0x4E, 0x81, 0xAD, 0x01, // 832
0x2C, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, 0xCC, 0x0E, 0x00, 0xAC, 0x0A, 0x6D, 0x0E, 0x28, 0x09, // 848
0xCF, 0x03, 0xF6, 0xAC, 0x0A, 0x6A, 0x03, 0x1A, 0x09, 0x1D, 0x06, 0xD9, 0x04, 0x03, 0x06, 0x02, // 864
0x5C, 0x71, 0x4E, 0x81, 0xAC, 0x05, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, 0x8F, 0x03, 0x34, 0xE4, // 880
0x09, 0x8D, 0x0E, 0x34, 0xD6, 0x09, 0x1D, 0x06, 0x06, 0x01, 0xFA, 0x8A, 0xB8, 0x32, 0x1D, 0x10, // 896
0x1D, 0x10, 0x07, 0x02, 0x00, 0x03, 0x32, 0x0F, 0xAD, 0x01, 0xF4, 0x06, 0x01, 0x4E, 0xD1, 0xF1, // 912
0xD8, 0x10, 0xCC, 0x0E, 0x00, 0x81, 0x0D, 0x0E, 0x23, 0x09, 0x21, 0x0E, 0x0C, 0x14, 0x94, 0x00, // 928
0x07, 0x00, 0x04, 0x02, 0x32, 0x08, 0x94, 0x01, 0x1C, 0x01, 0x07, 0x01, 0x02, 0x03, 0x32, 0x0F, // 944
0x80, 0x00, 0x01, 0x03, 0x09, 0x10, 0x8D, 0x0E, 0x34, 0xDC, 0x09, 0xAC, 0x01, 0x11, 0x1D, 0x06, // 960
0x1D, 0x02, 0x06, 0x02, 0x5C, 0x71, 0x4E, 0x81, 0xAD, 0x00, 0x96, 0x06, 0x01, 0x4E, 0xD1, 0xF1, // 976
0xD8, 0x1D, 0x06, 0x1C, 0x00, 0x06, 0x02, 0x5C, 0x71, 0x4E, 0x81, 0xAD, 0x00, 0x96, 0x06, 0x01, // 992
0x4E, 0xD1, 0xF1, 0xD8, 0x1D, 0x06, 0x1C, 0x01, 0x06, 0x02, 0x5C, 0x71, 0x4E, 0x81, 0xAD, 0x00, // 1008
0x96, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, 0x1D, 0x06, 0x1C, 0x02, 0x06, 0x02, 0x5C, 0x71, 0x4E, // 1024
0x81, 0xAD, 0x00, 0x96, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, 0x1D, 0x06, 0x1C, 0x03, 0x06, 0x02, // 1040
0x5C, 0x71, 0x4E, 0x81, 0xAD, 0x00, 0x96, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, 0x1D, 0x06, 0x1D, // 1056
0x03, 0x06, 0x02, 0x5C, 0x71, 0x4E, 0x81, 0xAD, 0x00, 0x96, 0x06, 0x01, 0x4E, 0xD1, 0xF1, 0xD8, // 1072
0x1D, 0x06, 0x06, 0x01, 0xFA, 0x8A, 0xB8, 0x32, 0x10, 0x0F, 0x53, 0xD9, 0xC6, // 1085
};
void setup()
{
Serial.begin( 115200);
Serial.println( "simon-wrench.ino");
Serial.print( "wrench version: ");
Serial.print( WRENCH_VERSION_MAJOR);
Serial.print( ".");
Serial.println( WRENCH_VERSION_MINOR);
WRState* w = wr_newState(); // create the state
// Bind the functions.
// The Math functions are provide by wrench.
// The normal functions can even have the same names.
// Adding a library function uses basic wrench functionality.
wr_loadMathLib( w); // register all the math functions
wr_loadStringLib( w); // for sprintf
wr_registerFunction( w, "print", print);
wr_registerFunction( w, "println", println);
wr_registerFunction( w, "delay", delay);
wr_registerFunction( w, "pinMode", pinMode);
wr_registerFunction( w, "digitalWrite", digitalWrite);
wr_registerFunction( w, "digitalRead", digitalWrite);
wr_registerFunction( w, "analogRead", analogRead);
wr_registerFunction( w, "tone", tone);
wr_registerFunction( w, "noTone", noTone);
wr_registerFunction( w, "randomSeed", randomSeed);
wr_registerFunction( w, "random", random);
wr_registerFunction( w, "shiftOut", shiftOut);
/*
wr_registerLibraryFunction( w, "lcd::begin", lcd_begin);
wr_registerLibraryFunction( w, "lcd::setCursor", lcd_setCursor);
wr_registerLibraryFunction( w, "lcd::print", lcd_print);
wr_registerLibraryFunction( w, "Wire::begin", Wire_begin);
wr_registerLibraryFunction( w, "Wire::beginTransmission", Wire_beginTransmission);
wr_registerLibraryFunction( w, "Wire::write", Wire_write);
wr_registerLibraryFunction( w, "Wire::endTransmission", Wire_endTransmission);
wr_registerLibraryFunction( w, "Wire::requestFrom", Wire_requestFrom);
wr_registerLibraryFunction( w, "Wire::available", Wire_available);
wr_registerLibraryFunction( w, "Wire::read", Wire_read);
*/
wr_run( w, simon_bytecode, simon_bytecodeSize); // load and run the code!
wr_destroyState( w );
}
void loop()
{
delay( 10); // a delay in the loop is better for Wokwi
}
// The functions convert the wrench code to the specific platform code.
void print( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
char buf[128];
for( int i=0; i<argn; ++i)
{
Serial.print( argv[i].asString(buf, sizeof(buf)));
}
}
void println( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
char buf[128];
for( int i=0; i<argn; ++i)
{
Serial.print( argv[i].asString(buf, sizeof(buf)));
}
Serial.println(); // allow no arguments for just a newline
}
void delay( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
if( argn == 1)
{
delay( (unsigned long)argv[0].asInt()); // a signed int will work up to 25 days
}
}
// No translation is needed for the LOW and HIGH in the wrench code,
// they seem to be 0 and 1 no every platform.
// The INPUT, OUTPUT and INPUT_PULLUP have differenct numbers
// on different platforms, those need an extra translation.
void pinMode( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
if( argn == 2)
{
int pin = argv[0].asInt();
if( pin >= 100)
pin += A0 - 100;
if ( argv[1].asInt() == 0) // wrench value for INPUT
{
pinMode( pin, INPUT); // Arduino value for INPUT
Serial.print("A");
Serial.print(pin);
}
else if ( argv[1].asInt() == 1) // wrench value for OUTPUT
{
pinMode( pin, OUTPUT); // Arduino value for OUTPUT
Serial.print("B");
Serial.print(pin);
}
else if ( argv[1].asInt() == 2) // wrench value for INPUT_PULLUP
{
pinMode( pin, INPUT_PULLUP); // Arduino value for INPUT_PULLUP
Serial.print("C");
Serial.print(pin);
}
}
}
// Assuming that LOW is 0 and HIGH is 1
void digitalWrite( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
if( argn == 2)
{
int pin = argv[0].asInt();
if( pin >= 100)
pin += A0 - 100;
digitalWrite( pin, argv[1].asInt());
Serial.print("D");
Serial.print(pin);
Serial.print("=");
Serial.print( argv[1].asInt());
Serial.print( ".");
}
}
// Assuming that LOW is 0 and HIGH is 1
void digitalRead( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
if( argn == 1)
{
int pin = argv[0].asInt();
if( pin >= 100)
pin += A0 - 100;
int value = digitalRead( pin);
wr_makeInt( &retVal, value);
Serial.print("R");
Serial.print(pin);
}
}
void analogRead( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
if ( argn == 1)
{
int pin = argv[0].asInt();
if( pin >= 100)
pin += A0 - 100;
int value = analogRead( pin);
wr_makeInt( &retVal, value); // put the value in the return package
}
}
void tone( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
if( argn == 2)
{
int pin = argv[0].asInt();
if( pin >= 100)
pin += A0 - 100;
tone( pin, argv[1].asInt());
}
}
void noTone( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
if( argn == 1)
{
int pin = argv[0].asInt();
if( pin >= 100)
pin = A0 - 100;
noTone( pin);
}
}
void randomSeed( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
if( argn == 1)
{
randomSeed(argv[0].asInt());
}
}
void random( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
if( argn == 2)
{
long x = random(argv[0].asInt(), argv[1].asInt());
wr_makeInt( &retVal, x);
}
}
void shiftOut( WRState* w, const WRValue* argv, const int argn, WRValue& retVal, void* usr)
{
if( argn == 4)
{
int pinData = argv[0].asInt();
if( pinData >= 100)
pinData += A0 - 100;
int pinClock = argv[1].asInt();
if( pinClock >= 100)
pinClock += A0 - 100;
shiftOut( pinData, pinClock, argv[2].asInt(), argv[3].asInt());
Serial.print("E");
Serial.print(pinData); Serial.print(",");
Serial.print(pinClock); Serial.print(",");
Serial.print(argv[2].asInt()); Serial.print(",");
Serial.print(argv[3].asInt()); Serial.print(".");
}
}
/*
void lcd_begin( WRValue* stackTop, const int argn, WRContext* c)
{
if( argn == 2)
{
int columns = stackTop[-2].asInt(); // first argument
int rows = stackTop[-1].asInt(); // second argument
int status = lcd.begin( columns, rows);
wr_makeInt( stackTop, status);
}
}
void lcd_setCursor( WRValue* stackTop, const int argn, WRContext* c)
{
if( argn == 2)
{
int column = stackTop[-2].asInt(); // first argument
int row = stackTop[-1].asInt(); // second argument
lcd.setCursor( column, row);
}
}
void lcd_print( WRValue* stackTop, const int argn, WRContext* c)
{
if( argn == 1)
{
char buf[60];
int n = lcd.print( stackTop[-1].asString(buf, sizeof(buf)));
wr_makeInt( stackTop, n);
}
}
void Wire_begin( WRValue* stackTop, const int argn, WRContext* c)
{
if( argn == 0)
{
Wire.begin();
}
}
void Wire_beginTransmission( WRValue* stackTop, const int argn, WRContext* c)
{
if( argn == 1)
{
int address = stackTop[-1].asInt(); // first argument
Wire.beginTransmission( address);
}
}
void Wire_write( WRValue* stackTop, const int argn, WRContext* c)
{
if( argn == 1)
{
int data = stackTop[-1].asInt();
Wire.write( data);
}
else if( argn == 2)
{
// To be added !
}
}
void Wire_endTransmission( WRValue* stackTop, const int argn, WRContext* c)
{
if( argn == 0)
{
int error = Wire.endTransmission();
wr_makeInt( stackTop, error);
}
else if( argn == 1)
{
int stop = stackTop[-1].asInt();
int error = Wire.endTransmission( stop);
wr_makeInt( stackTop, error);
}
}
void Wire_requestFrom( WRValue* stackTop, const int argn, WRContext* c)
{
if( argn == 2)
{
int address = stackTop[-2].asInt(); // first argument
int bytes = stackTop[-1].asInt(); // second argument
int n = Wire.requestFrom( address, bytes);
wr_makeInt( stackTop, n);
}
}
void Wire_available( WRValue* stackTop, const int argn, WRContext* c)
{
if( argn == 0)
{
int n = Wire.available();
wr_makeInt( stackTop, n);
}
}
void Wire_read( WRValue* stackTop, const int argn, WRContext* c)
{
if( argn == 0)
{
int data = Wire.read();
wr_makeInt( stackTop, data);
}
}
*/