Skip to content

Commit

Permalink
Add Cmake support and fix LL driver for win32
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Dec 12, 2021
1 parent 2175b32 commit b0e2128
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x86"
"intelliSenseMode": "windows-gcc-x86",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
Expand Down
39 changes: 16 additions & 23 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Debug program",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\LwOW.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build project"
}
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\LwOW.exe",
"miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "integratedTerminal"
}
]
}
}
13 changes: 9 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
{
"type": "cppbuild",
"label": "Build project",
"command": "ninja",
"command": "cmake",
"args": [
"-C \"build\""
"--build",
"\"build\""
],
"options": {
"cwd": "${workspaceFolder}"
Expand All @@ -30,13 +31,17 @@
{
"type": "shell",
"label": "Clean project",
"command": "ninja",
"command": "cmake",
"args": [
"-C \"build\" clean"
"--build",
"\"build\"",
"--target",
"clean"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": []
},
{
"type": "shell",
Expand Down
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ add_executable(${PROJECT_NAME}
lwow/src/system/lwow_sys_win32.c
lwow/src/devices/lwow_device_ds18x20.c
snippets/scan_devices.c
dev/VisualStudio/main.c)
dev/VisualStudio/main.c
)

target_include_directories(${PROJECT_NAME} PRIVATE
dev/VisualStudio
lwow/src/include/
lwow/src/include
snippets/include
)

target_compile_definitions(${PROJECT_NAME} PRIVATE
WIN32
_DEBUG
CONSOLE
TEST_CONSOLE_123
)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
Expand Down
36 changes: 32 additions & 4 deletions dev/VisualStudio/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ int
main(void) {
printf("Starting OneWire application..\r\n");

lwow_init(&ow, &lwow_ll_drv_win32, NULL); /* Initialize 1-Wire library and set user argument to 1 */
/* Initialize 1-Wire library and set user argument to 1 */
if (lwow_init(&ow, &lwow_ll_drv_win32, NULL) != lwowOK) {
printf("Could not initialize LwOW..\r\n");
while (1) { Sleep(1000); }
}

/* Get onewire devices connected on 1-wire port */
while (1) {
/*
* Scan for devices connected on 1-wire port
*
* This is a pre-defined function from snippets part of the lib
*/
printf("Scanning 1-Wire port...\r\n");
if (scan_onewire_devices(&ow, rom_ids, LWOW_ARRAYSIZE(rom_ids), &rom_found) == lwowOK) {
printf("Devices scanned, found %d device%s!\r\n", (int)rom_found, "s" + (rom_found == 1));
Expand All @@ -35,11 +44,24 @@ main(void) {
for (size_t c = 0; c < 5; c++) {
printf("Start temperature conversion\r\n");

lwow_ds18x20_start(&ow, NULL); /* Start conversion on all devices */
Sleep(1500); /* Release thread for 1 second */
/*
* Enable OW protection, to prevent access
* from other threads to the OW core
*/
lwow_protect(&ow, 1);

/* Start temperature conversion on all DS18x20 devices */
lwow_ds18x20_start_raw(&ow, NULL);

/*
* Sleep for some time
*
* Keep OW core protected to make sure
* other threads won't reset the bus and reset measurement being in process
*/
Sleep(2000);

/* Read temperature on all devices */
lwow_protect(&ow, 1);
for (size_t i = 0; i < rom_found; ++i) {
if (lwow_ds18x20_is_b(&ow, &rom_ids[i])) {
float temp;
Expand All @@ -50,6 +72,12 @@ main(void) {
}
}
}

/*
* Sensors are now idle, data has been read well
*
* Release access to allow other threads to get access
*/
lwow_unprotect(&ow, 1);
}
}
Expand Down
10 changes: 7 additions & 3 deletions lwow/src/system/lwow_ll_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ init(void* arg) {

/* Try to set com port data */
if (!SetCommState(com_port, &dcb)) {
printf("Cannot get COM port\r\n");
printf("Cannot get COM port..\r\n");
return 0;
}

Expand All @@ -90,12 +90,16 @@ init(void* arg) {
timeouts.ReadTotalTimeoutConstant = 0;
timeouts.ReadTotalTimeoutMultiplier = 0;
if (!SetCommTimeouts(com_port, &timeouts)) {
printf("Cannot set COM PORT timeouts\r\n");
printf("Cannot set COM PORT timeouts..\r\n");
}
GetCommTimeouts(com_port, &timeouts);
} else {
printf("Cannot get communication timeouts..\r\n");
return 0;
}
} else {
printf("Cannot get COM port info\r\n");
printf("Cannot get COM port info..\r\n");
return 0;
}

return 1;
Expand Down

0 comments on commit b0e2128

Please sign in to comment.