Skip to content

Commit

Permalink
(+) -DCEUMAKER_*
Browse files Browse the repository at this point in the history
  • Loading branch information
fsantanna committed Jul 27, 2017
1 parent dc4ea13 commit 5e56377
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ceu-maker/run/make-arduino.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set PATH=%~dp0\..\mingw\bin

cd %~dp0

lua53.exe ceu.lua --pre --pre-args="-Iceu\include" --pre-input="%CEU_SRC%" --ceu --ceu-err-unused=pass --ceu-err-uninitialized=pass --ceu-features-lua=false --ceu-features-thread=false --ceu-features-isr=%CEU_ISR% --env --env-types=ceu\env\arduino\env\types.h --env-output=ceu\env\arduino\env\_ceu_app.c.h
lua53.exe ceu.lua --pre --pre-args="-Iceu\include -DCEUMAKER_ARDUINO" --pre-input="%CEU_SRC%" --ceu --ceu-err-unused=pass --ceu-err-uninitialized=pass --ceu-features-lua=false --ceu-features-thread=false --ceu-features-isr=%CEU_ISR% --env --env-types=ceu\env\arduino\env\types.h --env-output=ceu\env\arduino\env\_ceu_app.c.h
if ERRORLEVEL 1 goto ERROR

..\arduino-1.8.3\arduino.exe --board arduino:%ARD_ARCH%:%ARD_BOARD%%ARD_CPU% --port %ARD_PORT% --upload ceu\env\arduino\env\env.ino
Expand Down
2 changes: 1 addition & 1 deletion ceu-maker/run/make-pico.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ copy dist\*.* %CEU_DIR%\dist\ >NUL
copy %CEU_DIR%\res\*.* %CEU_DIR%\dist\res\ >NUL
copy res\*.* %CEU_DIR%\dist\res\ >NUL

lua53.exe ceu.lua --pre --pre-args="-Iceu\include -DCEU_SRC=%CEU_SRC%" --pre-input="ceu\pico.ceu" --ceu --ceu-err-unused=pass --ceu-err-uninitialized=pass --env --env-types=ceu\env\types.h --env-main=ceu\env\main.c --cc --cc-args="-Ic\include -Lc\lib -lm -lmingw32 -lSDL2main -lSDL2 -lSDL2_gfx -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lSDL2_net" --cc-output=%CEU_DIR%\dist\tmp.exe
lua53.exe ceu.lua --pre --pre-args="-Iceu\include -DCEU_SRC=%CEU_SRC% -DCEUMAKER_PICO" --pre-input="ceu\pico.ceu" --ceu --ceu-err-unused=pass --ceu-err-uninitialized=pass --env --env-types=ceu\env\types.h --env-main=ceu\env\main.c --cc --cc-args="-Ic\include -Lc\lib -lm -lmingw32 -lSDL2main -lSDL2 -lSDL2_gfx -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lSDL2_net" --cc-output=%CEU_DIR%\dist\tmp.exe
if ERRORLEVEL 1 goto ERROR

cd %CEU_DIR%\dist\
Expand Down
123 changes: 123 additions & 0 deletions ceu-maker/samples/both/serial.ceu
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#ifdef CEUMAKER_ARDUINO

#include "arduino/arduino.ceu"

native/pre do
//##define CEU_ARDUINO_SERIAL_SPEED 9600
end

input byte SERIAL;
output bool PIN_13;

loop do
var byte a = _;
var byte b = _;
var byte c = _;

a = await SERIAL;

emit PIN_13(true);
b = await SERIAL;

do
spawn do
loop do
await 2s;
emit PIN_13(true);
await 2s;
emit PIN_13(false);
end
end
c = await SERIAL;
end

spawn do
loop do
await 250ms;
emit PIN_13(true);
await 250ms;
emit PIN_13(false);
end
end

_Serial.write(a);
_Serial.write(b);
_Serial.write(c);

await FOREVER;
end

#elif defined CEUMAKER_PICO

native/pre do
##include <windows.h>
end

{
// OPEN

HANDLE hSerial = CreateFile("COM3",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
ceu_dbg_assert(hSerial != INVALID_HANDLE_VALUE);

DCB dcbSerialParams = {0};
ceu_dbg_assert(GetCommState(hSerial,&dcbSerialParams));

dcbSerialParams.BaudRate = CBR_9600;
dcbSerialParams.ByteSize = 8;
dcbSerialParams.StopBits = ONESTOPBIT;
dcbSerialParams.Parity = NOPARITY;
dcbSerialParams.fDtrControl = DTR_CONTROL_ENABLE;
ceu_dbg_assert(SetCommState(hSerial, &dcbSerialParams));

PurgeComm(hSerial, PURGE_RXCLEAR | PURGE_TXCLEAR);
Sleep(2000);

// WRITE
{
const char* buffer = "ola";
int nbChar = 3;
DWORD bytesSend;

ceu_dbg_assert(WriteFile(hSerial, (void*)buffer, nbChar, &bytesSend, 0));
ceu_dbg_assert(bytesSend == nbChar);
printf(">>> sent\n");

//COMSTAT status;
//DWORD errors;
//ClearCommError(this->hSerial, &this->errors, &this->status);
}

// READ
{
char buffer[10];
DWORD bytesRead;

while (1) {
COMSTAT status;
DWORD errors;
ClearCommError(hSerial, &errors, &status);
if (status.cbInQue == 3) {
break;
}
}
ceu_dbg_assert(ReadFile(hSerial, buffer, 3, &bytesRead, NULL));
ceu_dbg_assert(bytesRead == 3);

buffer[3] = '\0';
printf(">>> %s\n", buffer);
}

// CLOSE

CloseHandle(hSerial);
}

await FOREVER;

#endif

0 comments on commit 5e56377

Please sign in to comment.