/** Sets the intensity (brightness) of a single GI triac */ void gi_leff_dim (U8 triac, U8 brightness) { /* Disable the GI string first. */ gi_clear_dimming (triac, gi_leff_dimming); gi_leff_output &= ~triac; if (brightness == 0) { /* Nothing to do if brightness = off */ } else if (brightness < 7 && system_config.allow_dim_illum == YES) { /* We want to dim the lamps at levels 1-6. Level 7 doesn't work because the GI string would have to be turned on and off very shortly before the next zerocross point, which can't be guaranteed to work. */ gi_leff_dimming[7-brightness] |= triac; } else { /* If the brightness is greater than the threshold, or if dimming has been disabled in the menu adjustments, then just it turn on all the way -- no need to do any dimming at IRQ time. */ gi_leff_output |= triac; } triac_update (); }
/** Frees a set of triacs at the end of a lamp effect */ void gi_leff_free (U8 triac) { gi_clear_dimming (triac, gi_leff_dimming); gi_leff_alloc &= ~triac; gi_leff_output &= ~triac; triac_update (); }
/** Turns off one or more triacs */ void gi_disable (U8 triac) { log_event (SEV_INFO, MOD_TRIAC, EV_TRIAC_OFF, triac); gi_clear_dimming (triac, gi_dimming); triac_output &= ~triac; triac_update (); }
/** Enable dimming for a GI string. */ void gi_dim (U8 triac, U8 intensity) { gi_clear_dimming (triac, gi_dimming); triac_output &= ~triac; gi_dimming[intensity] |= triac; triac_update (); }
/** Turns on one or more triacs */ void triac_enable (U8 triac) { log_event (SEV_INFO, MOD_TRIAC, EV_TRIAC_ON, triac); gi_clear_dimming (triac, gi_dimming); triac_output |= triac; triac_update (); }
/** Initialize the triac module */ void triac_init (void) { gi_leff_alloc = 0; triac_output = 0; gi_leff_output = 0; memset (gi_dimming, 0, ZC_MAX_PERIOD); memset (gi_leff_dimming, 0, ZC_MAX_PERIOD); triac_update (); }
/** Initialize the triac module */ void gi_init (void) { gi_leff_alloc = 0; gi_leff_output = 0; triac_output = 0; #ifdef CONFIG_TRIAC memset (gi_dimming, 0, ZC_MAX_PERIOD); memset (gi_leff_dimming, 0, ZC_MAX_PERIOD); #endif triac_update (); }
/** Enable dimming for a GI string. */ void gi_dim (U8 triac, U8 brightness) { gi_clear_dimming (triac, gi_dimming); triac_output &= ~triac; if (brightness == 0) ; else if (brightness < 7 && system_config.allow_dim_illum == YES) gi_dimming[7 - brightness] |= triac; else triac_output |= triac; triac_update (); }
/** * Start a lamp effect. */ void leff_start (leffnum_t id) { const leff_t *leff = &leff_table[id]; task_gid_t gid; /* See if the leff is already running. If so, get out now. */ gid = leff_gid_find_by_id (id); if (gid != GID_NULL) return; /* Allocate a new GID for the lamp effect process. If there are too many leffs already running, then this will fail. */ gid = leff_gid_alloc (); if (gid == GID_NULL) return; /* If the lamps can't all be allocated, then return. If the same leff is already running, this will also fail. If this does fail, note that we do not explicitly free up the GID allocated, but it will get reused implicitly since they cycle. */ page_push (MD_PAGE); if (!leff_res_can_alloc (leff_get_set (leff)) && !leff_can_preempt (leff)) { goto conflict; } /* Mark resources as in use. */ leff_res_alloc (leff_get_set (leff)); #ifdef CONFIG_GI gi_leff_allocate (leff->gi); #ifdef CONFIG_TRIAC triac_update (); #endif #endif /* Associate the GID with the lamp effect number. */ leff_running_list[gid - GID_LEFF_BASE] = id; /* Start the task to run the effect */ /* TODO - it won't start in the same page as caller! */ leff_create_task (leff, gid); dbprintf ("Started leff %d\n", id); #ifdef DEBUG_LEFFS leff_dump (); #endif conflict: page_pop (); }
/** Allocates one or more triacs for a lamp effect. The leff can override the default value for the strings. */ void gi_leff_allocate (U8 triac) { /* Only allow unallocated strings to be manipulated * by this effect. */ triac &= ~gi_leff_alloc; /* Mark the strings as allocated */ gi_leff_alloc |= triac; /* By default, allocated strings are off. */ gi_leff_output &= ~triac; /* TODO - return actually allocated strings to the caller * so that only those will be freed up on leff exit. */ triac_update (); }
/** * Update internal state to note that a leff is no longer running. * * This is invoked from both leff_exit() on its own, and from * an external leff_stop() call. */ static void leff_close (const leff_t *leff, U8 idx) { dbprintf ("Closing leff %d (idx %d)\n", leff_running_list[idx], idx); /* Turn off the resources that were in use, and free them */ page_push (MD_PAGE); rtt_disable (); lamp_set_subtract (leff_data_set, leff_get_set (leff)); leff_res_free (leff_get_set (leff)); rtt_enable (); page_pop (); #ifdef CONFIG_GI gi_leff_free (leff->gi); #endif #ifdef CONFIG_TRIAC triac_update (); #endif /* And mark the leff as not running anymore */ leff_running_list[idx] = LEFF_NULL; }
/** Disables a triac from a lamp effect */ void gi_leff_disable (U8 triac) { gi_clear_dimming (triac, gi_leff_dimming); gi_leff_output &= ~triac; triac_update (); }
/** Enables a triac from a lamp effect at full brightness */ void triac_leff_enable (U8 triac) { gi_clear_dimming (triac, gi_leff_dimming); gi_leff_output |= triac; triac_update (); }