]> git.kernelconcepts.de Git - oswald.git/commitdiff
Make accelerometer work, interrup driven tilt change mode
authorNils Faerber <nils.faerber@kernelconcepts.de>
Sun, 5 May 2013 21:22:33 +0000 (23:22 +0200)
committerNils Faerber <nils.faerber@kernelconcepts.de>
Sun, 5 May 2013 21:22:33 +0000 (23:22 +0200)
metawatch/mw_acc.c
metawatch/mw_acc.h
metawatch/mw_bt.c
metawatch/mw_main.c
metawatch/mw_main.h
metawatch/oswald_hal.c
ui/calendar.c
ui/oswald-ui.c
ui/oswald-ui.h
ui/oswald_hal.h
ui/oswald_screens.c

index 270f2467304894237492941ebf905ce38960adc7..9c4b0f56572efde16f7adc2bbc26d0cf78f0715f 100644 (file)
@@ -1,12 +1,87 @@
 #include <msp430.h>
 #include <msp430xgeneric.h>
 #include <stdint.h>
+#include <stdio.h>
 
 #include "mw_main.h"
+#include "mw_uart.h"
 
 #include "mw_acc.h"
 
-void mw_init_acc_i2c(void)
+#include "oswald_main.h"
+
+#define ACCEL_STATE_DISABLED           0x00
+#define ACCEL_STATE_ENABLED            0x01
+
+static uint8_t AccelState;
+static uint8_t AccelerometerBusy;
+static uint8_t LengthCount;
+static uint8_t Index;
+static uint8_t *pAccelerometerData;
+
+/*
+ * Accelerometer is a Kionix KXTF9-4100 connected to I2C
+ * I2C is pretty slow so reading and writing should be done non blocking
+ * using interrupts.
+ */
+
+#define ACCELEROMETER_NO_INTERRUPTS    0x00
+#define ACCELEROMETER_ALIFG            0x02
+#define ACCELEROMETER_NACKIFG          0x04
+#define ACCELEROMETER_STTIFG           0x06
+#define ACCELEROMETER_STPIFG           0x08
+#define ACCELEROMETER_RXIFG            0x0a
+#define ACCELEROMETER_TXIFG            0x0c
+
+#pragma vector=USCI_B1_VECTOR
+__interrupt void ACCERLEROMETER_I2C_ISR(void)
+{
+       // debug_uart_tx("ACC i2c irq\n");
+       switch (USCI_ACCELEROMETER_IV) {
+               case ACCELEROMETER_NO_INTERRUPTS: 
+                       break;
+               case ACCELEROMETER_ALIFG: 
+                       break;
+               case ACCELEROMETER_NACKIFG:
+                       nop();
+                       break; 
+               case ACCELEROMETER_STTIFG:
+                       nop();
+                       break; 
+               case ACCELEROMETER_STPIFG: 
+                       break;
+               case ACCELEROMETER_RXIFG:
+                       if (LengthCount > 0) {
+                               pAccelerometerData[Index++] = ACCELEROMETER_RXBUF;
+                               LengthCount--;
+                               if ( LengthCount == 1 ) {
+                                       /* All but one byte received. Send stop */
+                                       ACCELEROMETER_CTL1 |= UCTXSTP;
+                               } else if ( LengthCount == 0 ) {
+                                       /* Last byte received; disable rx interrupt */
+                                       ACCELEROMETER_IE &= ~UCRXIE;
+                                       AccelerometerBusy = 0;
+                               }
+                       }
+                       break;
+               case ACCELEROMETER_TXIFG:
+                       if ( LengthCount > 0 ) {
+                               ACCELEROMETER_TXBUF = pAccelerometerData[Index++];
+                               LengthCount--;
+                       } else {
+                               /* disable transmit interrupt and send stop */
+                               ACCELEROMETER_IE &= ~UCTXIE;
+                               ACCELEROMETER_CTL1 |= UCTXSTP;
+                               AccelerometerBusy = 0;
+                       }
+                       break;
+               default:
+                       break;
+       }
+
+}
+
+void mw_acc_init_i2c(void)
 {
        /* enable reset before configuration */
        ACCELEROMETER_CTL1 |= UCSWRST;
@@ -23,49 +98,307 @@ void mw_init_acc_i2c(void)
        ACCELEROMETER_CTL1 &= ~UCSWRST;
 }
 
-/*
- * DMA2 = SPI for LCD
- */
-static void mw_acc_i2c_write_byte(uint8_t byte)
+void mw_acc_disable_i2c(void)
 {
-       ACCELEROMETER_TXBUF = byte;
-       while ((ACCELEROMETER_CTL1 & ACCELEROMETER_IFG) == 0)
-               nop();
+       /* enable reset to hold it */
+       ACCELEROMETER_CTL1 |= UCSWRST;
 }
 
-/* OK this is polling write, but data is small and 400kHz I2C, it should "just work" :) */
-void mw_acc_i2c_write(const uint8_t addr, const void *data, const uint8_t len)
+void mw_acc_i2c_write(uint8_t RegisterAddress, uint8_t *pData, uint8_t Length)
 {
-       int i;
-
-       if (len == 0) {
+       if (Length == 0 || pData == 0)
                return;  
-       }
   
        while (UCB1STAT & UCBBUSY)
                nop();
   
+       AccelerometerBusy = 1;
+       LengthCount = Length;
+       Index = 0;
+       pAccelerometerData = pData;
+  
        /* 
+        * enable transmit interrupt and 
         * setup for write and send the start condition
         */
        ACCELEROMETER_IFG = 0;
        ACCELEROMETER_CTL1 |= UCTR + UCTXSTT;
-       while (!(ACCELEROMETER_IFG & UCTXIFG))
+       while(!(ACCELEROMETER_IFG & UCTXIFG))
                nop();
   
        /* 
-        * clear transmit interrupt flag,
+        * clear transmit interrupt flag, enable interrupt, 
         * send the register address
         */
        ACCELEROMETER_IFG = 0;
+       ACCELEROMETER_IE |= UCTXIE;
+       ACCELEROMETER_TXBUF = RegisterAddress;
 
-       mw_acc_i2c_write_byte(addr);
+       while (AccelerometerBusy)
+               nop();
+
+       while (ACCELEROMETER_CTL1 & UCTXSTP)
+               nop();
 
-       for (i=0; i<len; i++)
-               mw_acc_i2c_write_byte(*(uint8_t *)(data+i));
+       /* the rest of TX will be handled by the ISR */
+}
 
+void mw_acc_i2c_read_single(const uint8_t RegisterAddress, const uint8_t *pData)
+{
+       if ( pData == 0 )
+               return;
+  
+       /* wait for bus to be free */
+       while (UCB1STAT & UCBBUSY)
+               nop();
+  
+       AccelerometerBusy = 1;
+       LengthCount = 1;
+       Index = 0;
+       pAccelerometerData = (uint8_t *)pData;
+
+       /* transmit address */
+       ACCELEROMETER_IFG = 0;
+       ACCELEROMETER_CTL1 |= UCTR + UCTXSTT;
+       while (!(ACCELEROMETER_IFG & UCTXIFG))
+               nop();
+  
+       /* write register address */
+       ACCELEROMETER_IFG = 0;
+       ACCELEROMETER_TXBUF = RegisterAddress;
+       while (!(ACCELEROMETER_IFG & UCTXIFG))
+               nop();
+
+       /* send a repeated start (same slave address now it is a read command) 
+        * read possible extra character from rxbuffer
+        */
+       ACCELEROMETER_RXBUF;
+       ACCELEROMETER_IFG = 0;
+       ACCELEROMETER_IE |= UCRXIE;
+       ACCELEROMETER_CTL1 &= ~UCTR;
+       /* for a read of a single byte the stop must be sent while the byte is being 
+        * received. If this is interrupted an extra byte may be read.
+        * however, it will be discarded during the next read
+        */
+       if ( LengthCount == 1 ) {
+               /* errata usci30: prevent interruption of sending stop 
+                * so that only one byte is read
+                * this requires 62 us @ 320 kHz, 51 @ 400 kHz
+                */
+               ACCELEROMETER_CTL1 |= UCTXSTT;
+  
+               while(ACCELEROMETER_CTL1 & UCTXSTT)
+                       nop();
+
+               ACCELEROMETER_CTL1 |= UCTXSTP;
+       } else {
+               ACCELEROMETER_CTL1 |= UCTXSTT;
+       }
+  
+       /* wait until all data has been received and the stop bit has been sent */
+       while (AccelerometerBusy)
+               nop();
        while (ACCELEROMETER_CTL1 & UCTXSTP)
                nop();
+       Index = 0;
+       pAccelerometerData = 0;
 }
 
+/* errata usci30: only perform single reads 
+ * second solution: use DMA
+ */
+void mw_acc_i2c_read(const uint8_t RegisterAddress, uint8_t *pData, const uint8_t Length)
+{
+       int i;
+
+       for ( i = 0; i < Length; i++ ) {
+               mw_acc_i2c_read_single(RegisterAddress + i, (pData + i));
+       }
+}
+
+
+void mw_acc_init(void)
+{
+       uint8_t WriteRegisterData;
+       uint8_t pReadRegisterData[4];
+#if defined MW_DEVBOARD_V2
+       char tstr[16];
+#endif
+
+       ENABLE_ACCELEROMETER_POWER();
+
+       mw_acc_init_i2c();
+
+       /*
+        * make sure part is in standby mode because some registers can only
+        * be changed when the part is not active.
+        */
+       WriteRegisterData = PC1_STANDBY_MODE;
+       mw_acc_i2c_write(KIONIX_CTRL_REG1, &WriteRegisterData, 1);
+
+       /* enable face-up and face-down detection */
+       WriteRegisterData = TILT_FDM | TILT_FUM;
+       mw_acc_i2c_write(KIONIX_CTRL_REG2, &WriteRegisterData, 1);
+    
+       /* 
+        * the interrupt from the accelerometer can be used to get periodic data
+        * the real time clock can also be used
+        */
+  
+       /* change to output data rate to 25 Hz */
+       WriteRegisterData = WUF_ODR_25HZ | TAP_ODR_400HZ;
+       mw_acc_i2c_write(KIONIX_CTRL_REG3, &WriteRegisterData, 1);
+  
+       /* enable interrupt and make it active high */
+       WriteRegisterData = IEN | IEA;
+       mw_acc_i2c_write(KIONIX_INT_CTRL_REG1, &WriteRegisterData, 1);
+  
+       /* enable motion detection interrupt for all three axis */
+       WriteRegisterData = XBW | YBW | ZBW;
+       mw_acc_i2c_write(KIONIX_INT_CTRL_REG2, &WriteRegisterData, 1);
+
+       /* enable tap interrupt for Z-axis */
+       WriteRegisterData = TFDM;
+       mw_acc_i2c_write(KIONIX_INT_CTRL_REG3, &WriteRegisterData, 1);
+  
+       /* set TDT_TIMER to 0.2 secs*/
+       WriteRegisterData = 0x50;
+       mw_acc_i2c_write(KIONIX_TDT_TIMER, &WriteRegisterData, 1);
+  
+       /* set tap low and high thresholds (default: 26 and 182) */
+       WriteRegisterData = 40; //78;
+       mw_acc_i2c_write(KIONIX_TDT_L_THRESH, &WriteRegisterData, 1);
+       WriteRegisterData = 128;
+       mw_acc_i2c_write(KIONIX_TDT_H_THRESH, &WriteRegisterData, 1);
+    
+       /* set WUF_TIMER counter */
+       WriteRegisterData = 10;
+       mw_acc_i2c_write(KIONIX_WUF_TIMER, &WriteRegisterData, 1);
+    
+       /* this causes data to always be sent */
+       // WriteRegisterData = 0x00;
+       WriteRegisterData = 0x02 /*0x08*/;
+       mw_acc_i2c_write(KIONIX_WUF_THRESH, &WriteRegisterData, 1);
+     
+       /* single byte read test */
+       mw_acc_i2c_read(KIONIX_DCST_RESP, pReadRegisterData, 1);
+#if defined MW_DEVBOARD_V2
+       snprintf(tstr, 16, "acc DCST 0x%02x\n", pReadRegisterData[0]);
+       debug_uart_tx(tstr);
+#endif
+  
+       /* multiple byte read test */
+       mw_acc_i2c_read(KIONIX_WHO_AM_I, pReadRegisterData, 2);
+#if defined MW_DEVBOARD_V2
+       snprintf(tstr, 16, "acc is 0x%02x 0x%02x\n", pReadRegisterData[0], pReadRegisterData[1]);
+       debug_uart_tx(tstr);
+#endif
+
+       /* 
+        * KIONIX_CTRL_REG3 and DATA_CTRL_REG can remain at their default values 
+        *
+        * 50 Hz
+        */
+#if 0  
+       /* KTXF9 300 uA; KTXI9 165 uA */
+       WriteRegisterData = PC1_OPERATING_MODE | TAP_ENABLE_TDTE;
+  
+       /* 180 uA; KTXI9 115 uA */
+       WriteRegisterData = PC1_OPERATING_MODE | RESOLUTION_8BIT | WUF_ENABLE;
+
+       /* 180 uA; KTXI9 8.7 uA */
+       WriteRegisterData = PC1_OPERATING_MODE | TILT_ENABLE_TPE;
+
+       /* 720 uA; KTXI9 330 uA */  
+       WriteRegisterData = PC1_OPERATING_MODE | RESOLUTION_12BIT | WUF_ENABLE;
+#endif
+  
+       /* setup the default for the AccelerometerEnable command */
+#if 0
+       OperatingModeRegister = PC1_OPERATING_MODE | RESOLUTION_12BIT | TAP_ENABLE_TDTE | TILT_ENABLE_TPE; // | WUF_ENABLE;
+       InterruptControl = INTERRUPT_CONTROL_DISABLE_INTERRUPT;
+       SidControl = SID_CONTROL_SEND_DATA;
+       SidAddr = KIONIX_XOUT_L;
+       SidLength = XYZ_DATA_LENGTH;  
+
+       AccelState = ACCEL_STATE_INIT;
+#endif
+}
+
+void mw_acc_enable(void)
+{
+       uint8_t sdata;
+
+       mw_acc_init();
+
+       sdata = PC1_OPERATING_MODE | RESOLUTION_12BIT | TAP_ENABLE_TDTE | TILT_ENABLE_TPE | WUF_ENABLE;
+       //sdata = PC1_OPERATING_MODE | RESOLUTION_8BIT | TAP_ENABLE_TDTE | TILT_ENABLE_TPE; // | WUF_ENABLE;
+       mw_acc_i2c_write(KIONIX_CTRL_REG1, &sdata, 1);
+  
+       ACCELEROMETER_INT_ENABLE();
+       mw_acc_i2c_read(KIONIX_INT_REL, &sdata, 1);
+       AccelState = ACCEL_STATE_ENABLED;
+}
+
+void mw_acc_disable(void)
+{
+       uint8_t sdata;
+
+       if (AccelState == ACCEL_STATE_ENABLED) {
+               sdata = PC1_STANDBY_MODE;
+               mw_acc_i2c_write(KIONIX_CTRL_REG1, &sdata, 1);
+
+               ACCELEROMETER_INT_DISABLE();
+               mw_acc_disable_i2c();
+               DISABLE_ACCELEROMETER_POWER();
+               AccelState = ACCEL_STATE_DISABLED;
+       }
+}
+
+void mw_acc_read(int16_t *x, int16_t *y, int16_t *z)
+{
+       uint8_t rdata[6];
+
+       if (AccelState == ACCEL_STATE_ENABLED) {
+               mw_acc_i2c_read(KIONIX_XOUT_L, rdata, 6);
+
+               *x = rdata[0] | (rdata[1] << 8);
+               *y = rdata[2] | (rdata[3] << 8);
+               *z = rdata[4] | (rdata[5] << 8);
+       } else {
+               *x = 0;
+               *y = 0;
+               *z = 0;
+       }
+}
+
+void mw_acc_handle_irq(void)
+{
+       uint8_t sdata, srcreg1, srcreg2;
+#if defined MW_DEVBOARD_V2
+       char tstr[16];
+#endif
+
+       mw_acc_i2c_read(KIONIX_INT_SRC_REG1, &srcreg1, 1);
+#if defined MW_DEVBOARD_V2
+       snprintf(tstr, 16, "accsrc1: 0x%02x\n", srcreg1);
+       debug_uart_tx(tstr);
+#endif
+       mw_acc_i2c_read(KIONIX_INT_SRC_REG2, &srcreg2, 1);
+#if defined MW_DEVBOARD_V2
+       snprintf(tstr, 16, "accsrc2: 0x%02x\n", srcreg2);
+       debug_uart_tx(tstr);
+#endif
+       if (srcreg1 & INT_TAP_SINGLE) {
+       };
+       if (srcreg1 & INT_TAP_DOUBLE) {
+       };
+       if (srcreg2 & INT_WUFS) {
+               int16_t x, y, z;
+               mw_acc_read(&x, &y, &z);
+               oswald_handle_accel_event((int8_t)(x / (32768 / 255)), (int8_t)(y / (32768 / 255)), (int8_t)(z / (32768 / 255)));
+       }
+
+       mw_acc_i2c_read(KIONIX_INT_REL, &sdata, 1);
+}
 
index 59cee9337364fd100ea464de316fd8a475e0c577..2acf7c7b9e7b2498b2d08c3cf3d3f99e5709b062 100644 (file)
 #define TFUM (1 << 0)
 
 /* INT_SRC_REG2 */
-#define INT_TAP_SINGLE (0x04)
-#define INT_TAP_DOUBLE (0x08)
+#define INT_TPS                0x01
+#define INT_WUFS       0x02
+#define INT_TAP_SINGLE 0x04
+#define INT_TAP_DOUBLE 0x08
+#define INT_DRDY       0x10
 
-/* for readability */
-#define ONE_BYTE ( 1 )
 
-#endif
+void mw_acc_init_i2c(void);
+void mw_acc_disable_i2c(void);
+void mw_acc_i2c_read(const uint8_t RegisterAddress, uint8_t *pData, const uint8_t Length);
+void mw_acc_i2c_write(uint8_t RegisterAddress, uint8_t *pData, uint8_t Length);
+
+void mw_acc_init(void);
+void mw_acc_enable(void);
+void mw_acc_disable(void);
+void mw_acc_read(int16_t *x, int16_t *y, int16_t *z);
+void mw_acc_handle_irq(void);
 
+#endif
index 7cb24e1b0e63fad8978a87bd30243b050eb4c05f..8138b1ef4414e7d77d13707a22b751c0e7098259 100644 (file)
@@ -188,17 +188,6 @@ void mw_enable_bt(void)
        mw_bt_enabled = 1;
 }
 
-#pragma vector=PORT1_VECTOR
-__interrupt void BT_CTS_ISR (void)
-{
-       P1IFG &= ~BT_IO_CTS;
-
-       debug_uart_tx("BTS CTS triggered\n");
-       bt_hci_ehcill_wake();
-
-       LPM3_EXIT;
-}
-
 void mw_disable_bt(void)
 {
        mw_bt_enabled = 0;
index 89b014ebe748be909e475509957392796cf23304..4f8ee90b01e77ea6930ad91601becdbbdabee447 100644 (file)
@@ -10,6 +10,7 @@
 #include "mw_bt.h"
 #include "mw_adc.h"
 #include "mw_bt.h"
+#include "mw_acc.h"
 #include "bt_hci.h"
 #include "bt_l2cap.h"
 
@@ -18,7 +19,7 @@
 
 #include "bluetooth_init_cc256x.h"
 
-unsigned int _event_src = 0;
+uint16_t _event_src = 0;
 
 
 static void set16mhz(void)
@@ -111,7 +112,7 @@ static void setup_pins(void)
        DISABLE_LCD_LED();              // frontlight
        CONFIG_DEBUG_PINS();
        CONFIG_ACCELEROMETER_PINS();
-       // DISABLE_ACCELEROMETER_POWER(); // there is no accel. power switching!
+       DISABLE_ACCELEROMETER_POWER(); // starts from config 5 and later
 
        HARDWARE_CFG_SENSE_INIT();
 
@@ -324,7 +325,19 @@ static void handle_uart_rx_event(void)
 
        if (debug_uart_rx_char(&c)) {
                debug_uart_tx_char(c);
-               if (c == 'b') {
+               if (c == 'a') {
+                       debug_uart_tx("\nenabling ACC\n");
+                       mw_acc_enable();
+               } else if (c == 'A') {
+                       debug_uart_tx("\ndisabling ACC\n");
+                       mw_acc_disable();
+               } else if (c == 'r') {
+                       int16_t x,y,z;
+                       debug_uart_tx("\nread ACC: ");
+                       mw_acc_read(&x, &y, &z);
+                       snprintf(tstr, 64, "x:%d y:%d z:%d\n", x,y,z);
+                       debug_uart_tx(tstr);
+               } else if (c == 'b') {
                        debug_uart_tx("\nenabling BT\n");
                        mw_enable_bt();
                } else if (c == 'B') {
@@ -484,6 +497,9 @@ uint8_t handle_event(void)
                } else if (_event_src & TIMER_100MS_EVENT) {
                        _event_src &= ~TIMER_100MS_EVENT;
                        oswald_centisecond_tick();
+               } else if (_event_src & ACCEL_EVENT) {
+                       _event_src &= ~ACCEL_EVENT;
+                       mw_acc_handle_irq();
                } else {
 #if defined MW_DEVBOARD_V2
                        snprintf(tstr, 64, "unhandled event in 0x%04x\n", _event_src);
@@ -504,6 +520,26 @@ __interrupt void BUTTON_ISR (void)
        LPM3_EXIT;
 }
 
+#pragma vector=PORT1_VECTOR
+__interrupt void PORT1_GPIO_ISR (void)
+{
+       if (P1IFG & BT_IO_CTS) {
+               P1IFG &= ~BT_IO_CTS;
+
+               debug_uart_tx("BT CTS irq\n");
+               bt_hci_ehcill_wake();
+
+               LPM3_EXIT;
+       };
+       if (P1IFG & ACCELEROMETER_INT_PIN) {
+               P1IFG &= ~ACCELEROMETER_INT_PIN;
+               // debug_uart_tx("ACC irq\n");
+               _event_src |= ACCEL_EVENT;
+               LPM3_EXIT;
+       }
+}
+
+
 #if 0
 #pragma vector=NOVECTOR
 __interrupt void UNEXP_ISR (void)
index 23dcf5efa49f11341199ff2853cf28b039815968..039d40202a2aa46b52010f2ef1719fbaedebccb3 100644 (file)
@@ -21,6 +21,7 @@
 #define TIMER_100MS_EVENT      1 << 5
 #define POWER_SRC_EVENT                1 << 6
 #define BT_UART_RCV_EVENT      1 << 7
+#define ACCEL_EVENT            1 << 8
 
 extern unsigned int _event_src;
 
index 449355dabddc3b7129edecefb6f38d82b0b71f00..528f1a6d230b5a1e655dc33ab494c09fed92d498 100644 (file)
@@ -14,6 +14,7 @@
 #include "bt_hci.h"
 #include "bt_l2cap.h"
 #include "bluetooth_init_cc256x.h"
+#include "mw_acc.h"
 
 #include "oswald.h"
 #include "oswald_hal.h"
@@ -249,3 +250,17 @@ void hal_bluetooth_send_data(const void *mdat, uint16_t mlen)
        bt_l2cap_send_channel(0x40, mdat, mlen);
 }
 
+/*
+ * Control the accelerometer
+ */
+void hal_accelerometer_enable(void)
+{
+       mw_acc_enable();
+}
+
+void hal_accelerometer_disable(void)
+{
+       mw_acc_disable();
+}
+
+
index 6271e12a43b7edb9ae51561d46cfd02942019e8e..feca174572d13ec97236beb9d3440beba4003bf4 100644 (file)
@@ -4,9 +4,10 @@
 
 unsigned char is_leap(const unsigned int year)
 {
-  // Die Regel lautet: Alles, was durch 4 teilbar ist, ist ein Schaltjahr.
-  // Es sei denn, das Jahr ist durch 100 teilbar, dann ist es keins.
-  // Aber wenn es durch 400 teilbar ist, ist es doch wieder eins.
+       /* the rule is, everything that can be devided by 4 is leap.
+        * Exception: the year can be devided by 100, then it is not,
+        * except it canbe devided by 400, then it is again.
+        */
 
        if ((year % 400) == 0)
                return 1;
@@ -20,11 +21,11 @@ unsigned char is_leap(const unsigned int year)
 
 unsigned short days_of_month(const unsigned int uMonat, const unsigned int uJahr)
 {
-       //                     ungült,Jan,Feb,Mrz,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez
+       // invalid,January,Febuary,March,April,May,June,July,August,September,October,November,December
        int arrTageImMonat[13] = {  0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 
        if (uMonat == 2) {
-               // Februar: Schaltjahr unterscheiden
+               // Febuary: distinguish leap
                if (is_leap(uJahr))
                        return 29;
                else
index c482c7834569b230839ee99ec181f062625ebc37..29e15fd461cc2c7432f973a691aa445a5dca86ef 100644 (file)
@@ -109,6 +109,22 @@ const char *hal_get_radio_version_string(void)
        return "BlueZ";
 }
 
+void hal_accelerometer_enable(void)
+{
+       g_printerr("accel enable\n");
+       gtk_widget_set_sensitive(ui_g->x_sc, TRUE);
+       gtk_widget_set_sensitive(ui_g->y_sc, TRUE);
+       gtk_widget_set_sensitive(ui_g->z_sc, TRUE);
+}
+
+void hal_accelerometer_disable(void)
+{
+       g_printerr("accel enable\n");
+       gtk_widget_set_sensitive(ui_g->x_sc, FALSE);
+       gtk_widget_set_sensitive(ui_g->y_sc, FALSE);
+       gtk_widget_set_sensitive(ui_g->z_sc, FALSE);
+}
+
 
 static gint
 configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer user_data)
@@ -330,18 +346,24 @@ static void create_mainwin(oswald_ui *ui)
        sc = gtk_hscale_new_with_range (-128, 127, 1);
        gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
        g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelX_value_changed), ui);
+       ui->x_sc = sc;
+       gtk_widget_set_sensitive(ui->x_sc, FALSE);
 
        l = gtk_label_new("Y:");
        gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
        sc = gtk_hscale_new_with_range (-128, 127, 1);
        gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
        g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelY_value_changed), ui);
+       ui->y_sc = sc;
+       gtk_widget_set_sensitive(ui->y_sc, FALSE);
 
        l = gtk_label_new("Z:");
        gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5);
        sc = gtk_hscale_new_with_range (-128, 127, 1);
        gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5);
        g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelZ_value_changed), ui);
+       ui->z_sc = sc;
+       gtk_widget_set_sensitive(ui->z_sc, FALSE);
 
        gtk_widget_show_all(ui->mainwin);
 }
index 0872a94dd0cb6bcda6810853694d7ca9753a515a..fdadd4b1ef3b538215e0bdc17091b83f7078ac7c 100644 (file)
@@ -9,6 +9,9 @@ typedef struct {
        GtkWidget *mainwin;
        GtkWidget *darea;
        GdkPixmap *pixmap;
+       GtkWidget *x_sc;
+       GtkWidget *y_sc;
+       GtkWidget *z_sc;
        uint8_t accel_x;
        uint8_t accel_y;
        uint8_t accel_z;
index ad877d048f9e39d6f40f5ecb62d71b251cb042c3..bc7a715f4f8f007aa5a15598de0cf24cae72d500 100644 (file)
@@ -36,5 +36,9 @@ uint8_t *hal_bluetooth_get_local_bdaddr(void);
 void hal_bluetooth_set_visible(boolean visible);
 boolean hal_bluetooth_get_visible(void);
 void hal_bluetooth_send_data(const void *mdat, uint16_t mlen);
+
+void hal_accelerometer_enable(void);
+void hal_accelerometer_disable(void);
+
 #endif
 
index 9952365145772194891e3f1d4145d5b8f88e8924..c079e44fed344702d90b57093fbd436ad5106708 100644 (file)
@@ -143,6 +143,8 @@ static accelscreen_data_t accel_screen = {
 
 void draw_accel_screen(accel_data_t *accel_data)
 {
+       uint8_t x,y;
+
        hal_lcd_clear_display();
 
        oswald_draw_bitmap(36, 0, acc_icon_width, acc_icon_height, acc_icon_bits);
@@ -162,7 +164,13 @@ void draw_accel_screen(accel_data_t *accel_data)
        oswald_draw_line(40, 82, 92, 82);
        oswald_draw_line(40, 82, 40, 30);
 
-       oswald_draw_pixel(41+25+((accel_data->x * 50) / (254)), 31+25+((accel_data->y * 50) / (254)));
+       x = 41+25+((accel_data->x * 50) / (254));
+       y = 31+25+((accel_data->y * 50) / (254));
+       oswald_draw_pixel(x, y);
+       oswald_draw_pixel(x+1, y);
+       oswald_draw_pixel(x-1, y);
+       oswald_draw_pixel(x, y+1);
+       oswald_draw_pixel(x, y-1);
 
        hal_lcd_update_display();
 }
@@ -172,6 +180,11 @@ event_ret_t accel_handle_events(uint16_t event, void *data)
        switch (event) {
                case EVENT_SCREEN_VISIBLE:
                        draw_accel_screen(&accel_screen.accdata);
+                       hal_accelerometer_enable();
+                       return EVENT_RET_HANDLED;
+                       break;
+               case EVENT_SCREEN_DESTROY:
+                       hal_accelerometer_disable();
                        return EVENT_RET_HANDLED;
                        break;
                case EVENT_ACCEL_UPDATE: {