1
00:00:00,660 --> 00:00:07,140
In this election, we'll show you how to split the original single final version of this many projects

2
00:00:07,260 --> 00:00:15,360
script into two separate files and that we will want to revise the script to make it easier to write

3
00:00:15,360 --> 00:00:16,450
and to maintain.

4
00:00:17,760 --> 00:00:23,880
Let's have a look at the main script first to call it Modula here, and then the one that holds the

5
00:00:23,880 --> 00:00:28,310
individual functions in some of the variables will call it modules.

6
00:00:29,070 --> 00:00:33,330
So the main part of the script looks like this.

7
00:00:33,820 --> 00:00:41,430
I've got only the necessary modules, external modules included, and of course, necessary variables

8
00:00:41,430 --> 00:00:48,870
here, including the got I could see object to the display object and the being the object and they'll

9
00:00:48,870 --> 00:00:50,790
be parsing whenever necessary.

10
00:00:50,790 --> 00:00:55,480
I'll be passing those objects across to the functions in the other file.

11
00:00:56,280 --> 00:01:01,460
I also have the settings file here and I create the wireless object.

12
00:01:01,910 --> 00:01:06,980
Now, just before I continue, just to know that there are many different ways by which you can do that.

13
00:01:07,050 --> 00:01:14,400
For example, some of those variables, you could choose to put them into a second supporting file or

14
00:01:14,580 --> 00:01:18,140
even a third file and distribute them in different ways.

15
00:01:18,420 --> 00:01:24,780
But this was just the first iteration, the first version of the modular version of the script.

16
00:01:25,080 --> 00:01:28,290
And it's a possible approach, not the only approach.

17
00:01:29,190 --> 00:01:33,990
The only function in the main script is this one here at time.

18
00:01:34,460 --> 00:01:38,730
So I could have moved that to the other side as well.

19
00:01:38,910 --> 00:01:47,370
But it is just simpler to keep the time ISO function in the main part of my script in the main file

20
00:01:47,520 --> 00:01:54,180
just makes it easier to use and everything is identical here, as you've seen in the previous version

21
00:01:54,180 --> 00:01:54,870
of the program.

22
00:01:54,910 --> 00:01:59,420
So here's a program as you saw it in the previous lecture.

23
00:01:59,670 --> 00:02:01,830
Here's a time I said function.

24
00:02:01,830 --> 00:02:12,090
And here in this version of that, it is this addition into the if statement that decides whether to

25
00:02:12,090 --> 00:02:22,890
call the post to efficient that function and just edit the event equals one option here, because what

26
00:02:22,890 --> 00:02:30,570
I want to do is to make sure that the post to efficient that is called the very first time that I'm

27
00:02:30,570 --> 00:02:34,890
explicitly calling time ISO when I'm doing the test.

28
00:02:35,340 --> 00:02:43,320
So if this line of code down here, one of four is uncommented, then I'm passing number one to time

29
00:02:43,320 --> 00:02:46,260
ISO and that will be picked up right here.

30
00:02:46,410 --> 00:02:54,090
And that will allow me to definitely test posta if this isn't that what I'm doing, debugging, regardless

31
00:02:54,090 --> 00:02:59,460
of what the temperature is, there's just a debugging improvement here that I've made compared to the

32
00:02:59,460 --> 00:03:00,360
previous version.

33
00:03:00,750 --> 00:03:01,850
Nothing fancy, really.

34
00:03:02,610 --> 00:03:03,960
The rest is all the same.

35
00:03:03,990 --> 00:03:10,740
Now, what's more interesting to talk about here is what changes in the code, because obviously when

36
00:03:10,740 --> 00:03:18,150
I split a single file into two files is not just moving things around to the way that I'm calling those

37
00:03:18,150 --> 00:03:20,340
things also needs to be adjusted.

38
00:03:20,730 --> 00:03:24,370
So let's cut to the top again and have a look at the inputs.

39
00:03:24,780 --> 00:03:29,790
Now, all of the inputs here you recognize from the original version, version of the one, but a new

40
00:03:29,790 --> 00:03:30,740
one is this.

41
00:03:30,750 --> 00:03:38,250
So now I'm importing this supporting secondary file code or it'd be a meta edit if this is that and

42
00:03:38,250 --> 00:03:46,980
this module P y and I'm taking the name of this file without extension and importing it as a module,

43
00:03:47,400 --> 00:03:50,630
you can see that it's stored right here in the file system.

44
00:03:50,970 --> 00:03:56,910
It's called the modules, part of my two scripts software side of the project.

45
00:03:58,620 --> 00:04:04,750
And because this is a very long name to be using in my script, I'm just renaming it into modules.

46
00:04:05,130 --> 00:04:10,590
So now you can see that, for example, down here, if I want to call the do connect function that is

47
00:04:10,590 --> 00:04:15,210
inside this file, I need to prepare it with more same modules.

48
00:04:15,210 --> 00:04:21,550
DOT do connect and then I have to pass the necessary parameters in this case.

49
00:04:21,600 --> 00:04:30,150
Do connect and she can see requires access to the wireless network object and the settings object because

50
00:04:30,150 --> 00:04:35,160
it's referenced here to grab the Wi-Fi network name and password.

51
00:04:35,380 --> 00:04:40,950
So I'm passing those as parameters now where originally I didn't have to because everything was part

52
00:04:40,950 --> 00:04:42,630
of the same global set of parameters.

53
00:04:43,140 --> 00:04:50,280
So here it's got to connect parentheses, first parameter wassmann, landslided parameter settings,

54
00:04:50,520 --> 00:04:53,850
and then this function is called and it's executed.

55
00:04:54,220 --> 00:05:00,810
You can see that this test a little earlier for the recording and you can see that the output of this

56
00:05:00,810 --> 00:05:08,520
function appears in the shell and it's the connecting network right here.

57
00:05:11,050 --> 00:05:16,990
Another thing that I've done, obviously, in both versions of the program is to have lots and lots

58
00:05:16,990 --> 00:05:22,540
of shell printouts to help me with the so you can see it every opportunity, of course, to print out

59
00:05:22,540 --> 00:05:28,330
telling me what is going on so I can then have a look at the output and figure out whether things are

60
00:05:28,330 --> 00:05:29,890
working or if they're not working.

61
00:05:29,890 --> 00:05:32,750
Gives me clues about what it is that I need to fix.

62
00:05:34,060 --> 00:05:35,680
So that's what's happening here.

63
00:05:35,680 --> 00:05:43,930
With Do Connect are the functions that need to pass parameters to things such as, for example, the

64
00:05:44,770 --> 00:05:46,600
function that draws the display.

65
00:05:46,660 --> 00:05:57,130
So this one is electrostatic screen and I'm passing the display object because this function creates

66
00:05:57,130 --> 00:06:02,050
or printed out the left part of the display of the image and the display.

67
00:06:02,060 --> 00:06:03,330
That doesn't change.

68
00:06:03,640 --> 00:06:08,680
So I needed to pass the display object so that then I can write a text to it.

69
00:06:09,160 --> 00:06:10,440
OK, so that's about it.

70
00:06:10,450 --> 00:06:13,540
There's nothing else really here worth talking about.

71
00:06:13,990 --> 00:06:20,200
I do invite you to carefully study these two files and see how they interact and how they work.

72
00:06:20,660 --> 00:06:23,600
But I'm just going to go ahead and run it now.

73
00:06:23,830 --> 00:06:26,810
I mean, debugging mode, so I'm only going to run the timer.

74
00:06:27,040 --> 00:06:33,610
So once instead of going through the actual timer, interrupt, set up and running it and calling it

75
00:06:33,610 --> 00:06:36,820
every one second to make sure that things are working first.

76
00:06:43,020 --> 00:06:45,120
No, I had an issue here and it didn't.

77
00:06:45,180 --> 00:06:49,400
So you can see here that he was unable to connect to Wi-Fi.

78
00:06:49,410 --> 00:06:56,670
For some reason it's given me and already surprising error to zero, to which I don't really know what

79
00:06:56,670 --> 00:06:57,140
it means.

80
00:06:57,220 --> 00:07:04,930
I did some search, but this information is not very well, not very helpful, to say the least.

81
00:07:05,280 --> 00:07:05,910
So.

82
00:07:07,760 --> 00:07:16,550
At this point, I know that my script of the Wi-Fi connection does work, but mainly to try out to to

83
00:07:16,550 --> 00:07:20,590
run the script repeatedly until it gets it into the connection happens.

84
00:07:21,050 --> 00:07:25,060
So going to clear and run the script again.

85
00:07:26,450 --> 00:07:28,400
OK, and now second time.

86
00:07:30,930 --> 00:07:37,320
We did get medical configuration, so we did have a connection and you can see we've got a time, which

87
00:07:37,320 --> 00:07:46,350
is a good thing, and we got a if they sent that notification that appears right here, just arrived

88
00:07:46,890 --> 00:07:52,560
in Russia, it seems like everything is working except for that intermediate refusal to connect to my

89
00:07:52,560 --> 00:07:55,280
Wi-Fi network originally.

90
00:07:55,290 --> 00:07:59,250
So let's try now to run Descript.

91
00:08:01,260 --> 00:08:04,220
Properly, which means setting up the timeline as well.

92
00:08:07,730 --> 00:08:08,060
OK.

93
00:08:19,610 --> 00:08:27,050
All right, so you may notice that in the beginning you stop this, actually see if I can go back.

94
00:08:29,400 --> 00:08:30,300
Right here.

95
00:08:30,960 --> 00:08:38,670
So notice that in the beginning, the DP 32 was not able, for some reason to connect to Wi-Fi, so

96
00:08:38,670 --> 00:08:39,710
it failed at this point.

97
00:08:40,020 --> 00:08:49,650
But next time that the connection function was called, he was able to to do connect and then he was

98
00:08:49,650 --> 00:08:51,930
able to acquire the Internet.

99
00:08:51,930 --> 00:08:53,500
Time to get home connected.

100
00:08:53,520 --> 00:08:53,850
Yes.

101
00:08:53,860 --> 00:08:57,510
That means that it went to the Internet time server who was able to get the time.

102
00:08:57,840 --> 00:09:02,350
And after that, we were able to synchronize and sync the ATC with the Internet time.

103
00:09:02,370 --> 00:09:10,170
And from that point on which the script will not need to rethink ATC with at Internet time, I'll just

104
00:09:10,620 --> 00:09:14,940
get that time from the real time clock and speed on the screen every one second.

105
00:09:17,380 --> 00:09:22,990
All right, so it seems like it's working properly, I'm going to run this one more time.

106
00:09:34,980 --> 00:09:37,080
And there you go, the script works.

107
00:09:38,050 --> 00:09:40,440
Updates every one second.

108
00:09:41,350 --> 00:09:42,670
According to the.

109
00:09:43,900 --> 00:09:51,010
Period of the timeline of the hardware timer and the interrupt service routine.

110
00:09:59,500 --> 00:10:00,940
And those are generated.

111
00:10:03,510 --> 00:10:09,030
So that's an example of how you can split a large micro Python script into.

112
00:10:09,820 --> 00:10:10,770
And one fires.
