SBB Micro
Source code for the self-balancing-bike microcontroller unit (Teensy 4.1-based). 🚀️
Loading...
Searching...
No Matches
sbbmtp.h
Go to the documentation of this file.
1
2#ifndef __MTP_H__
3#define __MTP_H__
4
10
11//defines
12#define DOMTP 1
13#define STORAGENAME "SBB Logger"
14#define MTP_ENABLE_TIMEOUT 3000
15
16#if DOMTP == 1 //must exist both DOMTP and DOLOG for enabling MTP!
17
18//check mtp function
19bool check_mtp(void) {
20 uint32_t mtp_timer = millis();
21 while ((millis()-mtp_timer) <= MTP_ENABLE_TIMEOUT) {
22 if (digitalReadFast(ONOFF_STATE_PIN)) { return false; }
23 delay(100); //wait 100ms for the next check
24 }
25 if (!sd.begin(SD_CONFIG)) { return false; }
26 LEDmode = LedMode::MTPWAIT; //set LEDmode to MTPWAIT by default
27 return true;
28}
29
30//do mtp
31void do_mtp(void) {
32 //create mtp objects (local object to not leak RAM in 'normal' mode)
33 MTPStorage_SD storage; //storate obj for mtp
34 MTPD mtpd(&storage); //mtp obj
35 //add SD to storage
36 storage.addFilesystem(SD, STORAGENAME);
37 //wait for USB connected
38 while (true) {
39 if (USB_CONNECTED) {
41 mtpd.loop();
42 }
43 else
45 if ((micros() - sampling_timer) >= SAMPLING_TIME) {
46 sampling_timer = micros(); //update timer
47 do_led();
48 }
49 }
50}
51
52
53#else //empty funs if not mtp
54bool check_mtp(void) {return false;} //return false if not mtp
55void do_mtp(void) {}
56//add more empty logging functions here if necessary
57
58#endif
59#endif
#define SAMPLING_TIME
Sampling time of the control loop (us).
Definition config.h:119
#define SD_CONFIG
Configuration type of sd card.
Definition logger.h:15
#define sd
SD fat object (uses sd fat included in SD library).
Definition logger.h:14
#define USB_CONNECTED
Macro for checking the USB connection status-.
Definition config.h:309
bool check_mtp(void)
Check for MTP mode.
Definition sbbmtp.h:19
#define STORAGENAME
MTP storage name.
Definition sbbmtp.h:13
void do_mtp(void)
Run MTP mode.
Definition sbbmtp.h:31
#define MTP_ENABLE_TIMEOUT
Timeout for enabling MTP mode (ms).
Definition sbbmtp.h:14
#define ONOFF_STATE_PIN
Digital in for on/off buttun state (diode between onoff and this).
Definition config.h:103
void do_led()
Management of the status LED.
Definition userfun.h:418
uint32_t sampling_timer
Timer for the main cycle.
Definition objects.h:217
int8_t LEDmode
LED mode variable.
Definition objects.h:220
constexpr int8_t MTPWAIT
MTP wait for USB connected.
Definition objects.h:35
constexpr int8_t MTP
MTP mode.
Definition objects.h:33