Tamago.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: Beerware
2 /**
3  * @file Tamago.c
4  * @brief Tamago main application handler
5  * @author Michael Fitzmayer
6  * @copyright "THE BEER-WARE LICENCE" (Revision 42)
7  * @page Schematics Schematics
8  * @section SchSTM STM32F103C8xx
9  * @code{.unparsed}
10  *
11  * Todo.
12  *
13  * @endcode
14  * @section SchDMD Dot Matrix Display
15  * @code{.unparsed}
16  *
17  * RGB variant:
18  *
19  * Todo.
20  *
21  * Monochrome variant:
22  *
23  * +-----+
24  * | | OE ---> PA2
25  * OE | . . | A A ---> PA1
26  * GND | . . | B B ---> PA0
27  * GND | . . | NC CLK ---> PA5 (SPI1_SCK)
28  * GND . . | CLK SCLK ---> PA3
29  * GND . . | SCLK R/[G]/[B] ---> PA8 (SPI1_MOSI)
30  * GND | . . | R
31  * GND | . . | [G]
32  * GND | . . | [B]
33  * | |
34  * +-----+
35  *
36  * @endcode
37  */
38 
39 #include "Animation.h"
40 #include "BMP180.h"
41 #include "Clock.h"
42 #include "DMD.h"
43 #include "FreeRTOS.h"
44 #include "LifeCycle.h"
45 #include "M24FC256.h"
46 #include "Tamago.h"
47 #include "cmsis_os.h"
48 #include "task.h"
49 
50 static TaskHandle_t _hUpdateThread; ///< Update thread handle
51 
52 static void _SetAnimationByStats(Stats* pstStats);
53 static void _UpdateThread(void* pArg);
54 
55 /**
56  * @brief Initialise Tamago main application handler
57  * @return Error code
58  * @retval 0: OK
59  * @retval -1: Error
60  */
61 int Tamago_Init(void)
62 {
63  int nError = 0;
64  BaseType_t nStatus = pdPASS;
65 
66  #ifdef USE_BMP180
67  nError = BMP180_Init();
68  if (0 != nError)
69  {
70  return -1;
71  }
72  #endif
73 
76 
77  nStatus = xTaskCreate(
79  "Update",
80  configMINIMAL_STACK_SIZE,
81  NULL,
82  osPriorityNormal,
84 
85  if (pdPASS == nStatus)
86  {
87  osKernelStart();
88  }
89  else
90  {
91  return -1;
92  }
93 
94  return 0;
95 }
96 
97 /**
98  * @brief Update thread
99  * @param pArg: Unused
100  */
101 static void _UpdateThread(void* pArg)
102 {
103  Stats* pstStats = LifeCycle_GetStats();
104  uint16_t u16Cnt = 0;
105 
107  //DMD_SetBuffer(Animation_GetBufferAddr());
108 
109  while (1)
110  {
111  _SetAnimationByStats(pstStats);
112 
113  if (500 <= u16Cnt)
114  {
115  // These operations are executed approx. every 500ms
116  #ifdef USE_BMP180
117  int8_t s8Temp = 0;
118  BMP180_ReadTemperature(&s8Temp);
119  Clock_SetTemperature(s8Temp);
120  #endif
121 
123  u16Cnt = 0;
124  }
125 
126  Clock_Update();
127  DMD_Update();
128 
129  osDelay(1);
130  u16Cnt++;
131  }
132 }
133 
134 /**
135  * @brief Set animation by pet statistics
136  * @param pstStats
137  * Pointer to pet statistics
138  */
139 static void _SetAnimationByStats(Stats* pstStats)
140 {
141  switch (pstStats->eEvolution)
142  {
143  case EGG:
145  break;
146  case BABYTCHI:
148  break;
149  case MARUTCHI:
151  break;
152  case TAMATCHI:
154  break;
155  case KUCHITAMATCHI:
157  break;
158  case MAMETCHI:
160  break;
161  case GINJIROTCHI:
163  break;
164  case MASKUTCHI:
166  break;
167  case KUCHIPATCHI:
169  break;
170  case NYOROTCHI:
172  break;
173  case TARAKOTCHI:
175  break;
176  case OYAJITCHI:
178  break;
179  case OBAKETCHI:
181  break;
182  }
183 
184  if (LifeCycle_IsFlagSet(HAS_POOPED))
185  {
187  }
188  else
189  {
191  }
192 
193  if (LifeCycle_IsFlagSet(IS_SICK))
194  {
196  }
197  else
198  {
200  }
201 
202  if (LifeCycle_IsFlagSet(IS_SLEEPING))
203  {
205  }
206  else
207  {
209  }
210 }
void DMD_SetBuffer(uint8_t *pu8Buffer)
Set DMD image buffer.
Definition: DMD.c:91
uint8_t * Clock_GetBufferAddr(void)
Get address of image buffer.
Definition: Clock.c:59
Digital pressure sensor driver.
@ IDLE_GINJIROTCHI
ID, Ginjirotchi idle animation.
Definition: Animation.h:27
void Animation_Update(void)
Update animation buffer.
Definition: Animation.c:3076
@ IDLE_OBAKETCHI
ID, Obaketchi idle animation.
Definition: Animation.h:33
@ BABYTCHI
Baby, from Egg.
Definition: LifeCycle.h:17
@ IDLE_MARUTCHI
ID, Marutchi idle animation.
Definition: Animation.h:23
Tamago life cycle handler.
@ KUCHITAMATCHI
Teen, bad care from Marutchi.
Definition: LifeCycle.h:20
@ IDLE_KUCHITAMATCHI
ID, Kuchitamatchi idle animation.
Definition: Animation.h:25
@ ICON_SLEEP
ID, Sleep icon.
Definition: Animation.h:46
int BMP180_ReadTemperature(int8_t *ps8Temp)
Read current temperature.
Definition: BMP180.c:132
@ MARUTCHI
Child, from Babytchi.
Definition: LifeCycle.h:18
@ NYOROTCHI
Adult, bad care from Tamatchi, average care from Kuchitamatchi.
Definition: LifeCycle.h:25
static TaskHandle_t _hUpdateThread
Update thread handle.
Definition: Tamago.c:50
@ TAMATCHI
Teen, good care from Marutchi.
Definition: LifeCycle.h:19
bool LifeCycle_IsFlagSet(StatusFlag eFlag)
Check if status flag is set.
Definition: LifeCycle.c:55
Clock handler.
@ ICON_SKULL
ID, Skull icon.
Definition: Animation.h:45
@ OBAKETCHI
Dead.
Definition: LifeCycle.h:28
@ IDLE_EGG
ID, Egg idle animation.
Definition: Animation.h:20
Stats * LifeCycle_GetStats(void)
Get pet statistics.
Definition: LifeCycle.c:42
24FC256 driver
@ IDLE_MAMETCHI
ID, Mametchi idle animation.
Definition: Animation.h:26
@ TARAKOTCHI
Adult, Horrible care from both.
Definition: LifeCycle.h:26
@ GINJIROTCHI
Adult, above average care from Tamatchi.
Definition: LifeCycle.h:22
@ EGG
Egg.
Definition: LifeCycle.h:16
Pet statistics.
Definition: LifeCycle.h:48
@ IDLE_TARAKOTCHI
ID, Tarakotchi idle animation.
Definition: Animation.h:31
void Animation_Set(AnimID eID)
Set current animation.
Definition: Animation.c:3068
void Clock_SetTemperature(int8_t s8Temp)
Set temperature.
Definition: Clock.c:162
void LifeCycle_Init(void)
Initialise life cycle.
Definition: LifeCycle.c:33
@ MASKUTCHI
Adult, average care from Tamatchi.
Definition: LifeCycle.h:23
Tamago animation handler.
static void _UpdateThread(void *pArg)
Update thread.
Definition: Tamago.c:101
Tamago main application handler.
@ MAMETCHI
Adult, perfect care from Tamatchi.
Definition: LifeCycle.h:21
void Clock_Update(void)
Update clock-face buffer.
Definition: Clock.c:67
void DMD_Update(void)
Update dot matrix display.
Definition: DMD.c:100
@ IDLE_MASKUTCHI
ID, Maskutchi idle animation.
Definition: Animation.h:28
@ IDLE_BABYTCHI
ID, Babytchi idle animation.
Definition: Animation.h:22
@ IDLE_KUCHIPATCHI
ID, Kuchipatchi idle animation.
Definition: Animation.h:29
Dot Matrix Display driver.
@ IDLE_TAMATCHI
ID, Tamatchi idle animation.
Definition: Animation.h:24
@ KUCHIPATCHI
Adult, below average care from Tamatchi, perfect care from Kuchitamatchi.
Definition: LifeCycle.h:24
int Tamago_Init(void)
Initialise Tamago main application handler.
Definition: Tamago.c:61
Evolution eEvolution
Current evolution.
Definition: LifeCycle.h:52
void Animation_ShowIcon(IconID eID, bool bShow)
Show (or hide) icon.
Definition: Animation.c:3048
static void _SetAnimationByStats(Stats *pstStats)
Set animation by pet statistics.
Definition: Tamago.c:139
@ IDLE_OYAJITCHI
ID, Oyajotchi idle animation.
Definition: Animation.h:32
int BMP180_Init(void)
Initialise BMP180 driver.
Definition: BMP180.c:90
@ OYAJITCHI
Special, no discipline until it evolves to Maskutchi, perfect care from Maskutchi.
Definition: LifeCycle.h:27
@ IDLE_NYOROTCHI
ID, Nyorotchi idle animation.
Definition: Animation.h:30
void Animation_Init(void)
Initialise animation handler.
Definition: Animation.c:2988
@ ICON_POO
ID, Poo icon.
Definition: Animation.h:44