Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Scanner.h « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 464a9f6129ae321511c532b3d8eb9b5bda56e15c (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Scanner.h
 *
 *  Created on: 21 Mar 2017
 *      Author: Christian
 */

#ifndef SRC_SCANNER_H_
#define SRC_SCANNER_H_

#include "RepRapFirmware.h"
#include "GCodes/GCodeBuffer/GCodeBuffer.h"
#include "ObjectModel/ObjectModel.h"

#if SUPPORT_SCANNER

#define SCANNER_AS_SEPARATE_TASK	(0)					// set to 1 to use a separate task for the scanner (requires RTOS enabled too)
//#define SCANNER_AS_SEPARATE_TASK	(defined(RTOS))		// set to 1 to use a separate task for the scanner (requires RTOS enabled too)

const size_t ScanBufferSize = 128;						// Size of the 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 INHERIT_OBJECT_MODEL
{
public:
	friend class GCodes;

	Scanner(Platform& p) noexcept : platform(p) { }
	void Init() noexcept;
	void Exit() noexcept;
	void Spin() noexcept;

	bool IsEnabled() const noexcept { return enabled; }			// Is the usage of a 3D scanner enabled?
	bool Enable() noexcept;										// Enable 3D scanner extension. Returns true when done

	bool IsRegistered() const noexcept;							// Is the 3D scanner registered and ready to use?
	void Register() noexcept;									// Register a 3D scanner instance
	// External scanners are automatically unregistered when the main port (USB) is closed

	// Start a new 3D scan. Returns true when the scan has been initiated
	bool StartScan(const char *filename, int param, int resolution, int mode) noexcept;

	bool Cancel() noexcept;										// Cancel current 3D scanner action. Returns true when done
	bool Calibrate(int mode) noexcept;							// Calibrate the 3D scanner. Returns true when done
	bool SetAlignment(bool on) noexcept;						// Send ALIGN ON/OFF to the 3D scanner. Returns true when done
	bool Shutdown() noexcept;									// Send SHUTDOWN to the scanner and unregisters it

	bool DoingGCodes() const noexcept { return doingGCodes; }	// Has the scanner run any G-codes since the last state transition?
	const char GetStatusCharacter() const noexcept;				// Returns the status char for the status response
	float GetProgress() const noexcept;							// Returns the progress of the current action

protected:
	DECLARE_OBJECT_MODEL

private:
	GCodeBuffer *serialGCode;

	void SetGCodeBuffer(GCodeBuffer *gb) noexcept;

	void SetState(const ScannerState s) noexcept;
	void ProcessCommand() noexcept;

	bool IsDoingFileMacro() const noexcept;
	void DoFileMacro(const char *filename) noexcept;

	Platform& platform;

	bool enabled;

	bool doingGCodes;
	float progress;
	ScannerState state;

	char buffer[ScanBufferSize];
	size_t bufferPointer;

	int calibrationMode;

	String<MaxFilenameLength> scanFilename;
	int scanRange, scanResolution, scanMode;

	const char *uploadFilename;
	size_t uploadSize, uploadBytesLeft;
	FileStore *fileBeingUploaded;
};

inline bool Scanner::IsRegistered() const noexcept { return (state != ScannerState::Disconnected); }
inline void Scanner::SetGCodeBuffer(GCodeBuffer *gb) noexcept { serialGCode = gb; }

#endif

#endif