File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 77/**
88 * DS1302 block
99 */
10- //% weight=100 color=#A040E0 icon="\uf017" block="RTC DS1302"
10+ //% weight=100 color=#A040E0 icon="\uf017" block="RTC DS1302"
1111namespace DS1302 {
1212 let DS1302_REG_SECOND = 0x80
1313 let DS1302_REG_MINUTE = 0x82
@@ -125,7 +125,9 @@ namespace DS1302 {
125125 //% weight=78 blockGap=8
126126 //% parts="DS1302"
127127 getMonth ( ) : number {
128- return HexToDec ( this . getReg ( DS1302_REG_MONTH + 1 ) )
128+ let d = HexToDec ( this . getReg ( DS1302_REG_MONTH + 1 ) )
129+ if ( ( d < 1 ) || ( d > 12 ) ) return 1
130+ return d
129131 }
130132
131133 /**
@@ -147,7 +149,9 @@ namespace DS1302 {
147149 //% weight=76 blockGap=8
148150 //% parts="DS1302"
149151 getDay ( ) : number {
150- return HexToDec ( this . getReg ( DS1302_REG_DAY + 1 ) )
152+ let d = HexToDec ( this . getReg ( DS1302_REG_DAY + 1 ) )
153+ if ( ( d < 1 ) || ( d > 31 ) ) return 1
154+ return d
151155 }
152156
153157 /**
@@ -169,7 +173,9 @@ namespace DS1302 {
169173 //% weight=74 blockGap=8
170174 //% parts="DS1302"
171175 getWeekday ( ) : number {
172- return HexToDec ( this . getReg ( DS1302_REG_WEEKDAY + 1 ) )
176+ let d = HexToDec ( this . getReg ( DS1302_REG_WEEKDAY + 1 ) )
177+ if ( ( d < 1 ) || ( d > 7 ) ) return 1
178+ return d
173179 }
174180
175181 /**
You can’t perform that action at this time.
0 commit comments