-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgcode-tools.c
More file actions
69 lines (53 loc) · 1.87 KB
/
Copy pathgcode-tools.c
File metadata and controls
69 lines (53 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
============================================================================
Name : gcode-tools.c
Author : Radu - Eosif Mihailescu
Version : 1.0 (2012-08-12)
Copyright : (C) 2012 Radu - Eosif Mihailescu <radu.mihailescu@linux360.ro>
Description : G-Code Tool Table Handling Code
============================================================================
*/
#include <stdint.h>
#include <stdio.h>
#include "gcode-commons.h"
#include "gcode-tools.h"
#include "gcode-debugcon.h"
#include "gcode-parameters.h"
static TGCodeTool currentTool;
bool init_tools(void *data) {
int i = 0;
while(fetch_parameter(GCODE_TOOL_TYPE_BASE + i + 1)) i++;
GCODE_DEBUG("Tools up, %d installed, %d supported", i, GCODE_TOOL_COUNT);
return true;
}
TGCodeTool fetch_tool(uint8_t index) {
if(index != currentTool.index) {
currentTool.index = index;
currentTool.type = fetch_parameter(GCODE_TOOL_TYPE_BASE + index);
currentTool.diameter = fetch_parameter(GCODE_TOOL_DIAM_BASE + index);
currentTool.length = fetch_parameter(GCODE_TOOL_LEN_BASE + index);
}
return currentTool;
}
bool update_tool(TGCodeTool tool) {
if(tool.index == currentTool.index) currentTool = tool;
return set_parameter(GCODE_TOOL_TYPE_BASE + tool.index, currentTool.type) &&
set_parameter(GCODE_TOOL_DIAM_BASE + tool.index, currentTool.diameter) &&
set_parameter(GCODE_TOOL_LEN_BASE + tool.index, currentTool.length);
}
double radiusof_tool(uint8_t index) {
if(!index) return 0.0;
if(index != currentTool.index)
return fetch_parameter(GCODE_TOOL_DIAM_BASE + index) / 2.0;
else return currentTool.diameter / 2.0;
}
double lengthof_tool(uint8_t index) {
if(!index) return 0.0;
if(index != currentTool.index)
return fetch_parameter(GCODE_TOOL_LEN_BASE + index);
else return currentTool.length;
}
bool done_tools(void) {
GCODE_DEBUG("Tools down");
return true;
}