Skip to content

Commit d297ba6

Browse files
initial commit
0 parents  commit d297ba6

File tree

23 files changed

+1442
-0
lines changed

23 files changed

+1442
-0
lines changed

‎.gitignore‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.build
2+
.mbed
3+
projectfiles
4+
*.py*
5+
mbed-os
6+
BUILD
7+
8+
compile_commands.json
9+
.clangd
10+
.cache

‎main.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//=====[Libraries]=============================================================
2+
3+
#include "irrigation_system.h"
4+
5+
//=====[Main function, the program entry point after power on or reset]========
6+
7+
int main()
8+
{
9+
irrigationSystemInit();
10+
while (true) {
11+
irrigationSystemUpdate();
12+
}
13+
}

‎mbed-os.lib‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os.git#26606218ad9d1ee1c8781aa73774fd7ea3a7658e

‎mbed_app.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"target_overrides": {
3+
"*": {
4+
"target.printf_lib": "std"
5+
}
6+
}
7+
}

‎modules/arm_book_lib.h‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//=====[#include guards - begin]===============================================
2+
3+
#ifndef _ARM_BOOK_LIB_H_
4+
#define _ARM_BOOK_LIB_H_
5+
6+
//=====[Libraries]=============================================================
7+
8+
#include <mbed.h>
9+
10+
//=====[Declaration of public defines]=========================================
11+
12+
// Functional states
13+
#ifndef OFF
14+
#define OFF 0
15+
#endif
16+
#ifndef ON
17+
#define ON (!OFF)
18+
#endif
19+
20+
// Electrical states
21+
#ifndef LOW
22+
#define LOW 0
23+
#endif
24+
#ifndef HIGH
25+
#define HIGH (!LOW)
26+
#endif
27+
28+
#define delay(ms) thread_sleep_for( ms )
29+
30+
//=====[#include guards - end]=================================================
31+
32+
#endif // _ARM_BOOK_LIB_H_

‎modules/buttons/buttons.cpp‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//=====[Libraries]=============================================================
2+
3+
#include "mbed.h"
4+
#include "arm_book_lib.h"
5+
6+
#include "buttons.h"
7+
8+
//=====[Declaration of private defines]========================================
9+
10+
//=====[Declaration of private data types]=====================================
11+
12+
//=====[Declaration and initialization of public global objects]===============
13+
14+
static DigitalIn changeModeButton(PG_1);
15+
static DigitalIn howOftenButton(PF_9);
16+
static DigitalIn howLongButton(PF_7);
17+
static DigitalIn moistureButton(PF_8);
18+
19+
//=====[Declaration of external public global variables]=======================
20+
21+
//=====[Declaration and initialization of public global variables]=============
22+
23+
//=====[Declaration and initialization of private global variables]============
24+
25+
static buttonsStatus_t buttonsStatus;
26+
27+
//=====[Implementations of public functions]===================================
28+
29+
void buttonsInit()
30+
{
31+
changeModeButton.mode(PullUp);
32+
howOftenButton.mode(PullUp);
33+
howLongButton.mode(PullUp);
34+
moistureButton.mode(PullUp);
35+
36+
buttonsStatus.changeMode = OFF;
37+
buttonsStatus.howOften = HOW_OFTEN_MIN;
38+
buttonsStatus.howLong = HOW_LONG_MIN;
39+
buttonsStatus.moisture = MOISTURE_MIN;
40+
}
41+
42+
void buttonsUpdate()
43+
{
44+
buttonsStatus.changeMode = !changeModeButton;
45+
46+
if ( !howOftenButton ) {
47+
buttonsStatus.howOften = buttonsStatus.howOften + HOW_OFTEN_INCREMENT;
48+
if ( buttonsStatus.howOften >= HOW_OFTEN_MAX + HOW_OFTEN_INCREMENT) {
49+
buttonsStatus.howOften = HOW_OFTEN_MIN;
50+
}
51+
}
52+
53+
if ( !howLongButton ) {
54+
buttonsStatus.howLong = buttonsStatus.howLong + HOW_LONG_INCREMENT;
55+
if ( buttonsStatus.howLong >= HOW_LONG_MAX + HOW_LONG_INCREMENT) {
56+
buttonsStatus.howLong = HOW_LONG_MIN;
57+
}
58+
}
59+
60+
if ( !moistureButton ) {
61+
buttonsStatus.moisture = buttonsStatus.moisture + MOISTURE_INCREMENT;
62+
if ( buttonsStatus.moisture >= MOISTURE_MAX + MOISTURE_INCREMENT) {
63+
buttonsStatus.moisture = MOISTURE_MIN;
64+
}
65+
}
66+
}
67+
68+
buttonsStatus_t buttonsRead()
69+
{
70+
return buttonsStatus;
71+
}

‎modules/buttons/buttons.h‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//=====[#include guards - begin]===============================================
2+
3+
#ifndef _BUTTONS_H_
4+
#define _BUTTONS_H_
5+
6+
//=====[Declaration of public defines]=========================================
7+
8+
#define HOW_OFTEN_INCREMENT 1
9+
#define HOW_OFTEN_MIN 1
10+
#define HOW_OFTEN_MAX 24
11+
#define HOW_LONG_INCREMENT 10
12+
#define HOW_LONG_MIN 0
13+
#define HOW_LONG_MAX 90
14+
#define MOISTURE_INCREMENT 5
15+
#define MOISTURE_MIN 0
16+
#define MOISTURE_MAX 95
17+
18+
//=====[Declaration of public data types]======================================
19+
20+
typedef struct buttonsStatus {
21+
bool changeMode;
22+
int howOften;
23+
int howLong;
24+
int moisture;
25+
} buttonsStatus_t;
26+
27+
//=====[Declarations (prototypes) of public functions]=========================
28+
29+
void buttonsInit();
30+
void buttonsUpdate();
31+
buttonsStatus_t buttonsRead();
32+
33+
//=====[#include guards - end]=================================================
34+
35+
#endif // _BUTTONS_H_

0 commit comments

Comments
 (0)