Explorar o código

Merge pull request #49 from jancoow/DisplayOptimalisations

Display optimalisations
Remco %!s(int64=9) %!d(string=hai) anos
pai
achega
857021afd8
Modificáronse 14 ficheiros con 37 adicións e 141 borrados
  1. 1 0
      alarm.c
  2. 6 7
      alarm.h
  3. 9 9
      contentparser.c
  4. 0 60
      display.c
  5. 3 1
      jsmn.c
  6. 0 13
      keyboard.c
  7. 1 1
      keyboard.h
  8. 1 8
      main.c
  9. 5 2
      network.c
  10. 4 4
      network.h
  11. 4 22
      ntp.c
  12. 3 3
      ntp.h
  13. 0 3
      uart0driver.c
  14. 0 8
      vs10xx.c

+ 1 - 0
alarm.c

@@ -4,6 +4,7 @@
 #include <string.h>
 #include <time.h>
 #include <assert.h>
+#include <math.h>
 
 #include "log.h"
 #include "rtc.h"

+ 6 - 7
alarm.h

@@ -1,10 +1,7 @@
 /* Alarm get/set status values */
-#define ALARM_1 	5
-#define ALARM_2		6
-
-#define AFLGS		0b11111111
 
 #ifndef _ALARM_DEFINED
+#define _ALARM_DEFINED
 struct _alarm
 {
 	struct _tm time;
@@ -16,8 +13,6 @@ struct _alarm
 	int id;
 	int state;
 };
-#define _ALARM_DEFINED
-#endif
 
 void handleAlarm(int idx);
 int checkAlarms(void);
@@ -27,4 +22,8 @@ void deleteAlarm(int idx);
 int compareTime(tm t1, tm t2);
 void setState(int idx);
 int getState(int idx);
-struct _alarm getAlarm(int idx);
+struct _alarm getAlarm(int idx);
+int maxAlarms(void);
+int isLeapYear(int y);
+void setSnooze(int idx);
+#endif

+ 9 - 9
contentparser.c

@@ -12,7 +12,9 @@
 
 void parseAlarmJson(char* content){
     int r;
-    int i = 2;
+    int i;
+    int usedAlarms[maxAlarms()];
+    int j;
     jsmn_parser p;
     jsmntok_t token[160]; /* We expect no more than 128 tokens */
 
@@ -25,16 +27,15 @@ void parseAlarmJson(char* content){
         printf("Aantal tokens found: %d \n", r);
     }
 
-    int usedAlarms[maxAlarms()];
-    int j;
+
     struct _tm time = GetRTCTime();
     for(j = 0; j < maxAlarms(); j++){
         usedAlarms[j] = 0;
     }
-    for(i; i < r; i++)
+    for(i = 2; i < r; i++)
     {
-        int id;
-        u_short port;
+        int id = 0;
+        u_short port = 0;
         char url[24];
         char ip[24];
         char name[16];
@@ -44,7 +45,7 @@ void parseAlarmJson(char* content){
         memset(ip, 0, 24);
         memset(name, 0, 17);
 
-        for (i; (st == -1 && i < r); i+=2) {                                //Zodra ST is gevonden, betekent dit de laatste token van een alarm.
+        for (i = i; (st == -1 && i < r); i+=2) {                                //Zodra ST is gevonden, betekent dit de laatste token van een alarm.
             if (jsoneq(content, &token[i], "YYYY") == 0) {
                 time.tm_year= getIntegerToken(content, &token[i + 1]) - 1900;
             }else if (jsoneq(content, &token[i], "MM") == 0) {
@@ -68,7 +69,7 @@ void parseAlarmJson(char* content){
             }else if (jsoneq(content, &token[i], "name") == 0) {
                 getStringToken(content, &token[i + 1], name);
             }else if (jsoneq(content, &token[i], "oo") == 0) {
-                getStringToken(content, &token[i + 1], oo);
+                oo = getIntegerToken(content, &token[i + 1]);
             }else if (jsoneq(content, &token[i], "st") == 0) {
                 st = getIntegerToken(content, &token[i + 1]);
                 i+=2;
@@ -151,4 +152,3 @@ void parsetimezone(char* content)
     int timezone = atoi(content);
     setTimeZone(timezone);
 }
-

+ 0 - 60
display.c

@@ -42,33 +42,6 @@ static void LcdWriteByte(u_char, u_char);
 static void LcdWriteNibble(u_char, u_char);
 static void LcdWaitBusy(void);
 
-int timerLCD(u_char Mode){
-    time_t Start;
-    if(Mode == startLCD)
-    {
-            time_t diff = time(0) - Start;
-            return diff;
-    }
-    else if(Mode == stopLCD)
-    {
-        Start = time(0);
-    }
-}
-/*!
- * \addtogroup Display
- */
-
-/*@{*/
-
-/*-------------------------------------------------------------------------*/
-/*                         start of code                                   */
-/*-------------------------------------------------------------------------*/
-
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief control backlight
- */
-/* ����������������������������������������������������������������������� */
 void LcdBackLight(u_char Mode)
 {
     if (Mode==LCD_BACKLIGHT_ON)
@@ -82,39 +55,6 @@ void LcdBackLight(u_char Mode)
     }
 }
 
-
-/* ����������������������������������������������������������������������� */
-
-/*
- * Lcdbacklight knipperen
- */
-
-void LcdBacklightKnipperen(u_char Mode)
-{
-    time_t Start;
-    time_t Stop;
-    if (Mode==startLCD)
-    {
-        sbi(LCD_BL_PORT, LCD_BL_BIT);   // Turn on backlight
-        timer(Start);
-    }
-    if (Mode==stopLCD)
-    {
-        cbi(LCD_BL_PORT, LCD_BL_BIT);   // Turn off backlight
-        timer(Stop);
-    }
-}
-/*
-
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief Write a single character on the LCD
- *
- * Writes a single character on the LCD on the current cursor position
- *
- * \param LcdChar character to write
- */
-/* ����������������������������������������������������������������������� */
 void LcdChar(char MyChar)
 {
     LcdWriteByte(WRITE_DATA, MyChar);

+ 3 - 1
jsmn.c

@@ -1,4 +1,6 @@
 #include "jsmn.h"
+#include <stdio.h>
+#include <string.h>
 
 /**
  * Allocates a fresh unused token from the token pull.
@@ -334,4 +336,4 @@ int getIntegerToken(const char *json, jsmntok_t *tok){
  */
 void getStringToken(const char *json, jsmntok_t *tok, char *res){
 	sprintf(res, "%.*s", tok->end - tok->start, json + tok->start);
-}
+}

+ 0 - 13
keyboard.c

@@ -192,19 +192,6 @@ static u_char KbRemapKey(u_short LongKey)
     }
 }
 
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief Return the repeating property for this key
- *
- * \return 'TRUE' in case the key was repeating, 'FALSE' if not
- *
- */
-/* ����������������������������������������������������������������������� */
-static u_char KbKeyIsRepeating(u_short Key)
-{
-    return(KeyRepeatArray[KbRemapKey(Key)]==KEY_REPEAT);
-}
-
 /* ����������������������������������������������������������������������� */
 /*!
  * \brief set the property of this key to repeating or not-repeating

+ 1 - 1
keyboard.h

@@ -91,7 +91,7 @@
 /*-------------------------------------------------------------------------*/
 void    KbInit(void);
 void  KbScan(void);
-int 	CheckKey();
+int 	CheckKey(void);
 int     KbWaitForKeyEvent(u_long);
 u_char  KbGetKey(void);
 void    KbSetKeyRepeating(u_char, u_char);

+ 1 - 8
main.c

@@ -44,6 +44,7 @@
 #include "system.h"
 #include "typedefs.h"
 #include "uart0driver.h"
+#include "vs10xx.h"
 #include "watchdog.h"
 
 
@@ -82,15 +83,7 @@ static void SysControlMainBeat(u_char);
  */
 static void SysMainBeatInterrupt(void *p)
 {
-
-    /*
-     *  scan for valid keys
-     */
     KbScan();
-
-    if(KbGetKey() != KEY_NO_KEY){
-        LcdBackLight(LCD_BACKLIGHT_ON);
-    }
 }
 
 /*!

+ 5 - 2
network.c

@@ -7,6 +7,7 @@
 #include <sys/confnet.h>
 #include <sys/socket.h>
 #include <netinet/tcp.h>
+#include <sys/types.h>
 
 #include <stdlib.h>
 #include <string.h>
@@ -17,6 +18,8 @@
 
 #include <stdio.h>
 #include <io.h>
+#include <sys/version.h>
+#include <dev/irqreg.h>
 #include <arpa/inet.h>
 #include <pro/dhcp.h>
 #include <pro/sntp.h>
@@ -47,7 +50,7 @@ void NetworkInit() {
 }
 
 char* getMacAdress(){
-    ether_ntoa(confnet.cdn_mac);
+    return ether_ntoa(confnet.cdn_mac);
 }
 
 void httpGet(char address[], void (*parser)(char*)){
@@ -108,4 +111,4 @@ bool NetworkIsReceiving(void){
 
 bool hasNetworkConnection(void){
     return hasNetwork;
-}
+}

+ 4 - 4
network.h

@@ -4,11 +4,11 @@
 
 #ifndef _Network_H
 #define _Network_H
-
-//bool hasNetworkConnection(void);
-//bool NetworkIsReceiving(void);
+#include "typedefs.h"
+bool hasNetworkConnection(void);
+bool NetworkIsReceiving(void);
 extern void NetworkInit(void);
 extern void httpGet(char address[], void (*parser)(char*));
-char* getMacAdress();
+char* getMacAdress(void);
 
 #endif /* _Network_H */

+ 4 - 22
ntp.c

@@ -21,6 +21,8 @@
 #include "log.h"
 #include "ntp.h"
 #include "contentparser.h"
+#include "alarm.h"
+#include "network.h"
 
 int TIME_ZONE = 1;
 #define LOG_MODULE  LOG_NTP_MODULE
@@ -68,7 +70,7 @@ void NtpCheckValidTime(void){
     tm current_tm;
     X12RtcGetClock(&current_tm);
 
-    validTime = NtpCompareTime(current_tm, stored_tm);
+    validTime = compareTime(current_tm, stored_tm);
     if (validTime){
         puts("NtpCheckValidTime(): Time was valid \n");
     }else {
@@ -76,26 +78,6 @@ void NtpCheckValidTime(void){
     }
 }
 
-//Tests if t1 is after t2.
-bool NtpCompareTime(tm t1, tm t2){
-
-    if (t1.tm_year > t2.tm_year)
-        return true;
-    if (t1.tm_mon > t2.tm_mon)
-        return true;
-    if (t1.tm_mday > t2.tm_mday)
-        return true;
-    if (t1.tm_hour > t2.tm_hour)
-        return true;
-    if (t1.tm_min > t2.tm_min)
-        return true;
-    if (t1.tm_sec > t2.tm_sec)
-        return true;
-
-    //else
-    return false;
-}
-
 bool NtpTimeIsValid(void){
     return validTime;
 }
@@ -105,7 +87,7 @@ void NtpSync(void){
     isSyncing = true;
     httpGet("/gettimezone.php", parsetimezone);
     _daylight = 0;
-    printf(TIME_ZONE);
+    printf("Timezone is: %d", TIME_ZONE);
     NutDelay(100);
     //puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
     timeserver = inet_addr("213.154.229.24");

+ 3 - 3
ntp.h

@@ -6,6 +6,7 @@
 #define _Ntp_H
 
 #include "typedefs.h"
+#include <time.h>
 
 extern bool NtpIsSyncing(void);
 extern void NtpInit(void);
@@ -14,9 +15,8 @@ extern void setTimeZone(int timezone);
 extern bool NtpTimeIsValid(void);
 
 void NtpCheckValidTime(void);
-void NtpWriteTimeToEeprom(tm);
-bool NtpCompareTime(tm, tm);
+void NtpWriteTimeToEeprom(tm time_struct);
 
 void setTimeZone(int timezone);
-int getTimeZone();
+int getTimeZone(void);
 #endif /* _Ntp_H */

+ 0 - 3
uart0driver.c

@@ -106,9 +106,6 @@ THREAD(Uart0KeyEvents, arg)
         result = fgets(result, 16, stream);
         short _reset_received = strcmp(rst, result);
 
-        *rst = "abcde\n";
-        *result = "";
-
         if (_reset_received == 0){
             LogMsg_P(LOG_INFO, PSTR(">>>>>> RESET COMMAND RECEIVED"));
             //RESET SIR!

+ 0 - 8
vs10xx.c

@@ -91,7 +91,6 @@
 /*-------------------------------------------------------------------------*/
 static volatile u_char vs_status = VS_STATUS_STOPPED;
 static u_short g_vs_type;
-static u_char VsPlayMode;
 
 
 static void VsLoadProgramCode(void);
@@ -787,13 +786,6 @@ u_short VsMemoryTest(void)
 int VsSetVolume(u_char left, u_char right)
 {
     u_char ief;
-    if(left < 0){
-        left = 0;
-    }
-    if(right < 0){
-        right = 0;
-    }
-    printf("%d %d", left, right);
 
     ief = VsPlayerInterrupts(0);