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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*
* Scanner.h
*
* Created on: 21 Mar 2017
* Author: Christian
*/
#ifndef SRC_SCANNER_H_
#define SRC_SCANNER_H_
#include "RepRapFirmware.h"
#include "GCodes/GCodeBuffer.h"
#if SUPPORT_SCANNER
const size_t ScanBufferSize = 128; // Buffer for incoming commands
enum class ScannerState
{
Disconnected, // scanner mode is disabled
Idle, // scanner is registered but not active
EnablingAlign, // running align_on.g
DisablingAlign, // running align_off.g
ScanningPre, // running scan_pre.g
Scanning, // 3D scanner is scanning
ScanningPost, // running scan_post.g
PostProcessing, // post-processor is busy
CalibratingPre, // running calibrate_pre.g
Calibrating, // 3D scanner is calibrating
CalibratingPost, // running calibrate_post.g
Uploading // uploading a binary file
};
class Scanner
{
public:
friend class GCodes;
Scanner(Platform& p) : platform(p) { }
void Init();
void Exit();
void Spin();
bool IsEnabled() const { return enabled; } // Is the usage of a 3D scanner enabled?
bool Enable(); // Enable 3D scanner extension. Returns true when done
bool IsRegistered() const; // Is the 3D scanner registered and ready to use?
bool Register(); // Register a 3D scanner. Returns true when done
// External scanners are automatically unregistered when the main port (USB) is closed
bool StartScan(const char *filename, int param); // Start a new 3D scan. Returns true when the scan has been initiated
bool Cancel(); // Cancel current 3D scanner action. Returns true when done
bool Calibrate(); // Calibrate the 3D scanner. Returns true when done
bool SetAlignment(bool on); // Send ALIGN ON/OFF to the 3D scanner. Returns true when done
bool Shutdown(); // Send SHUTDOWN to the scanner and unregisters it
bool DoingGCodes() const { return doingGCodes; } // Has the scanner run any G-codes since the last state transition?
const char GetStatusCharacter() const; // Returns the status char for the status response
float GetProgress() const; // Returns the progress of the current action
private:
GCodeBuffer *serialGCode;
void SetGCodeBuffer(GCodeBuffer *gb);
void SetState(const ScannerState s);
void ProcessCommand();
bool IsDoingFileMacro() const;
void DoFileMacro(const char *filename);
Platform& platform;
bool enabled;
bool doingGCodes;
float progress;
ScannerState state;
char buffer[ScanBufferSize];
size_t bufferPointer;
String<MaxFilenameLength> scanFilename;
int scanParam;
const char *uploadFilename;
size_t uploadSize, uploadBytesLeft;
FileStore *fileBeingUploaded;
};
inline bool Scanner::IsRegistered() const { return (state != ScannerState::Disconnected); }
inline void Scanner::SetGCodeBuffer(GCodeBuffer *gb) { serialGCode = gb; }
#endif
#endif
|